Skip to content
Snippets Groups Projects
Commit 3801ed57 authored by TheJoeCoder's avatar TheJoeCoder
Browse files

Create Dockerfile

parent 0e337445
Branches
No related tags found
No related merge requests found
## 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"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment