Select Git revision
TheJoeCoder authored
Dockerfile 1.70 KiB
## Builder ##
# Pull image
FROM python:3.12-slim-bookworm AS builder
# Set working dir to app directory
WORKDIR /usr/src/app
# Set env variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc
# Install python requirements
COPY ./requirements.txt .
COPY ./requirements.prod.txt .
RUN pip wheel --no-cache-dir --wheel-dir /usr/src/app/wheels -r requirements.txt
RUN pip wheel --no-cache-dir --wheel-dir /usr/src/app/wheels -r requirements.prod.txt
## Final image ##
# Pull image
FROM python:3.12-slim-bookworm
# App user dir
RUN mkdir -p /home/app
# App user
RUN addgroup --system app && adduser --system --group app
# Create directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
RUN mkdir $APP_HOME/staticfiles
RUN mkdir $APP_HOME/mediafiles
WORKDIR $APP_HOME
ENV DJANGO_SETTINGS_MODULE=local_settings_prod
# Install requirements
RUN apt-get update && apt-get install -y --no-install-recommends netcat-openbsd
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
COPY --from=builder /usr/src/app/requirements.prod.txt .
RUN pip install --upgrade pip
RUN pip install --force-reinstall -U setuptools
RUN pip install --no-cache /wheels/*
# copy entrypoint.sh
COPY ./entrypoint.sh .
RUN sed -i 's/\r$//g' $APP_HOME/entrypoint.sh
RUN chmod +x $APP_HOME/entrypoint.sh
# copy project
COPY . $APP_HOME
# chown all the files to the app user
RUN chown -R app:app $APP_HOME
# change to the app user
USER app
# set the container start script to entrypoint.sh
ENTRYPOINT ["/home/app/web/entrypoint.sh"]
# Expose the port the app runs on
EXPOSE 8000
# And we're done!