-
Notifications
You must be signed in to change notification settings - Fork 14
feat(container): add Docker Compose support with persistent SQLite volume #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis update introduces a comprehensive overhaul of the containerization workflow for the ASP.NET Core Web API project. It adds a multi-stage Dockerfile with health checks, non-root execution, and persistent volume management. Docker Compose is now the recommended orchestration method, and supporting scripts and documentation have been updated to reflect these changes. Minor dependency and configuration updates are also included. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Docker Compose
participant Container (api)
participant Entrypoint Script
participant ASP.NET Core App
User->>Docker Compose: docker compose up
Docker Compose->>Container (api): Start container
Container (api)->>Entrypoint Script: Run entrypoint.sh
Entrypoint Script->>Entrypoint Script: Check for DB in volume
alt DB not found in volume
Entrypoint Script->>Entrypoint Script: Copy DB from image to volume
else DB exists
Entrypoint Script->>Entrypoint Script: Skip copy
end
Entrypoint Script->>ASP.NET Core App: Exec app command
ASP.NET Core App->>ASP.NET Core App: Start, expose /health
Docker Compose->>Container (api): Healthcheck via healthcheck.sh
Container (api)->>ASP.NET Core App: curl /health
Possibly related PRs
Suggested labels
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ Finishing Touches
🧪 Generate Unit Tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (13)
.gitignore (1)
1-3: Consider being more comprehensive with ignored patterns.While the simplified .gitignore aligns with containerization where build outputs are managed within Docker, it removes many standard ignore patterns that could be useful even in a containerized development workflow.
Consider preserving additional patterns for IDE-specific files and other common temporary files to prevent accidental commits:
logs/ bin/ obj/ +.vs/ +.vscode/ +*.user +*.suo +.DS_StoreREADME.md (4)
45-47: Verify build command syntax
Thedocker compose buildcommand is correct. Consider adding the--pullflag if you want to always fetch the latest base images during builds.
52-52: Confirm run command
Usingdocker compose upis appropriate. Optionally, suggest adding-d(detached mode) for production scenarios to free up the terminal.
55-56: Refine blockquote language
Add the article “the” for clarity:- > On first run, the container copies... + > On the first run, the container copies... - > On subsequent runs, that volume is reused... + > On subsequent runs, the volume is reused...🧰 Tools
🪛 LanguageTool
[uncategorized] ~55-~55: You might be missing the article “the” here.
Context: ...ppbash docker compose up> On first run, the container copies a pre-seeded ...(AI_EN_LECTOR_MISSING_DETERMINER_THE)
64-68: Optional database reset step
Thedocker compose down -vcommand correctly removes the volume to reset the database on next startup. Consider adding a warning about permanent data loss when running this.docker-compose.yml (2)
5-7: Build context specification
Thebuild.context: .anddockerfile: Dockerfilesettings are correct. If you ever need to pass build-time variables, you can add anargs:block here.
8-11: Ports and volume mount
The port mapping andstorage:/storage/volume mount look good. For consistency, you could remove the trailing slash on the container path (/storage)—though functionally it’s equivalent.scripts/entrypoint.sh (1)
1-2: Initialize shell script with strict mode
Using#!/bin/shandset -eensures the script exits on any command failure. You might also addset -uandset -o pipefailfor stricter error handling.Dockerfile (5)
13-20: Source copy and publish
Including the pre-seeded database understorage/players-sqlite3.dbin the builder context is appropriate. To reduce context size, consider a.dockerignorefor unnecessary files.
25-31: Install curl for health checks
Combiningapt-get updatewithinstall -y --no-install-recommends curland cleanup is best practice. For fully reproducible builds, you could pin thecurlversion.🧰 Tools
🪛 GitHub Check: Codacy Static Code Analysis
[warning] 30-30: Dockerfile#L30
Pin versions in apt get install. Instead ofapt-get install <package>useapt-get install <package>=<version>
33-38: Metadata labels
The OCI labels improve image metadata. You might also addorg.opencontainers.image.versionororg.opencontainers.image.createdfor completeness.
43-49: Copy published artifacts and docs
Copying the application, README, andassetsadds documentation to the image. If theassetsfolder is not required at runtime, consider omitting it to slim the image.
67-68: Healthcheck configuration
TheHEALTHCHECKinvocation of./healthcheck.shis correctly configured. Ensure your app’s/healthendpoint returns appropriate exit codes.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
src/Dotnet.Samples.AspNetCore.WebApi/storage/players-sqlite3.dbis excluded by!**/*.db
📒 Files selected for processing (9)
.gitignore(1 hunks)Dockerfile(1 hunks)README.md(1 hunks)docker-compose.yml(1 hunks)scripts/entrypoint.sh(1 hunks)scripts/healthcheck.sh(1 hunks)src/Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csproj(1 hunks)src/Dotnet.Samples.AspNetCore.WebApi/Program.cs(3 hunks)test/Dotnet.Samples.AspNetCore.WebApi.Tests/packages.lock.json(12 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md
[uncategorized] ~55-~55: 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)
🪛 GitHub Check: Codacy Static Code Analysis
Dockerfile
[warning] 30-30: Dockerfile#L30
Pin versions in apt get install. Instead of apt-get install <package> use apt-get install <package>=<version>
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (21)
test/Dotnet.Samples.AspNetCore.WebApi.Tests/packages.lock.json (1)
549-550: Package version updates look good.The package updates from 9.0.4 to 9.0.5 and 8.0.15 to 8.0.16 (for Microsoft.AspNetCore.OpenApi) are minor version updates that likely include security patches or bug fixes, supporting the containerization changes.
Also applies to: 729-730, 763-764, 774-775, 779-780, 784-785, 794-795, 805-806, 820-821, 835-836
src/Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csproj (1)
31-31: Database path change aligns with Docker volume strategy.Changing the database path from "Data" to "storage" supports the containerization workflow with a persistent SQLite volume as introduced in the Docker-related files.
scripts/healthcheck.sh (1)
1-5: Well-structured health check script.This script provides a simple and effective health check mechanism for Docker container monitoring, following best practices with proper error handling.
src/Dotnet.Samples.AspNetCore.WebApi/Program.cs (3)
39-42: Good database path update for containerization.The path change from "Data" to "storage" is consistent with the project file changes and Docker volume strategy.
53-53: Health checks integration supports container monitoring.Adding health checks is a best practice for containerized applications, enabling Docker to properly monitor application health.
97-98: Properly mapped health endpoint.The health check endpoint is mapped correctly and documented with a reference link, providing the endpoint that will be used by the Docker health check script.
README.md (2)
39-43: Added Docker Compose instructions with persistent volume
The new section clearly introduces Docker Compose for building and running the app with a persistent SQLite volume. This aligns perfectly with the PR objectives.
58-61: Stop command section is clear
Thedocker compose downinstruction cleanly stops and removes containers as expected.docker-compose.yml (3)
1-4: Define service and image
Theapiservice is correctly defined with bothimageandcontainer_name. Including theimagename alongsidebuildtags the built image appropriately.
12-14: Environment and restart policy
SettingSTORAGE_PATHensures the application picks up the correct SQLite file. Therestart: unless-stoppedpolicy is appropriate for resilience.
16-17: Persisted named volume
Declaring thestoragevolume without driver details uses the default local driver, which is sufficient for SQLite persistence.scripts/entrypoint.sh (4)
4-6: Define database paths
IMAGE_STORAGE_PATHandVOLUME_STORAGE_PATHcorrectly map the seed file and the persistent volume location.
9-17: Database initialization logic
The conditional block to seed the DB on first run is sound. Ensure/storageis writable (it’s created in the Dockerfile).
20-21: Skip seed copy on existing database
The else branch cleanly skips copying when the database file is already present.
23-25: Entrypoint execution
Logging readiness messages beforeexec "$@"improves observability, andexeccorrectly replaces the shell with the application process.Dockerfile (6)
5-11: Builder stage setup
The multi-stage build leveragingmcr.microsoft.com/dotnet/sdk:8.0is correct. Restoring before copying full source optimizes cache layers.
39-42: Runtime environment variables
ASPNETCORE_URLSandASPNETCORE_ENVIRONMENTare correctly set for production use.
53-55: Include entrypoint and healthcheck scripts
Using--chmod=555ensures executability. Confirm thathealthcheck.shlogic matches the health endpoint configured in your app.
57-59: Pre-seeded database for runtime
TheCOPY --from=builder ...storage/players-sqlite3.db ./docker-compose/command places the seed DB bundle where the entrypoint expects it.
61-64: Non-root user and storage directory
Addingaspnetcoreuser and owning/storageensures the container doesn’t run as root, improving security.
70-73: Entrypoint and default command
SplittingENTRYPOINTandCMDallows override flexibility while running your custom entrypoint logic by default.



Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Chores
.gitignorefile.