33# ==========================================
44FROM python:3.10-slim AS builder
55
6- ARG GITHUB_TOKEN
7-
86WORKDIR /build
97
108# Install build dependencies
@@ -20,8 +18,10 @@ RUN apt-get update \
2018
2119COPY requirements.txt .
2220
23- # CRITICAL: Create .netrc to authenticate HTTPS URLs automatically
24- RUN echo "machine github.com login ${GITHUB_TOKEN} password x-oauth-basic" > ~/.netrc \
21+ # SECURE FIX: Use a secret mount instead of ARG.
22+ # This mounts the token only for this command, leaving no trace in the image history.
23+ RUN --mount=type=secret,id=github_token \
24+ echo "machine github.com login $(cat /run/secrets/github_token) password x-oauth-basic" > ~/.netrc \
2525 && chmod 600 ~/.netrc \
2626 && pip install --user --no-cache-dir -r requirements.txt \
2727 && rm ~/.netrc
@@ -35,9 +35,13 @@ LABEL maintainer="Engineering Team <engineering@aviso.com>" \
3535 version="1.0.0" \
3636 description="Aviso Core Django Service"
3737
38+ # Create the user first so we can use it for permissions
39+ RUN adduser --disabled-password --gecos '' appuser
40+
3841ENV PYTHONDONTWRITEBYTECODE=1 \
3942 PYTHONUNBUFFERED=1 \
4043 AVISO_APPS=aviso_core \
44+ # Update PATH so python finds the installed scripts
4145 PATH="/home/appuser/.local/bin:$PATH"
4246
4347WORKDIR /app
@@ -49,17 +53,15 @@ RUN apt-get update \
4953 libmemcached11 \
5054 && rm -rf /var/lib/apt/lists/*
5155
52- RUN adduser --disabled-password --gecos '' appuser
53-
54- COPY --from=builder /root/.local /home/appuser/.local
55-
56- COPY . /app
56+ # FIX: Copy artifacts and change ownership immediately
57+ # The files in builder are owned by root (/root/.local).
58+ # We must chown them to appuser when copying to /home/appuser/.local
59+ COPY --from=builder --chown=appuser:appuser /root/.local /home/appuser/.local
5760
58- RUN chown -R appuser:appuser /app
61+ COPY --chown= appuser:appuser . /app
5962
6063USER appuser
6164
6265EXPOSE 8000
6366
64- # Ensure Gunicorn is installed in requirements.txt!
6567CMD ["gunicorn" , "aviso_core.wsgi:application" , "--bind" , "0.0.0.0:8000" , "--workers" , "3" ]
0 commit comments