11#----------------- Build stage -----------------
2- # Stage used to compile code and install dependencies
3- FROM python:3.12-slim AS builder
2+ FROM --platform=linux/amd64 python:3.12-slim AS builder
43WORKDIR /build
54COPY . .
6-
5+
76# Install build dependencies
87RUN apt-get update && apt-get install -y build-essential
98RUN rm -rf /var/lib/apt/lists/*
10-
9+
1110# Create virtual environment
1211RUN python -m venv /opt/venv
1312ENV PATH="/opt/venv/bin:$PATH"
14-
13+
1514# Install Python dependencies
1615RUN pip install --no-cache-dir --upgrade pip
1716RUN pip install -e .
18-
17+
1918#----------------- Production stage -----------------
20- # Stage used to run the application
21- FROM python:3.12-slim AS production
19+ FROM --platform=linux/amd64 python:3.12-slim AS production
2220WORKDIR /app
23-
21+
2422# Install runtime system dependencies
2523RUN apt-get update && apt-get install -y --no-install-recommends curl
2624RUN rm -rf /var/lib/apt/lists/*
27-
28- # Create user and set permissions; don't run as root for security reasons
29- RUN groupadd -r appuser && useradd -r -g appuser appuser
30-
31- # Copy only the necessary artifacts from the build stage
25+
26+ # Copy artifacts from build stage
3227COPY --from=builder /opt/venv /opt/venv
3328COPY --from=builder /build/policyengine_household_api /app/policyengine_household_api
34-
35- # Copy the startup script from the existing GCP configuration
29+
30+ # Copy startup script
3631COPY ./gcp/policyengine_household_api/start.sh /app/start.sh
37-
38- # Make startup script executable and set ownership
3932RUN chmod +x /app/start.sh
40- RUN chown -R appuser:appuser /app
41- USER appuser
42-
43- # Configure environment
33+
34+ # Configure environment (runs as root by default)
4435ENV PATH="/opt/venv/bin:$PATH"
4536EXPOSE 8080
46-
47- # Use the startup script from the existing GCP configuration
37+
4838CMD ["/app/start.sh"]
0 commit comments