From d56ad286532f09131f8df0565c8aab53a6bc3dda Mon Sep 17 00:00:00 2001 From: Nano Taboada Date: Fri, 23 May 2025 21:52:22 -0300 Subject: [PATCH 1/4] chore(container): rename Docker Compose file to preferred canonical form --- docker-compose.yml => compose.yaml | 1 + 1 file changed, 1 insertion(+) rename docker-compose.yml => compose.yaml (88%) diff --git a/docker-compose.yml b/compose.yaml similarity index 88% rename from docker-compose.yml rename to compose.yaml index b772932..19dde9b 100644 --- a/docker-compose.yml +++ b/compose.yaml @@ -16,3 +16,4 @@ services: volumes: storage: + name: python-samples-fastapi-restful_storage From cf9574c5135092889d66499da1e0269443e6096b Mon Sep 17 00:00:00 2001 From: Nano Taboada Date: Fri, 23 May 2025 21:53:41 -0300 Subject: [PATCH 2/4] chore(container): simplify creation of dynamically allocated system user --- Dockerfile | 24 ++++++++++++------------ scripts/entrypoint.sh | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index a30bf47..d6e6c52 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,10 +35,10 @@ LABEL org.opencontainers.image.source="https://github.com/nanotaboada/python-sam # Copy metadata docs for container registries (e.g.: GitHub Container Registry) COPY README.md ./ -COPY assets ./assets +COPY assets/ ./assets/ # Copy pre-built wheels from builder -COPY --from=builder /app/wheelhouse /app/wheelhouse +COPY --from=builder /app/wheelhouse/ /app/wheelhouse/ # Install dependencies COPY requirements.txt . @@ -47,29 +47,29 @@ RUN pip install --no-cache-dir --no-index --find-links /app/wheelhouse -r requir # Copy application source code COPY main.py ./ -COPY databases ./databases -COPY models ./models -COPY routes ./routes -COPY schemas ./schemas -COPY services ./services +COPY databases/ ./databases/ +COPY models/ ./models/ +COPY routes/ ./routes/ +COPY schemas/ ./schemas/ +COPY services/ ./services/ # https://rules.sonarsource.com/docker/RSPEC-6504/ # Copy entrypoint and healthcheck scripts COPY --chmod=755 scripts/entrypoint.sh ./entrypoint.sh COPY --chmod=755 scripts/healthcheck.sh ./healthcheck.sh -# Copy pre-seeded SQLite database as init bundle -COPY --chmod=755 storage ./docker-compose +# The 'hold' is our storage compartment within the image. Here, we copy a +# pre-seeded SQLite database file, which Compose will mount as a persistent +# 'storage' volume when the container starts up. +COPY --chmod=755 storage/ ./hold/ # Add non-root user and make volume mount point writable -RUN groupadd --system fastapi && \ - adduser --system --ingroup fastapi --disabled-password --gecos '' fastapi && \ +RUN adduser --system --disabled-password --group fastapi && \ mkdir -p /storage && \ chown fastapi:fastapi /storage ENV PYTHONUNBUFFERED=1 -# Drop privileges USER fastapi EXPOSE 9000 diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index 3ab4944..442afa0 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -IMAGE_STORAGE_PATH="/app/docker-compose/players-sqlite3.db" +IMAGE_STORAGE_PATH="/app/hold/players-sqlite3.db" VOLUME_STORAGE_PATH="/storage/players-sqlite3.db" echo "✔ Starting container..." From ecc18fa850c63d7930749224acd300b3a7770dc5 Mon Sep 17 00:00:00 2001 From: Nano Taboada Date: Fri, 23 May 2025 21:54:03 -0300 Subject: [PATCH 3/4] chore(container): exclude __pycache__ from the Docker build context --- .dockerignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.dockerignore b/.dockerignore index e62d337..e139133 100644 --- a/.dockerignore +++ b/.dockerignore @@ -19,3 +19,7 @@ CONTRIBUTING.md coverage.xml LICENSE /tests/ +__pycache__/ +*.pyc +*.pyo +*.pyd From 5c0af65981d26d57d51993f40b8094ed7374be73 Mon Sep 17 00:00:00 2001 From: Nano Taboada Date: Fri, 23 May 2025 21:54:12 -0300 Subject: [PATCH 4/4] chore(container): adjust health check script defaults --- scripts/healthcheck.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh index 9f5a04b..e3a9877 100644 --- a/scripts/healthcheck.sh +++ b/scripts/healthcheck.sh @@ -1,5 +1,5 @@ #!/bin/sh set -e -# Simple health check using curl -curl --fail http://localhost:9000/health +# Minimal curl-based health check with timeout and error reporting +curl --fail --silent --show-error --connect-timeout 1 --max-time 2 http://localhost:9000/health