Skip to content

Commit

Permalink
Improve development experience with docker (#267)
Browse files Browse the repository at this point in the history
* Make paths consistent between builder and runtime

* Avoid reliance on Dockerfile default ENV values

* Fix issue with pickling memoryview in librabbitmq

* Use dev environment when running locally

* Reload api and worker containers on app changes
  • Loading branch information
c-w authored Dec 22, 2019
1 parent 34e047f commit ca05e9f
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APP_PORT=8080
BUILD_TAG=development
BUILD_TARGET=runtime
BUILD_TARGET=builder
DOCKER_REPO=ascoderu
SERVER_WORKERS=1
QUEUE_WORKERS=1
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ script:
if [[ "$TRAVIS_PULL_REQUEST" = "false" ]] && [[ "$TEST_MODE" = "live" ]]; then
echo "Skipping live service test for branch build"
else
export BUILD_TARGET=runtime
make build verify-build
make start
make integration-tests
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ running the unit tests and other CI steps such as linting:
make build
You can now run the application stack:
You can now run the application stack; code changes will be hot reloaded:

.. sourcecode :: sh
Expand Down
14 changes: 12 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ services:

api:
<<: *shared-app-build
command: ["/app/run-gunicorn.sh"]
command: ["/app/docker/docker-entrypoint-dev.sh", "/app/docker/app/run-gunicorn.sh"]
environment:
<<: *shared-app-environment
PORT: "8080"
CONNEXION_SPEC: dir:/app/opwen_email_server/swagger
SERVER_WORKERS: ${SERVER_WORKERS}
TESTING_UI: "True"
Expand All @@ -70,10 +71,13 @@ services:
depends_on:
- appinsights
- azurite
volumes:
- .:/app
- venv:/app/venv

worker:
<<: *shared-app-build
command: ["/app/run-celery.sh"]
command: ["/app/docker/docker-entrypoint-dev.sh", "/app/docker/app/run-celery.sh"]
environment:
<<: *shared-app-environment
CELERY_QUEUE_NAMES: all
Expand All @@ -82,6 +86,9 @@ services:
- appinsights
- azurite
- rabbitmq
volumes:
- .:/app
- venv:/app/venv

setup:
image: ${DOCKER_REPO}/opwenserver_setup:${BUILD_TAG}
Expand Down Expand Up @@ -133,3 +140,6 @@ services:
image: mcr.microsoft.com/azure-storage/azurite:latest
ports:
- ${AZURITE_PORT}:10000

volumes:
venv:
29 changes: 12 additions & 17 deletions docker/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN wget -q -O /tmp/shellcheck.tar.xz "https://storage.googleapis.com/shellcheck
&& rm /tmp/shellcheck.tar.xz \
&& shellcheck --version

WORKDIR /src
WORKDIR /app

COPY requirements*.txt ./
COPY makefile .
Expand All @@ -24,6 +24,9 @@ COPY . .
ARG LOKOLE_SENDGRID_KEY=""
RUN make ci clean

ENV PY_ENV=/app/venv
ENV HOT_RELOAD="True"

FROM python:${PYTHON_VERSION}-slim AS runtime

RUN groupadd -r opwen \
Expand All @@ -36,19 +39,11 @@ RUN pip --no-cache-dir -q install /deps/*.whl
USER opwen
WORKDIR /app

COPY --from=builder /src/docker/docker-entrypoint.sh .
COPY --from=builder /src/docker/app/run-celery.sh .
COPY --from=builder /src/docker/app/run-gunicorn.sh .
COPY --from=builder /src/opwen_email_server ./opwen_email_server

ENV PY_ENV="/usr/local"
ENV TESTING_UI="False"
ENV CONNEXION_SPEC="SET_ME"
ENV SERVER_WORKERS="1"
ENV QUEUE_WORKERS="1"
ENV LOKOLE_LOG_LEVEL="INFO"
ENV PORT=8080

EXPOSE ${PORT}
ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["bash"]
COPY --from=builder /app/docker/docker-entrypoint.sh ./docker/docker-entrypoint.sh
COPY --from=builder /app/docker/app/run-celery.sh ./docker/app/run-celery.sh
COPY --from=builder /app/docker/app/run-gunicorn.sh ./docker/app/run-gunicorn.sh
COPY --from=builder /app/opwen_email_server ./opwen_email_server

ENV PY_ENV=/usr/local

ENTRYPOINT ["/app/docker/docker-entrypoint.sh"]
15 changes: 15 additions & 0 deletions docker/docker-entrypoint-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

if [[ "${HOT_RELOAD}" != "True" ]]; then
exec "$@"
fi

rootdir="$(readlink -f "$(dirname "$0")/..")"

exec "${PY_ENV}/bin/watchmedo" \
auto-restart \
--debug-force-polling \
--directory="${rootdir}/opwen_email_server" \
--pattern='*.py' \
--recursive \
-- "$@"
6 changes: 5 additions & 1 deletion helm/templates/api-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ spec:
containers:
- name: api
image: {{.Values.version.imageRegistry}}/opwenserver_app:{{.Values.version.dockerTag}}
command: ["/app/run-gunicorn.sh"]
command: ["/app/docker/app/run-gunicorn.sh"]
env:
- name: PORT
value: "8080"
- name: CONNEXION_SPEC
value: dir:/app/opwen_email_server/swagger
- name: SERVER_WORKERS
value: "{{.Values.server.serverWorkers}}"
- name: TESTING_UI
value: "False"
{{ include "opwen.environment.shared" . }}
- name: REGISTRATION_USERNAME
valueFrom:
Expand Down
2 changes: 2 additions & 0 deletions helm/templates/nginx-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ spec:
- name: nginx
image: {{.Values.version.imageRegistry}}/opwenserver_nginx:{{.Values.version.dockerTag}}
env:
- name: PORT
value: "8888"
- name: DNS_RESOLVER
value: 127.0.0.1:53 ipv6=off
- name: HOSTNAME_CLIENT_METRICS
Expand Down
2 changes: 1 addition & 1 deletion helm/templates/worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spec:
containers:
- name: worker
image: {{.Values.version.imageRegistry}}/opwenserver_app:{{.Values.version.dockerTag}}
command: ["/app/run-celery.sh"]
command: ["/app/docker/app/run-celery.sh"]
env:
- name: CELERY_QUEUE_NAMES
value: all
Expand Down
5 changes: 4 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
flake8==3.7.9
flex==6.14.1
isort==4.3.21
librabbitmq==2.0.0
PyAMQP==0.0.8.11
lockfile==0.12.2
mypy==0.740
nose2[coverage_plugin]==0.9.1
Expand All @@ -10,3 +10,6 @@ responses==0.10.6
bandit==1.6.2
yamllint==1.18.0
yapf==0.28.0

# replace with pypi when watchdog > 0.9.0 is released
https://github.com/gorakhargosh/watchdog/archive/6793588d8ab8e2cd45aa2151b0b0bd7da5dd2617.zip#egg=watchdog[watchmedo]

0 comments on commit ca05e9f

Please sign in to comment.