-
Notifications
You must be signed in to change notification settings - Fork 71
feat: Add Docker setup for local development #58
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
Includes Dockerfile, Docker Compose configuration, and a workaround script (run_sepomex_update.rb) for database seeding due to a persistent 'csv' load error under 'bundle exec'. Updates README with setup instructions and documents the seeding issue and workaround.
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.
Pull Request Overview
This PR adds Docker support for local development of the API-Codigos-Postales project and includes a workaround for a CSV load issue during database seeding.
- Added a Dockerfile and docker-compose.yml to orchestrate the web and db services.
- Created a workaround script (run_sepomex_update.rb) and updated documentation in README.md.
- Made adjustments in the Rakefile and Gemfile to support the changes.
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| run_sepomex_update.rb | Introduces a new script to download, extract, and seed postal codes. |
| docker-compose.yml | Defines development containers with proper service dependencies and healthchecks. |
| Readme.md | Updates setup instructions for local Docker-based development. |
| Rakefile | Adjusts require order for CSV to work around the loading issue. |
| Gemfile | Minor formatting changes. |
Files not reviewed (1)
- Dockerfile: Language not supported
run_sepomex_update.rb
Outdated
| response_post = Net::HTTP.post_form(uri, params) | ||
|
|
||
| puts 'Writing Zip' | ||
| File.open('latest.zip', 'w') do |file| |
Copilot
AI
Apr 29, 2025
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.
Consider using binary write mode ('wb') when opening 'latest.zip' to correctly handle binary data from the downloaded zip file.
| File.open('latest.zip', 'w') do |file| | |
| File.open('latest.zip', 'wb') do |file| |
docker-compose.yml
Outdated
| - app-network | ||
| healthcheck: | ||
| # Ensure username matches POSTGRES_USER above | ||
| test: ["CMD-SHELL", "pg_isready -U your_postgres_user -d api-codigos-postales"] |
Copilot
AI
Apr 29, 2025
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.
The healthcheck command uses 'your_postgres_user' whereas the service environment sets POSTGRES_USER to 'postgres'. Please update to use the correct username.
| test: ["CMD-SHELL", "pg_isready -U your_postgres_user -d api-codigos-postales"] | |
| test: ["CMD-SHELL", "pg_isready -U postgres -d api-codigos-postales"] |
Rakefile
Outdated
| @@ -1,6 +1,10 @@ | |||
| $LOAD_PATH.unshift('/usr/local/lib/ruby/3.4.0') unless $LOAD_PATH.include?('/usr/local/lib/ruby/3.4.0') | |||
Copilot
AI
Apr 29, 2025
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.
Hardcoding the Ruby version in the $LOAD_PATH may lead to compatibility issues; consider using a dynamic approach based on RUBY_VERSION.
| $LOAD_PATH.unshift('/usr/local/lib/ruby/3.4.0') unless $LOAD_PATH.include?('/usr/local/lib/ruby/3.4.0') | |
| $LOAD_PATH.unshift("/usr/local/lib/ruby/#{RUBY_VERSION}") unless $LOAD_PATH.include?("/usr/local/lib/ruby/#{RUBY_VERSION}") |
This commit introduces comprehensive Docker support for the API-Codigos-Postales application, enabling easy setup and execution using Docker Compose. Key changes and problem resolutions include: - **Initial Dockerfile and docker-compose.yml setup:** Configured the application and PostgreSQL database services for containerization. - **Resolved Ruby version mismatch:** Corrected the Ruby version in the Dockerfile to `3.4.2` to align with the `Gemfile` specification, fixing build failures. - **Fixed PostgreSQL password authentication:** Addressed persistent `PG::ConnectionBad` errors by ensuring the database volume was properly reset and recreated with the correct password, resolving connection issues. - **Addressed `LoadError: cannot load such file -- csv`:** Explicitly added `gem 'csv'` to the `Gemfile` to ensure the `csv` library is correctly bundled and available within the Docker environment, resolving the original data seeding failure. - **Updated `Readme.md`:** Added detailed instructions for building, running, migrating, and seeding the database using `docker compose`, ensuring clarity and ease of use for new developers.
This commit introduces a daily cron job to automatically update the postal code data using the `rake sepomex:update` task. - **Added `cron` to Docker image:** Modified `Dockerfile` to install `cron` and copy necessary scripts and configuration. - **Created `update_sepomex.sh`:** A shell script to execute the `rake sepomex:update` command within the container. - **Configured cron schedule:** Created `cron/sepomex_update_cron` to schedule the `update_sepomex.sh` script to run daily at 3:00 AM. - **Introduced `cron_worker` service:** Added a new service to `docker-compose.yml` to run the cron daemon, ensuring the scheduled task executes within the Docker environment. - **Updated `Readme.md`:** Documented the cron job setup, including verification and testing instructions.
feat: Dockerize application with automated data updates
This PR introduces robust Docker support for local development of the API-Codigos-Postales project, enabling developers to seamlessly set up and run the application, its PostgreSQL database, and automated data updates using Docker Compose.
All previous issues with database seeding and dependency loading have been resolved.
Summary of Changes
How to Use (Quick Summary)
Cron Job Verification
The daily update will run automatically at 3:00 AM UTC.
You can:
This Docker setup provides a reproducible, containerized, and self-updating environment for the API-Codigos-Postales project — ideal for both development and onboarding.