From 4941265d114640dccee1130b02ef7be70c3e9789 Mon Sep 17 00:00:00 2001 From: Michael Gecht Date: Fri, 29 Dec 2017 16:56:15 +0100 Subject: [PATCH] Add missing dokku deploy files --- docker/dokku/Dockerfile | 65 ++++++++++++++++++++++++-------------- docker/dokku/app.json | 2 +- docker/dokku/deploy.sh | 7 ++++ docker/dokku/entrypoint.sh | 11 +++++++ 4 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 docker/dokku/deploy.sh create mode 100644 docker/dokku/entrypoint.sh diff --git a/docker/dokku/Dockerfile b/docker/dokku/Dockerfile index 6480a72..9d5993f 100644 --- a/docker/dokku/Dockerfile +++ b/docker/dokku/Dockerfile @@ -1,34 +1,51 @@ -FROM python:3.6.2-alpine3.6 -ENV PYTHONBUFFERED 1 +FROM python:alpine3.7 +ARG DJANGO_SETTINGS_MODULE +ARG DJANGO_ADMIN_URL +ARG DJANGO_SECRET_KEY +ARG DATABASE_URL +ARG DJANGO_SENTRY_DSN +ENV PYTHONBUFFERED=1 DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE} DJANGO_ADMIN_URL=${DJANGO_ADMIN_URL} DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY} DATABASE_URL=${DATABASE_URL} DJANGO_SENTRY_DSN=${DJANGO_SENTRY_DSN} # Add new user to run the whole thing as non-root -RUN addgroup -S app -RUN adduser -G app -h /app -D app +RUN addgroup -S app \ + && adduser -G app -h /app -D app -# Copy Pipfile and install system-wide -# We're installing system-wide, because we currently have problems -# correctly using the entrypoint.sh, while activating the virtual environment -COPY Pipfile Pipfile.lock /app/ -WORKDIR /app - -# Install build dependencies for PostgreSQL. While we're at it, also install -# pipenv and all python requirements. Then remove unneeded build dependencies. -RUN apk update \ +# Install build dependencies +RUN echo "@edge https://nl.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \ + && apk update \ && apk add bash \ - && apk add --no-cache --virtual .build-deps \ + && apk add \ + && apk add --no-cache \ gcc \ musl-dev \ - && apk add --no-cache postgresql postgresql-dev \ - && pip install pipenv \ - && pipenv install --system --verbose \ - && apk del .build-deps + zlib-dev \ + jpeg-dev \ + libxslt-dev \ + libxml2-dev \ + postgresql \ + postgresql-dev \ + jpeg \ + gettext \ + tzdata + +# Set the correct timezone +RUN cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime \ + && echo "Europe/Berlin" > /etc/timezone + +# Copy Pipfile and install python dependencies +COPY --chown=app:app Pipfile Pipfile.lock / +RUN pip install pipenv +RUN LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "pipenv install --system --deploy" + +# Copy dokku specific files to the project root +COPY --chown=app:app docker/dokku/* /app/ +COPY --chown=app:app docker/dokku/entrypoint.sh / +RUN chmod +x entrypoint.sh /app/deploy.sh -# Change to user and copy code USER app -COPY . /app +WORKDIR /app -# Copy dokku specific files -COPY docker/dokku/* /app/ +# Copy all related app files +COPY --chown=app:app . /app -# Let Django collect all staticfiles -RUN python /app/manage.py collectstatic --noinput +ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker/dokku/app.json b/docker/dokku/app.json index 1e619ab..ad2ad27 100644 --- a/docker/dokku/app.json +++ b/docker/dokku/app.json @@ -1,7 +1,7 @@ { "scripts": { "dokku": { - "predeploy": "python /app/manage.py migrate --noinput" + "predeploy": "sh /app/deploy.sh" } } } diff --git a/docker/dokku/deploy.sh b/docker/dokku/deploy.sh new file mode 100644 index 0000000..38cd619 --- /dev/null +++ b/docker/dokku/deploy.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -e + +python /app/manage.py migrate --noinput +python /app/manage.py compilemessages +yarn prod +python /app/manage.py collectstatic --noinput diff --git a/docker/dokku/entrypoint.sh b/docker/dokku/entrypoint.sh new file mode 100644 index 0000000..be17645 --- /dev/null +++ b/docker/dokku/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e + +# while ! pg_isready -h $POSTGRES_HOST -p $POSTGRES_PORT; do +# >&2 echo "Postgres is unavailable - sleeping" +# sleep 1 +# done + +# >&2 echo "Postgres is up - continuing" + +exec "$@"