From 8390ff12c967521584afcc234e36105c5360a851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Oliger?= Date: Thu, 30 May 2019 13:29:43 +0200 Subject: [PATCH] dockerize --- Dockerfile | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 27 +++++++++++++++++++++++++++ uwsgi.ini | 8 ++++++++ 3 files changed, 89 insertions(+) create mode 100644 Dockerfile create mode 100644 uwsgi.ini diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..9524d632 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,54 @@ +ARG BUILD_DATE="" +ARG ARCH=amd64 +ARG PYTHON_VERSION=3 + + +# First stage +FROM docker.io/${ARCH}/python:${PYTHON_VERSION}-alpine3.8 as builder + +# Install deps +COPY requirements.txt /tmp + +RUN apk add --no-cache \ + build-base \ + postgresql-dev \ + linux-headers + +RUN pip install --prefix="/install" --no-warn-script-location -r /tmp/requirements.txt \ + braintree \ + uWSGI + + +## Second stage +FROM docker.io/${ARCH}/python:${PYTHON_VERSION}-alpine3.8 + +ENV DEBUG False +ENV DB_NAME /data/hc.sqlite + +RUN apk add --no-cache libpq \ + mailcap + +RUN addgroup -g 900 -S healthchecks && \ + adduser -u 900 -S healthchecks -G healthchecks + +WORKDIR /app + +COPY --from=builder /install /usr/local +COPY . . + +RUN ./manage.py collectstatic --noinput && \ + ./manage.py compress + +RUN mkdir /data && chown healthchecks:healthchecks /data + +VOLUME /data + +USER healthchecks + +EXPOSE 8000/tcp + +ARG SYNAPSE_VERSION +ARG PYTHON_VERSION +ARG BUILD_DATE + +CMD ["uwsgi", "--enable-threads", "uwsgi.ini"] diff --git a/README.md b/README.md index 6151fd76..f2bc3f53 100644 --- a/README.md +++ b/README.md @@ -281,6 +281,33 @@ test them on a copy of your database, not on the live database right away. In a production setup, you should also have regular, automated database backups set up. + +## Deployment + +### Docker + +To run the app, you can: + + $ docker build -t healthchecks:latest . + + $ docker volume create \ + --driver local \ + --opt type=tmpfs \ + --opt device=tmpfs \ + --opt o=uid=900,gid=900 \ + healthchecks + + $ docker run -d \ + --name healthchecks \ + --mount source=healthchecks,target=/data \ + -p 8000:8000 \ + healthchecks:latest + +to migrate the db: + + $ docker exec healthchecks ./manage.py migrate + + ## Integrations ### Discord diff --git a/uwsgi.ini b/uwsgi.ini new file mode 100644 index 00000000..6d379693 --- /dev/null +++ b/uwsgi.ini @@ -0,0 +1,8 @@ +[uwsgi] +http-socket = :8000 +enable-threads +plugin = python3 +module = hc.wsgi:application +static-map = /static=static-collected +static-gzip-dir = static-collected/CACHE +attach-daemon = ./manage.py sendalerts