Browse Source

Change docker-compose.prod.yml to use Pipfile

pull/1147/head
Hironsan 3 years ago
parent
commit
8f72d592e3
4 changed files with 26 additions and 42 deletions
  1. 15
      app/Dockerfile.prod
  2. 30
      app/tools/run.sh
  3. 6
      docker-compose.prod.yml
  4. 17
      tools/run.sh

app/Dockerfile → 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" ]

30
app/tools/run.sh

@ -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

6
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:

17
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
Loading…
Cancel
Save