-
Notifications
You must be signed in to change notification settings - Fork 15
Add Docker and Docker Compose support for development and deployment #143
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
base: main
Are you sure you want to change the base?
Conversation
- Add multi-stage Dockerfile for optimized production builds (Go 1.24 + Alpine) - Add Dockerfile.dev for development with Air live reload - Add docker-compose.yml for production deployment with volumes and health check - Add docker-compose.dev.yml for development with source mounting and Delve debugger - Add .dockerignore to exclude unnecessary files from Docker context - Add .air.docker.toml for Docker-specific live reload configuration - Update Makefile with Docker targets (docker-build, docker-run, docker-compose-up, etc.) - Update README.markdown with comprehensive Docker documentation - Update CLAUDE.md with Docker commands reference Addresses issue requirements: - Multi-stage build for optimized image size - Health check using /api/where/current-time.json endpoint - Volume persistence for GTFS database - Non-root user for security - Live reload support for development
- Create config.docker.json with data-path set to /app/data/gtfs.db - Update docker-compose.yml to mount config.docker.json - Update .air.docker.toml to use config.docker.json for dev - Update README.markdown Docker instructions
|
hey @aaronbrethorst can you review the PR and let me know if you need any changes? |
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.
Hey! Thanks for putting together this Docker support PR — this is a really valuable addition to the project. The overall architecture is solid: the multi-stage build, non-root user setup, and volume configuration in docker-compose.yml all follow best practices. Nice work on the comprehensive documentation too!
I did find a few issues that we'll need to address before merging. Nothing major conceptually, but they would cause problems for users trying to follow the documented workflows.
Issues to Fix
1. make docker-run has a few problems
In Makefile, the docker-run target needs some adjustments:
docker-run: docker-build
docker run -p 4000:4000 -v $(PWD)/config.json:/app/config.json:ro maglevWhat needs to change:
- Add
--name maglev— Without this, thedocker-stoptarget won't work since it tries to stop a container namedmaglev - Use
config.docker.jsoninstead ofconfig.json— The docker-compose.yml correctly usesconfig.docker.jsonwhich has the rightdata-pathsetting (/app/data/gtfs.db). Usingconfig.jsonwould write the database to/app/gtfs.dbwhich the non-root user may not have permission to write to - Add the data volume — Without
-v maglev-data:/app/data, the database won't persist when the container is removed
Here's what it should look like:
docker-run: docker-build
docker run --name maglev -p 4000:4000 \
-v $(PWD)/config.docker.json:/app/config.json:ro \
-v maglev-data:/app/data maglev2. Default command in Dockerfile.dev uses wrong Air config
In Dockerfile.dev, the CMD uses .air.toml:
CMD ["air", "-c", ".air.toml"]This should be .air.docker.toml instead. The docker-compose.dev.yml overrides this correctly, but if someone runs the Dockerfile directly without compose, they'll get errors because .air.toml doesn't include the -f config.docker.json flag.
3. README references a Makefile target that doesn't exist
In README.markdown, there's a reference to make schema:
`make schema` - Dump the DB's SQL schema to a file for sqlc.The Makefile doesn't have a schema target — I think this line should either be removed or changed to reference make models.
4. Health check API key
The health checks in the Dockerfile and both docker-compose files assume key=test is a valid API key. If someone changes their API keys and forgets to update the health check, their container will restart indefinitely.
Maybe add a note in the README about this? Something like: "Note: The health check uses key=test. If you change your API keys, update the health check command accordingly."
5. config.docker.json ships with production mode
The file has "env": "production" but "api-keys": ["test"]. This is fine for getting started, but might be worth a comment in the file or docs reminding users to change the API keys before deploying.
Once the issues above are fixed, this PR is good to go! The core Docker setup is well done — these are just some small gaps in the Makefile and Dockerfile.dev that would trip up users.
Thanks again for the contribution!
Description
Issue #139
Add Docker and Docker Compose support to make it easier for developers to get started with the project and to simplify deployment. This provides a consistent development environment across different platforms and streamlines the deployment process.
Changes Made
New Files
Dockerfile- Multi-stage production build (Go 1.24 + Alpine 3.21)Dockerfile.dev- Development image with Air live reload and Delve debugger.dockerignore- Excludes unnecessary files from Docker build contextdocker-compose.yml- Production configuration with volumes and health checkdocker-compose.dev.yml- Development setup with source mountingconfig.docker.json- Docker-specific config with/app/data/gtfs.dbpath for persistence.air.docker.toml- Air configuration for Docker development environmentModified Files
Makefile- Added Docker targets (docker-build, docker-run, docker-compose-up, etc.)README.markdown- Added comprehensive Docker documentationCLAUDE.md- Added Docker commands referenceTesting & Verification
All acceptance criteria from the issue have been verified:
Test 1:
docker build -t maglev .completes successfullyTest 2:
docker run -p 4000:4000 maglevstarts the serverTest 3:
docker-compose upworks correctlyTest 4: API accessible at
http://localhost:4000/api/where/current-time.json?key=testTest 5: Configuration can be modified via mounted volumes
Test 6: GTFS database persists across container restarts
Test 7: Health check returns healthy status
Test 8: Logs output to stdout/stderr correctly
Test 9: Image size is optimized (multi-stage build)
How to Use
Quick Start (Production)
docker-compose up### Development with Live Reload
docker-compose -f docker-compose.dev.yml up### Manual Docker Commands
docker build -t maglev .
docker run -p 4000:4000 -v $(pwd)/config.docker.json:/app/config.json:ro -v maglev-data:/app/data maglev## Checklist