Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ CONTRIBUTING.md
coverage.xml
LICENSE
/tests/
__pycache__/
*.pyc
*.pyo
*.pyd
24 changes: 12 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml → compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ services:

volumes:
storage:
name: python-samples-fastapi-restful_storage
2 changes: 1 addition & 1 deletion scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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..."
Expand Down
4 changes: 2 additions & 2 deletions scripts/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -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