diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..470a70af4cdf26588c7d40f3d1b82c3e178ce2a5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,66 @@ +## 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 --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 + +# run entrypoint.sh +ENTRYPOINT ["/home/app/web/entrypoint.sh"]