2023-07-15 17:46:19 +03:00
|
|
|
# ==========================================
|
|
|
|
# ============ Multi-stage build ===========
|
|
|
|
# ==========================================
|
|
|
|
FROM ubuntu:jammy as python-base
|
|
|
|
|
2024-03-29 12:16:27 +03:00
|
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
2023-07-15 17:46:19 +03:00
|
|
|
RUN apt-get update -qq && \
|
2024-03-29 12:16:27 +03:00
|
|
|
apt-get full-upgrade -y && \
|
|
|
|
apt-get install -y --no-install-recommends \
|
|
|
|
curl \
|
|
|
|
gpg-agent \
|
|
|
|
software-properties-common && \
|
|
|
|
add-apt-repository -y ppa:deadsnakes/ppa && \
|
|
|
|
add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
|
2023-07-15 17:46:19 +03:00
|
|
|
apt-get install -y --no-install-recommends \
|
2024-03-29 12:16:27 +03:00
|
|
|
python3.12 \
|
|
|
|
libstdc++6 && \
|
|
|
|
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.12 && \
|
|
|
|
python3.12 -m pip install --upgrade pip && \
|
|
|
|
python3.12 -m pip install wheel && \
|
|
|
|
apt-get autoclean -y && \
|
|
|
|
apt-get autoremove -y && \
|
|
|
|
apt-get clean && \
|
2023-07-15 17:46:19 +03:00
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
# ========= Builder ==============
|
|
|
|
FROM python-base as builder
|
|
|
|
|
|
|
|
# Set env variables
|
|
|
|
ENV PYTHONDONTWRITEBYTECODE 1
|
|
|
|
ENV PYTHONUNBUFFERED 1
|
|
|
|
|
|
|
|
COPY ./requirements.txt ./
|
2024-03-29 12:16:27 +03:00
|
|
|
RUN python3.12 -m pip wheel \
|
2023-07-15 17:46:19 +03:00
|
|
|
--no-cache-dir --no-deps \
|
|
|
|
--wheel-dir=/wheels -r requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
# ======== Application ============
|
|
|
|
FROM python-base
|
|
|
|
|
|
|
|
# Install security updates and system packages
|
|
|
|
RUN apt-get update -qq && \
|
|
|
|
apt-get upgrade -y && \
|
|
|
|
apt-get install -y \
|
|
|
|
netcat && \
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
# Setup the app user
|
|
|
|
ENV USER_HOME=/home/app
|
|
|
|
ENV APP_HOME=/home/app/web
|
|
|
|
|
|
|
|
RUN mkdir -p $USER_HOME && \
|
|
|
|
mkdir -p $APP_HOME && \
|
|
|
|
mkdir -p $APP_HOME/static && \
|
|
|
|
mkdir -p $APP_HOME/media && \
|
2023-09-01 20:45:15 +03:00
|
|
|
mkdir -p $APP_HOME/backup && \
|
2023-07-15 17:46:19 +03:00
|
|
|
adduser --system --group app
|
|
|
|
|
|
|
|
# Install python dependencies
|
|
|
|
WORKDIR $APP_HOME
|
|
|
|
COPY --from=builder /wheels /wheels
|
|
|
|
RUN pip install --no-cache /wheels/* && \
|
|
|
|
rm -rf /wheels
|
|
|
|
|
|
|
|
# Copy application sources and setup permissions
|
2023-08-05 15:45:18 +03:00
|
|
|
COPY apps/ ./apps
|
2023-07-15 17:46:19 +03:00
|
|
|
COPY project/ ./project
|
2023-08-27 16:01:00 +03:00
|
|
|
COPY fixtures/ ./fixtures
|
2023-07-15 17:46:19 +03:00
|
|
|
COPY manage.py entrypoint.sh ./
|
|
|
|
RUN sed -i 's/\r$//g' $APP_HOME/entrypoint.sh && \
|
2023-09-01 20:45:15 +03:00
|
|
|
chmod +x $APP_HOME/entrypoint.sh && \
|
2023-07-15 17:46:19 +03:00
|
|
|
chown -R app:app $APP_HOME && \
|
|
|
|
chmod -R a+rwx $APP_HOME/static && \
|
2023-09-01 20:45:15 +03:00
|
|
|
chmod -R a+rwx $APP_HOME/media && \
|
|
|
|
chmod -R a+rwx $APP_HOME/backup
|
2023-07-15 17:46:19 +03:00
|
|
|
|
2023-08-05 15:45:18 +03:00
|
|
|
RUN
|
|
|
|
|
2023-07-15 17:46:19 +03:00
|
|
|
USER app
|
|
|
|
WORKDIR $APP_HOME
|
|
|
|
|
|
|
|
ENTRYPOINT ["sh", "entrypoint.sh"]
|