forked from claw/flaskpaste
containerfile: remove vendored jaraco from setuptools, purge pip cache
This commit is contained in:
@@ -16,10 +16,11 @@ RUN python -m venv /opt/venv
|
|||||||
ENV PATH="/opt/venv/bin:$PATH"
|
ENV PATH="/opt/venv/bin:$PATH"
|
||||||
RUN pip install --no-cache-dir --upgrade pip wheel
|
RUN pip install --no-cache-dir --upgrade pip wheel
|
||||||
|
|
||||||
# Install Python dependencies (includes security pins for setuptools, jaraco.context)
|
# Install Python dependencies (includes security pins from requirements.txt)
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN pip install --no-cache-dir -r requirements.txt gunicorn \
|
RUN pip install --no-cache-dir -r requirements.txt gunicorn \
|
||||||
&& rm -rf /opt/venv/lib/python*/site-packages/setuptools/_vendor/jaraco.context*.dist-info
|
&& pip cache purge 2>/dev/null || true \
|
||||||
|
&& rm -rf /opt/venv/lib/python*/site-packages/setuptools/_vendor/jaraco*
|
||||||
|
|
||||||
|
|
||||||
# Stage 2: Runtime image
|
# Stage 2: Runtime image
|
||||||
@@ -32,7 +33,8 @@ LABEL description="Lightweight secure pastebin REST API"
|
|||||||
# Note: System packages upgraded for Trivy scan; app runs from venv
|
# Note: System packages upgraded for Trivy scan; app runs from venv
|
||||||
RUN apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
|
RUN apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
|
||||||
&& pip install --no-cache-dir --upgrade pip 'setuptools>=80.0' 'jaraco.context>=6.1.0' \
|
&& pip install --no-cache-dir --upgrade pip 'setuptools>=80.0' 'jaraco.context>=6.1.0' \
|
||||||
&& rm -rf /usr/local/lib/python*/site-packages/setuptools/_vendor/jaraco.context*.dist-info \
|
&& pip cache purge 2>/dev/null || true \
|
||||||
|
&& rm -rf /root/.cache /usr/local/lib/python*/site-packages/setuptools/_vendor/jaraco* \
|
||||||
&& groupadd -r flaskpaste && useradd -r -g flaskpaste flaskpaste
|
&& groupadd -r flaskpaste && useradd -r -g flaskpaste flaskpaste
|
||||||
|
|
||||||
# Copy virtual environment from builder
|
# Copy virtual environment from builder
|
||||||
|
|||||||
@@ -16,12 +16,13 @@ RUN apk add --no-cache gcc musl-dev libffi-dev
|
|||||||
# Create virtual environment and upgrade pip
|
# Create virtual environment and upgrade pip
|
||||||
RUN python -m venv /opt/venv
|
RUN python -m venv /opt/venv
|
||||||
ENV PATH="/opt/venv/bin:$PATH"
|
ENV PATH="/opt/venv/bin:$PATH"
|
||||||
RUN pip install --no-cache-dir --upgrade "pip>=25.3" wheel
|
RUN pip install --no-cache-dir --upgrade pip wheel
|
||||||
|
|
||||||
# Install Python dependencies (includes security pins from requirements.txt)
|
# Install Python dependencies (includes security pins from requirements.txt)
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN pip install --no-cache-dir -r requirements.txt gunicorn && \
|
RUN pip install --no-cache-dir -r requirements.txt gunicorn \
|
||||||
pip install --no-cache-dir --force-reinstall --no-deps "jaraco.context>=6.1.0"
|
&& pip cache purge 2>/dev/null || true \
|
||||||
|
&& rm -rf /opt/venv/lib/python*/site-packages/setuptools/_vendor/jaraco*
|
||||||
|
|
||||||
|
|
||||||
# Stage 2: Alpine runtime (minimal)
|
# Stage 2: Alpine runtime (minimal)
|
||||||
@@ -30,12 +31,10 @@ FROM python:3.11-alpine
|
|||||||
LABEL maintainer="FlaskPaste"
|
LABEL maintainer="FlaskPaste"
|
||||||
LABEL description="Minimal secure pastebin REST API (Alpine)"
|
LABEL description="Minimal secure pastebin REST API (Alpine)"
|
||||||
|
|
||||||
# Apply security fixes to base image (versions from requirements.txt)
|
# Apply security fixes to base image, remove vendored vulnerable packages
|
||||||
COPY requirements.txt /tmp/
|
RUN pip install --no-cache-dir --upgrade pip 'setuptools>=80.0' 'jaraco.context>=6.1.0' \
|
||||||
RUN pip install --no-cache-dir --upgrade pip && \
|
&& pip cache purge 2>/dev/null || true \
|
||||||
pip install --no-cache-dir -r /tmp/requirements.txt && \
|
&& rm -rf /root/.cache /usr/local/lib/python*/site-packages/setuptools/_vendor/jaraco*
|
||||||
pip install --no-cache-dir --force-reinstall --no-deps "jaraco.context>=6.1.0" && \
|
|
||||||
rm /tmp/requirements.txt
|
|
||||||
|
|
||||||
# Create non-root user
|
# Create non-root user
|
||||||
RUN addgroup -g 65532 -S flaskpaste && adduser -u 65532 -S -G flaskpaste flaskpaste
|
RUN addgroup -g 65532 -S flaskpaste && adduser -u 65532 -S -G flaskpaste flaskpaste
|
||||||
|
|||||||
Reference in New Issue
Block a user