gmba_django/Dockerfile.prod

86 lines
1.8 KiB
Text
Raw Permalink Normal View History

###########
# BUILDER #
###########
# pull official base image
FROM python:3.9.6-alpine as builder
# set work directory
WORKDIR /usr/src/gmba_django
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev
# lint
RUN pip install --upgrade pip
RUN pip install flake8==3.9.2
COPY . .
2022-08-25 08:26:59 +00:00
#RUN flake8 --ignore=E501,F401 .
# install dependencies
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/gmba_django/wheels -r requirements.txt
#########
# FINAL #
#########
# pull official base image
FROM python:3.9.6-alpine
# create directory for the app user
2022-09-25 10:19:08 +00:00
RUN mkdir -p /home/app
# create the app user
RUN addgroup -S app && adduser -S app -G app
# create the appropriate directories
2022-09-25 10:19:08 +00:00
ENV HOME=/home/app
ENV APP_HOME=/home/app/gmba_django
RUN mkdir $APP_HOME
2022-09-19 04:24:17 +00:00
RUN mkdir $APP_HOME/static
2022-09-19 08:05:02 +00:00
RUN mkdir $APP_HOME/media
2022-09-25 10:19:08 +00:00
#ADD gmba_django /data/app
#WORKDIR /data/app/gmba_django
# install dependencies
RUN apk update && apk add libpq
COPY --from=builder /usr/src/gmba_django/wheels /wheels
COPY --from=builder /usr/src/gmba_django/requirements.txt .
RUN pip install --no-cache /wheels/*
# copy entrypoint.prod.sh
2022-09-25 10:19:08 +00:00
COPY ./entrypoint.prod.sh /entrypoint.prod.sh
2022-09-24 11:15:41 +00:00
COPY ./init.sh /init.sh
2022-09-25 10:19:08 +00:00
RUN sed -i 's/\r$//g' /entrypoint.prod.sh
RUN chmod +x /entrypoint.prod.sh
# copy project
2022-09-25 10:19:08 +00:00
#COPY . $APP_HOME
2022-09-24 11:15:41 +00:00
2022-09-25 10:19:08 +00:00
ADD . /home/app/gmba_django
WORKDIR /home/app/gmba_django
2022-09-24 11:15:41 +00:00
# chown all the files to the app user
RUN chown -R app:app $APP_HOME
# change to the app user
USER app
2022-09-25 14:20:51 +00:00
#RUN python manage.py collectstatic --noinput
# run entrypoint.prod.sh
2022-09-25 10:19:08 +00:00
ENTRYPOINT ["/entrypoint.prod.sh"]
EXPOSE 8000
2022-09-25 10:19:08 +00:00
CMD ["gunicorn", "--bind", "[::]:8000", "--chdir", "/home/app/gmba_django", "--workers", "3", "gmba_django.wsgi:application"]