Skip to content

Conversation

@nanotaboada
Copy link
Owner

@nanotaboada nanotaboada commented May 16, 2025

This change is Reviewable

Summary by CodeRabbit

  • New Features

    • Added Docker Compose support for easier container management and persistent SQLite database storage.
    • Introduced an entrypoint script to initialize the database volume on first run.
  • Improvements

    • Updated Dockerfile and container setup for better database handling and user permissions.
    • Enhanced environment variable support for database file path configuration.
  • Documentation

    • Revised README with detailed container usage instructions and volume management.
  • Chores

    • Updated configuration files to reflect directory renaming from "data" to "database".

@coderabbitai
Copy link

coderabbitai bot commented May 16, 2025

Warning

Rate limit exceeded

@nanotaboada has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 52 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4345e1e and 3266f36.

⛔ Files ignored due to path filters (1)
  • sqlite3-db/players-sqlite3.db is excluded by !**/*.db
📒 Files selected for processing (9)
  • .codacy.yml (1 hunks)
  • Dockerfile (4 hunks)
  • README.md (1 hunks)
  • codecov.yml (1 hunks)
  • database/player_database.py (1 hunks)
  • docker-compose.yml (1 hunks)
  • routes/player_route.py (1 hunks)
  • schemas/player_schema.py (1 hunks)
  • scripts/entrypoint.sh (1 hunks)

Walkthrough

The changes migrate the application from using a data directory to a database directory for database storage and configuration. The Docker setup is refactored to use Docker Compose, with persistent volume management for the SQLite database. Environment variable support for the database path is added, and an entrypoint script is introduced for database initialization.

Changes

File(s) Change Summary
.codacy.yml, codecov.yml Updated ignore/exclude paths from data/**/*/^data/.* to database/**/*/^database/.*.
Dockerfile Added comments, switched from copying data to database, included entrypoint.sh and sqlite3-db, created fastapi user/group, set up /sqlite3-db directory, added ENTRYPOINT for script execution.
docker-compose.yml Introduced new file defining the api service with persistent SQLite volume, environment variables, and restart policy.
README.md Replaced Docker instructions with Docker Compose workflow, added persistent volume and database initialization explanations.
database/player_database.py Changed database path logic to use DATABASE_FILE_PATH environment variable, defaulting to new location; imported os module.
routes/player_route.py, schemas/player_schema.py Updated imports from data.player_database to database.player_database.
scripts/entrypoint.sh New script to initialize the database in the persistent volume on first run, then execute the application.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Docker Compose
    participant Container
    participant Entrypoint Script
    participant SQLite DB Volume

    User->>Docker Compose: docker compose up
    Docker Compose->>Container: Start container
    Container->>Entrypoint Script: Run entrypoint.sh
    Entrypoint Script->>SQLite DB Volume: Check for DB file
    alt DB file missing in volume
        Entrypoint Script->>Container: Copy DB from image to volume
    else DB file exists
        Entrypoint Script->>Entrypoint Script: Skip copy
    end
    Entrypoint Script->>Container: Start Uvicorn server (CMD)
Loading

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nanotaboada nanotaboada linked an issue May 16, 2025 that may be closed by this pull request
@codacy-production
Copy link

