diff --git a/app/Dockerfile b/app/Dockerfile.prod similarity index 54% rename from app/Dockerfile rename to app/Dockerfile.prod index dbb3549d..a2814c04 100644 --- a/app/Dockerfile +++ b/app/Dockerfile.prod @@ -8,7 +8,8 @@ WORKDIR /app ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 -COPY . /app/ +COPY ./app/ /app/ +COPY ./Pipfile* /app/ # hadolint ignore=DL3013 RUN apt-get update \ @@ -17,6 +18,12 @@ RUN apt-get update \ libpq-dev=11.9-0+deb10u1 \ unixodbc-dev=2.3.6-0.1 \ g++=4:8.3.0-1 \ - && pip install --no-cache-dir -U pip setuptools \ - && pip install --no-cache-dir -r requirements.txt \ - && apt-get clean + && pip install --no-cache-dir pipenv==2020.11.15 \ + && pipenv install --system --deploy \ + && pip uninstall -y pipenv virtualenv-clone virtualenv \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +COPY tools/ /opt/bin/ + +ENTRYPOINT [ "/opt/bin/run.sh" ] diff --git a/app/tools/run.sh b/app/tools/run.sh deleted file mode 100755 index d39ac8ee..00000000 --- a/app/tools/run.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit - -echo "Making staticfiles" -static_dir=staticfiles -mkdir -p client/dist/static -if [[ ! -d $static_dir ]] || [[ -z $(ls -A $static_dir) ]]; then - echo "Executing collectstatic" - python manage.py collectstatic --noinput; -fi - -echo "Initializing database" -python manage.py wait_for_db -python manage.py migrate -python manage.py create_roles - -echo "Creating admin" -if [[ -n "${ADMIN_USERNAME}" ]] && [[ -n "${ADMIN_PASSWORD}" ]] && [[ -n "${ADMIN_EMAIL}" ]]; then - python manage.py create_admin \ - --username "${ADMIN_USERNAME}" \ - --password "${ADMIN_PASSWORD}" \ - --email "${ADMIN_EMAIL}" \ - --noinput \ - || true -fi - -echo "Starting django" -gunicorn --bind="0.0.0.0:${PORT:-8000}" --workers="${WORKERS:-1}" app.wsgi --timeout 300 - diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index aa1c230d..7afa8dbb 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -2,8 +2,10 @@ version: "3.7" services: backend: - build: ./app - command: ["/app/tools/run.sh"] + build: + context: . + dockerfile: app/Dockerfile.prod + # command: ["/app/tools/run.sh"] volumes: - static_volume:/app/staticfiles environment: diff --git a/tools/run.sh b/tools/run.sh index 45ef6336..93aa098c 100755 --- a/tools/run.sh +++ b/tools/run.sh @@ -3,16 +3,21 @@ set -o errexit echo "Making staticfiles" -if [[ ! -d "app/staticfiles" ]]; then python app/manage.py collectstatic --noinput; fi +static_dir=staticfiles +mkdir -p client/dist/static +if [[ ! -d $static_dir ]] || [[ -z $(ls -A $static_dir) ]]; then + echo "Executing collectstatic" + python manage.py collectstatic --noinput; +fi echo "Initializing database" -python app/manage.py wait_for_db -python app/manage.py migrate -python app/manage.py create_roles +python manage.py wait_for_db +python manage.py migrate +python manage.py create_roles echo "Creating admin" if [[ -n "${ADMIN_USERNAME}" ]] && [[ -n "${ADMIN_PASSWORD}" ]] && [[ -n "${ADMIN_EMAIL}" ]]; then - python app/manage.py create_admin \ + python manage.py create_admin \ --username "${ADMIN_USERNAME}" \ --password "${ADMIN_PASSWORD}" \ --email "${ADMIN_EMAIL}" \ @@ -21,4 +26,4 @@ if [[ -n "${ADMIN_USERNAME}" ]] && [[ -n "${ADMIN_PASSWORD}" ]] && [[ -n "${ADMI fi echo "Starting django" -gunicorn --bind="0.0.0.0:${PORT:-8000}" --workers="${WORKERS:-1}" --pythonpath=app app.wsgi --timeout 300 +gunicorn --bind="0.0.0.0:${PORT:-8000}" --workers="${WORKERS:-1}" app.wsgi --timeout 300