2025-01-24 11:43:18 +05:00
|
|
|
###########
|
|
|
|
# BUILDER #
|
|
|
|
###########
|
|
|
|
|
2025-01-20 14:33:03 +05:00
|
|
|
# pull official base image
|
2025-02-12 19:27:05 +05:00
|
|
|
FROM python:3.11-slim AS builder
|
2025-01-20 14:33:03 +05:00
|
|
|
|
|
|
|
# set work directory
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# set environment variables
|
|
|
|
ENV PYTHONDONTWRITEBYTECODE 1
|
|
|
|
ENV PYTHONUNBUFFERED 1
|
|
|
|
|
|
|
|
# install system dependencies
|
2025-01-24 11:43:18 +05:00
|
|
|
RUN apt-get update && \
|
2025-02-12 19:27:05 +05:00
|
|
|
apt-get install -y --no-install-recommends gcc && \
|
|
|
|
apt-get clean && \
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
2025-01-20 14:33:03 +05:00
|
|
|
|
2025-01-24 11:43:18 +05:00
|
|
|
# lint
|
2025-01-20 14:33:03 +05:00
|
|
|
RUN pip install --upgrade pip
|
2025-01-24 11:43:18 +05:00
|
|
|
COPY . /app/
|
|
|
|
|
|
|
|
# install python dependencies
|
2025-01-20 14:33:03 +05:00
|
|
|
COPY ./requirements.txt .
|
2025-01-24 11:43:18 +05:00
|
|
|
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
#########
|
|
|
|
# FINAL #
|
|
|
|
#########
|
|
|
|
|
|
|
|
# pull official base image
|
2025-02-12 19:27:05 +05:00
|
|
|
FROM python:3.11-slim
|
2025-01-20 14:33:03 +05:00
|
|
|
|
2025-01-24 11:43:18 +05:00
|
|
|
# create directory for the app user
|
|
|
|
RUN mkdir -p /home/app
|
|
|
|
|
|
|
|
# create the app user
|
|
|
|
RUN addgroup --system app && adduser --system --group app
|
|
|
|
|
|
|
|
# create the appropriate directories
|
2025-02-12 19:27:05 +05:00
|
|
|
RUN mkdir -p /home/app/api/staticfiles
|
|
|
|
RUN chmod -R 777 /home/app/api/staticfiles
|
|
|
|
WORKDIR /home/app/api
|
2025-01-24 11:43:18 +05:00
|
|
|
|
|
|
|
# install dependencies
|
2025-02-12 19:27:05 +05:00
|
|
|
RUN apt-get update && \
|
|
|
|
apt-get install -y --no-install-recommends netcat-openbsd && \
|
|
|
|
apt-get clean && \
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
2025-01-24 11:43:18 +05:00
|
|
|
COPY --from=builder /app/wheels /wheels
|
|
|
|
COPY --from=builder /app/requirements.txt .
|
|
|
|
RUN pip install --upgrade pip
|
|
|
|
RUN pip install --no-cache /wheels/*
|
|
|
|
|
|
|
|
# copy entrypoint.prod.sh
|
|
|
|
COPY ./entrypoint.prod.sh .
|
2025-02-12 19:27:05 +05:00
|
|
|
RUN sed -i 's/\r$//g' /home/app/api/entrypoint.prod.sh
|
|
|
|
RUN chmod +x /home/app/api/entrypoint.prod.sh
|
2025-01-20 14:33:03 +05:00
|
|
|
|
|
|
|
# copy project
|
2025-02-12 19:27:05 +05:00
|
|
|
COPY . /home/app/api
|
2025-01-24 11:43:18 +05:00
|
|
|
|
|
|
|
# chown all the files to the app user
|
2025-02-12 19:27:05 +05:00
|
|
|
RUN chown -R app:app /home/app/api
|
2025-01-24 11:43:18 +05:00
|
|
|
|
|
|
|
# change to the app user
|
|
|
|
USER app
|
2025-01-20 14:33:03 +05:00
|
|
|
|
2025-01-24 11:43:18 +05:00
|
|
|
# run entrypoint.prod.sh
|
|
|
|
ENTRYPOINT ["/home/app/api/entrypoint.prod.sh"]
|