Skip to content

Commit ba3a690

Browse files
committed
Updated main Dockerfile and entrypoint script with Charles' changes
Signed-off-by: Charlie Evans <charlie.glenn.evans.jr@gmail.com>
1 parent 8120428 commit ba3a690

2 files changed

Lines changed: 57 additions & 19 deletions

File tree

Dockerfile

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
1-
FROM registry.access.redhat.com/ubi8/python-38:1-71.1634036286
1+
FROM python:3.9.13-slim-buster as base
22

3-
WORKDIR /opt/app-root/src
3+
# Setup env
4+
ENV LANG C.UTF-8
5+
ENV LC_ALL C.UTF-8
6+
ENV PYTHONDONTWRITEBYTECODE 1
7+
ENV PYTHONFAULTHANDLER 1
48

5-
COPY --chown=1001:0 . .
6-
RUN chmod -R g=u .
79

8-
USER 1001
10+
FROM base AS python-deps
11+
12+
# Install pipenv and compilation dependencies
13+
RUN pip install --no-cache-dir --upgrade pip==22.2.2 && \
14+
pip install --no-cache-dir pipenv==2022.8.24 gunicorn==20.1.0 django==4.1 django_bootstrap4==22.2 django_extensions==3.2.0 django-allow-cidr==0.5.0 django_q==1.3.9 psycopg2-binary==2.9.3 whitenoise==6.2.0
15+
16+
# Install python dependencies in /.venv
17+
WORKDIR /
18+
COPY Pipfile Pipfile.lock ./
19+
20+
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy
21+
922

10-
ENV LC_ALL=C.UTF-8 \
11-
LANG=C.UTF-8 \
12-
PYTHONDONTWRITEBYTECODE=1 \
13-
PYTHONFAULTHANDLER=1
23+
FROM base AS runtime
24+
25+
# Install extra packages
26+
RUN apt-get update && \
27+
apt-get install -y --no-install-recommends postgresql-client=11+200+deb10u4 iputils-ping=3:20180629-2+deb10u2 curl=7.64.0-4+deb10u2 && rm -rf /var/lib/apt/lists/*
28+
29+
# Create and switch to a new user
30+
RUN useradd --create-home --uid 1001 --gid 0 appuser
31+
WORKDIR /home/appuser
32+
33+
# Copy virtual env from python-deps stage
34+
COPY --from=python-deps /.venv /.venv
35+
ENV PATH="/.venv/bin:$PATH"
36+
37+
# Install application into container
38+
COPY --chown=1001:0 . .
39+
RUN chmod -R g=u .
1440

15-
# see issue https://github.com/pypa/pipenv/issues/4220 for pipenv version
16-
RUN pip install --no-cache-dir --upgrade pip==21.3.1 && \
17-
pip install --no-cache-dir pipenv==2018.11.26 && \
18-
pipenv install --system --dev
41+
USER appuser
1942

2043
EXPOSE 8080
2144

22-
ENTRYPOINT ["sh", "entrypoint.sh"]
23-
CMD ["gunicorn", "-b", "0.0.0.0:8080", "--env", "DJANGO_SETTINGS_MODULE=cfc_project.settings", "cfc_project.wsgi", "--timeout 120"]
45+
CMD ["bash", "entrypoint.sh"]

entrypoint.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

3-
# python3 manage.py migrate --no-input
4-
python3 manage.py collectstatic --no-input --clear
3+
if [[ ! -z ${POSTGRESQL_DATABASE_FILE} ]]; then
4+
export POSTGRESQL_DATABASE=`cat $POSTGRESQL_DATABASE_FILE`
5+
fi
6+
if [[ ! -z ${POSTGRESQL_USER_FILE} ]]; then
7+
export POSTGRESQL_USER=`cat $POSTGRESQL_USER_FILE`
8+
fi
9+
if [[ ! -z ${POSTGRESQL_PASSWORD_FILE} ]]; then
10+
export POSTGRESQL_PASSWORD=`cat $POSTGRESQL_PASSWORD_FILE`
11+
fi
512

6-
exec "$@"
13+
python3 manage.py makemigrations
14+
python3 manage.py migrate
15+
python3 manage.py loaddata sources/cfc-seed.json
16+
17+
TEST="${USE_SQLITE3:-False}"
18+
if [[ "${TEST,,}" == "true" ]]; then
19+
python3 manage.py runserver 0.0.0.0:8080
20+
else
21+
gunicorn -b 0.0.0.0:8080 --env DJANGO_SETTINGS_MODULE=cfc_project.settings cfc_project.wsgi --timeout 120
22+
fi

0 commit comments

Comments
 (0)