From 3801ed5720a65bc37d5eeca6634071b029c987f1 Mon Sep 17 00:00:00 2001 From: TheJoeCoder <joe@radialbog9.uk> Date: Tue, 18 Feb 2025 23:26:07 +0000 Subject: [PATCH] Create Dockerfile --- Dockerfile | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..470a70a --- /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"] -- GitLab