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 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/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 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..." 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