reduce production image size without runtime drift
Some checks failed
Upload latest backend image to GHCR / upload (push) Failing after 2m45s
Test Backend / Build and Test Backend (push) Failing after 2m3s
Upload latest frontend image to GHCR / upload (push) Failing after 13s
Test Frontend / Build and Test Frontend (push) Successful in 10m51s
Trivy Security Scans / Trivy Filesystem Scan (Source Code) (push) Failing after 1m43s
Trivy Security Scans / Trivy Docker Image Scan (Backend & Frontend) (push) Failing after 27s
Some checks failed
Upload latest backend image to GHCR / upload (push) Failing after 2m45s
Test Backend / Build and Test Backend (push) Failing after 2m3s
Upload latest frontend image to GHCR / upload (push) Failing after 13s
Test Frontend / Build and Test Frontend (push) Successful in 10m51s
Trivy Security Scans / Trivy Filesystem Scan (Source Code) (push) Failing after 1m43s
Trivy Security Scans / Trivy Docker Image Scan (Backend & Frontend) (push) Failing after 27s
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
# Stage 1: Build stage with dependencies
|
||||
ARG PYTHON_IMAGE=python:3.13-slim
|
||||
|
||||
FROM ${PYTHON_IMAGE} AS builder
|
||||
|
||||
# Metadata labels
|
||||
LABEL maintainer="Voyage contributors" \
|
||||
version="0.10.0" \
|
||||
description="Voyage — the ultimate self-hosted travel companion." \
|
||||
@@ -14,64 +13,55 @@ LABEL maintainer="Voyage contributors" \
|
||||
org.opencontainers.image.vendor="Voyage contributors" \
|
||||
org.opencontainers.image.licenses="GPL-3.0"
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
DEBIAN_FRONTEND=noninteractive \
|
||||
VIRTUAL_ENV=/opt/venv
|
||||
|
||||
WORKDIR /code
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Install system dependencies needed for build
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
git \
|
||||
postgresql-client \
|
||||
gdal-bin \
|
||||
build-essential \
|
||||
libgdal-dev \
|
||||
nginx \
|
||||
memcached \
|
||||
supervisor \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
libpq-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Python dependencies
|
||||
COPY ./server/requirements.txt /code/
|
||||
RUN pip install --upgrade pip \
|
||||
&& pip install --no-cache-dir -r requirements.txt
|
||||
COPY ./server/requirements.txt /tmp/requirements.txt
|
||||
|
||||
RUN python -m venv "$VIRTUAL_ENV" \
|
||||
&& "$VIRTUAL_ENV/bin/pip" install --upgrade pip \
|
||||
&& "$VIRTUAL_ENV/bin/pip" install --no-cache-dir --no-compile --prefer-binary -r /tmp/requirements.txt \
|
||||
&& find "$VIRTUAL_ENV" \( -type d -name '__pycache__' -o -type d -name 'tests' \) -prune -exec rm -rf '{}' + \
|
||||
&& find "$VIRTUAL_ENV" -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete
|
||||
|
||||
# Stage 2: Final image with runtime dependencies
|
||||
FROM ${PYTHON_IMAGE}
|
||||
WORKDIR /code
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Install runtime dependencies (including GDAL)
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
DEBIAN_FRONTEND=noninteractive \
|
||||
VIRTUAL_ENV=/opt/venv
|
||||
|
||||
WORKDIR /code
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
postgresql-client \
|
||||
gdal-bin \
|
||||
libgdal-dev \
|
||||
libgdal36 \
|
||||
nginx \
|
||||
memcached \
|
||||
supervisor \
|
||||
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy Python packages from builder
|
||||
COPY --from=builder /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages
|
||||
COPY --from=builder /usr/local/bin /usr/local/bin
|
||||
|
||||
# Copy project code and configs
|
||||
COPY --from=builder /opt/venv /opt/venv
|
||||
COPY ./server /code/
|
||||
COPY ./nginx.conf /etc/nginx/nginx.conf
|
||||
COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
COPY ./entrypoint.sh /code/entrypoint.sh
|
||||
|
||||
RUN chmod +x /code/entrypoint.sh \
|
||||
&& mkdir -p /code/static /code/media
|
||||
|
||||
# Collect static files
|
||||
RUN python3 manage.py collectstatic --noinput --verbosity 2
|
||||
RUN "$VIRTUAL_ENV/bin/python" manage.py collectstatic --noinput --verbosity 2
|
||||
|
||||
# Expose ports
|
||||
EXPOSE 80 8000
|
||||
|
||||
# Start with an entrypoint that runs init tasks then starts supervisord
|
||||
ENTRYPOINT ["/code/entrypoint.sh"]
|
||||
|
||||
# Start supervisord to manage processes
|
||||
CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|
||||
|
||||
Reference in New Issue
Block a user