codacy-production bot commented May 16, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+1.29% 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (d081ba7) 111 99 89.19%
Head commit (3266f36) 126 (+15) 114 (+15) 90.48% (+1.29%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#361) 4 4 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@codecov
Copy link

codecov bot commented May 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.18%. Comparing base (d081ba7) to head (3266f36).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #361   +/-   ##
=======================================
  Coverage   89.18%   89.18%           
=======================================
  Files           2        2           
  Lines         111      111           
=======================================
  Hits           99       99           
  Misses         12       12           
Components Coverage Δ
Services 79.31% <ø> (ø)
Routes 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (10)
Dockerfile (2)

49-51: Clarify seed DB copy destination
Copying your seed database from sqlite3-db into /app/docker-compose works, but naming a folder docker-compose inside your image may be confusing. Consider renaming the target dir to something like seed-db for clarity, e.g.:

- COPY --chown=root:root --chmod=755 sqlite3-db ./docker-compose
+ COPY --chown=root:root --chmod=755 sqlite3-db ./seed-db

Then update ENTRYPOINT, entrypoint.sh, and your code to reference /app/seed-db/players-sqlite3.db.


66-66: Use absolute path in ENTRYPOINT
Relying on ./entrypoint.sh works because of WORKDIR, but using the absolute path makes it more robust:

- ENTRYPOINT ["./entrypoint.sh"]
+ ENTRYPOINT ["/app/entrypoint.sh"]
docker-compose.yml (3)

1-4: Specify Compose file version for compatibility
Although modern Docker Compose can infer the format, adding at the top:

version: "3.9"

ensures consistent behavior across different Docker/Compose versions.


5-12: Use external .env for configuration
Hardcoding DATABASE_FILE_PATH in the Compose file reduces flexibility. You can move it to a .env file:

env_file:
  - .env
environment:
  - DATABASE_FILE_PATH=${DATABASE_FILE_PATH}

This makes overrides and local testing easier.


1-19: Add a healthcheck for liveness/readiness
To improve operational resilience, define a healthcheck that probes your FastAPI app (e.g., curl --fail http://localhost:9000/health). Docker can then automatically restart the container on failure.

scripts/entrypoint.sh (2)

1-3: Enhance shell safety
You have set -e, but consider using:

#!/usr/bin/env bash
set -euo pipefail

This will also catch unset variables and pipeline failures.


4-6: Respect the DATABASE_FILE_PATH env var
Right now VOLUME_DATABASE_FILE_PATH is hardcoded. To allow overrides, use something like:

IMAGE_DATABASE_FILE_PATH="/app/seed-db/players-sqlite3.db"
VOLUME_DATABASE_FILE_PATH="${DATABASE_FILE_PATH:-/sqlite3-db/players-sqlite3.db}"

This makes your script adapt if someone changes the env var.

README.md (3)

62-64: Minor grammar: add missing article
Change:

> On first run, the container...

to:

> On the first run, the container...
🧰 Tools
🪛 LanguageTool

[uncategorized] ~62-~62: You might be missing the article “the” here.
Context: ...pp bash docker compose up > On first run, the container copies a pre-seeded ...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


44-54: Document environment variable overrides
Mention how consumers can override DATABASE_FILE_PATH via a .env file or docker compose up --env-file:

You can set `DATABASE_FILE_PATH` in a `.env` file to point to a custom DB location.

56-60: Include detached mode example
Add a note showing how to run in detached mode:

docker compose up -d

so the terminal remains free.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d081ba7 and 4345e1e.

⛔ Files ignored due to path filters (1)
  • sqlite3-db/players-sqlite3.db is excluded by !**/*.db
📒 Files selected for processing (9)
  • .codacy.yml (1 hunks)
  • Dockerfile (4 hunks)
  • README.md (1 hunks)
  • codecov.yml (1 hunks)
  • database/player_database.py (1 hunks)
  • docker-compose.yml (1 hunks)
  • routes/player_route.py (1 hunks)
  • schemas/player_schema.py (1 hunks)
  • scripts/entrypoint.sh (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
routes/player_route.py (1)
database/player_database.py (1)
  • generate_async_session (33-41)
🪛 GitHub Check: Codeac Code Quality
database/player_database.py

[failure] 8-8: import-error
Unable to import 'sqlalchemy.ext.asyncio'


[failure] 9-9: import-error
Unable to import 'sqlalchemy.orm'

🪛 LanguageTool
README.md

[uncategorized] ~62-~62: You might be missing the article “the” here.
Context: ...pp bash docker compose up > On first run, the container copies a pre-seeded ...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

🔇 Additional comments (13)
codecov.yml (1)

43-43: Properly updated ignore path for project restructuring.

The change from ^data/.* to ^database/.* in the ignore paths aligns with the project's directory restructuring where database-related files are moved from the data to database directory.

.codacy.yml (1)

5-5: Consistently updated exclude path.

The exclusion path update from data/**/* to database/**/* correctly maintains consistency with the project's directory restructuring and matches the changes made in codecov.yml.

routes/player_route.py (1)

10-10: Import path properly updated for new directory structure.

The import path has been correctly updated to reflect the migration from data to database directory, maintaining the same functionality while supporting the restructured project organization.

schemas/player_schema.py (1)

6-6: Import path correctly updated for directory restructuring.

The import statement for Base has been appropriately updated to reference the new database directory, maintaining consistency with other changes in this PR.

database/player_database.py (2)

6-6: Added os module import for environment variable support.

The os module import enables environment variable access, which is essential for containerized applications to configure database paths externally.


11-12:

Details

✅ Verification successful

Environment variable support added for database path configuration.

This change effectively implements environment variable configuration for the database file path, with a sensible default that points to the expected volume mount location. This is a crucial component for Docker Compose deployments with persistent volumes.

For the SQLite path, using environment variables allows the container to connect to the database in the mounted volume while maintaining the same code in different environments.


🏁 Script executed:

#!/bin/bash
# Verify if there are any references to the old database path that need updating

echo "Checking for any remaining references to old database path..."
rg -i "data/players-sqlite3.db" --type-not=yml

Length of output: 207


🏁 Script executed:

#!/bin/bash
echo "Searching for any remaining references to the old database path across the repository..."
# Remove the unrecognized --type-not filter to scan all files
rg -i "data/players-sqlite3.db"

Length of output: 218


No Remaining References to Old Database Path

Verified that a repository-wide search for “data/players-sqlite3.db” returned no matches. The new environment-variable-driven default (./sqlite3-db/players-sqlite3.db) is fully in place, and there are no lingering references to the old path.

Dockerfile (4)

17-18: Skip: Stage comments added
The new Stage 2 comments clearly delineate the runtime phase. No action needed here.


32-43: Skip: Code COPY directives look correct
The application code and prebuilt wheels are copied in read-only mode with appropriate ownership and permissions. Everything aligns with the multi-stage build approach.


45-45: Skip: README metadata copy
Copying the README.md into the image for reference is fine.


53-57: Non-root user and volume mount setup is solid
Creating a fastapi system user/group and pre-chowning /sqlite3-db promotes security. Well done.

docker-compose.yml (1)

17-19: Volume declaration is correct
Defining the sqlite3-db named volume at the bottom ensures persistence. No changes needed.

scripts/entrypoint.sh (1)

25-26: Exec replacement is correct
Using exec "$@" cleanly replaces the shell with your Uvicorn command, ensuring proper signal handling.

README.md (1)

44-49: Documentation updated for Docker Compose
The new “Container” section accurately replaces the old Docker instructions with Docker Compose steps. Nice clarity.

@nanotaboada nanotaboada force-pushed the feature/docker-compose branch from 4345e1e to 2628fed Compare May 16, 2025 13:36
@sonarqubecloud
Copy link

@nanotaboada nanotaboada merged commit 486a8af into master May 16, 2025
21 checks passed
@nanotaboada nanotaboada deleted the feature/docker-compose branch May 16, 2025 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Docker Compose support with persistent SQLite volume

2 participants