From 9b2fb65b6371e6f54d00c7663e5663152527c0fd Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Wed, 12 Feb 2025 10:11:57 +0000 Subject: [PATCH] Update `Dockerfile` --- Dockerfile | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index c0470ce..5195eae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,34 +1,20 @@ -# Build an intermediate image for the Python requirements -FROM python:3.9-slim-buster as intermediate +FROM python:3.11-alpine AS base -# Install Git and Python requirements -RUN apt update && apt install -y build-essential +FROM base AS build COPY requirements.txt . RUN python -m pip install --user -r requirements.txt pip -# Start from a fresh image -FROM python:3.9-slim-buster - -# Keeps Python from generating .pyc files in the container -ENV PYTHONDONTWRITEBYTECODE=1 - -# Turns off buffering for easier container logging -ENV PYTHONUNBUFFERED=1 - -RUN useradd -u 4000 -d /app appuser +FROM base AS app +RUN adduser -u 4000 -h /app -D appuser +ENV PATH=$PATH:/app/.local/bin WORKDIR /app - -# Copy over the Python requirements from the intermediate container -COPY --from=intermediate /root/.local /app/.local - -RUN chown -R appuser: /app - USER appuser - -# Set the main execution command -ENTRYPOINT [".local/bin/waitress-serve", "main:app"] -# HEALTHCHECK --interval=5s --timeout=30s --start-period=5s --retries=3 CMD [ "/app/healthcheck.sh" ] -EXPOSE 8080/tcp - -# Copy in the code +COPY --chown=appuser --from=build /root/.local /app/.local COPY main.py . + +FROM app +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 +ENV PYTHONPATH=/app +ENTRYPOINT ["waitress-serve", "main:app"] +EXPOSE 8080/tcp