ci: add docker build & push to GHCR (#397)

This commit is contained in:
Mickael 2025-07-09 13:30:03 +02:00 committed by GitHub
parent f5b20dec44
commit 37eb4be3b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 94 additions and 34 deletions

View file

@ -1,42 +1,45 @@
# Stage 1: Install Python dependencies
FROM python:3.13-slim AS python-builder
WORKDIR /build
# System build tools
RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc python3-dev \
&& rm -rf /var/lib/apt/lists/*
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends gcc python3-dev; \
rm -rf /var/lib/apt/lists/*
# Metadata and code that setuptools needs
COPY pyproject.toml .
COPY src/ ./src/
# Install runtime dependencies defined in pyproject.toml
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir --timeout 1000 .
RUN set -eux; \
pip install --no-cache-dir --upgrade pip; \
pip install --no-cache-dir --timeout 1000 .
# Stage 2: Runtime image
FROM python:3.13-slim
LABEL org.opencontainers.image.source="https://github.com/coderamp-labs/gitingest"
# Minimal runtime utilities
RUN apt-get update \
&& apt-get install -y --no-install-recommends git curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ARG UID=1000
ARG GID=1000
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends git curl; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*
ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
WORKDIR /app
RUN useradd -m -u 1000 appuser
RUN set -eux; \
groupadd -g "$GID" appuser; \
useradd -m -u "$UID" -g "$GID" appuser
# Copy Python site-packages and code
COPY --from=python-builder /usr/local/lib/python3.13/site-packages/ \
/usr/local/lib/python3.13/site-packages/
COPY src/ ./
COPY --from=python-builder --chown=$UID:$GID /usr/local/lib/python3.13/site-packages/ /usr/local/lib/python3.13/site-packages/
COPY --chown=$UID:$GID src/ ./
# Set permissions
RUN chown -R appuser:appuser /app
RUN set -eux; \
chown -R appuser:appuser /app
USER appuser
EXPOSE 8000