Skip to content
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

Adds a production ready docker environment #730

Merged
merged 18 commits into from
Feb 12, 2024
Merged

Conversation

microstudi
Copy link
Contributor

@microstudi microstudi commented Feb 2, 2024

This PR optimizes the application for its use in Docker images:

  • Unifies development/production webserver by using Puma. Makes it configurable in terms of multithreading/multiprocessing.
  • Removes capistrano related files
  • Tests the docker build process in an action
  • Enables and documents (see README) ENV vars for the application
  • Provides a docker-compose.yml production testing file (not for real use)
  • Optimizes a two-step Docker image. Removes the necessity of a JS runtime after a precomilation of assets
  • Uses a supervisor that allows to run Sidekiq/Rails on the same Docker image (this can be configured with ENV vars)
  • Lints ruby files with rubocop
  • Fixes the use of ImageMagik in Rails 7

Testing

Run

docker compose up

Visit http:/localhost:3000/

Env vars summary:

ENV Description Default
RAILS_ENV Define the rails environment (not necessary to setup unless you have some special requirements) production
SECRET_KEY_BASE Secret key for the application, generate a new one with the command rails secret
DATABASE_URL Database URL, the format is postgresql://user:password@host:port/database
RAILS_SERVE_STATIC_FILES Tell the application to serve static files (you might want to turn this off if you are using an external web server to serve files from the public folder) true
RAILS_LOG_TO_STDOUT Tell the application to log to STDOUT (useful for Docker) true
RAILS_LOG_LEVEL Log level for the application (use debug for maximum information) info
RAILS_MAX_THREADS Maximum number of threads to use in the application (use 1 if multithreading is not desired) 5
RAILS_MIN_THREADS Minimum number of threads to use in the application RAILS_MAX_THREADS value
WEB_CONCURRENCY Number of web server processes to use 2
RUN_SIDEKIQ Run Sidekiq worker process in the docker instance (you might want to change this if want to run different docker instances for Sidekiq and Rails) true
RUN_RAILS Run Rails web server process in the docker instance true
QUEUE_ADAPTER Adapter to use for background jobs (currently the application is using exclusively Sidekiq, so no other options here right now) sidekiq
SIDEKIQ_CONCURRENCY Number of threads to use in Sidekiq 5
STORAGE_PROVIDER Storage provider for the application (currently the application supports local and amazon) local
FORCE_SSL Force SSL connections false
MAIL_LINK_HOST Host to use in the links sent by email (use your domain without protocol mydomain.tld)
MAIL_LINK_PROTOCOL Protocol to use in the previous host defined for links sent by email https
SMTP_ADDRESS SMTP server address (ie: smtp.mailgun.org)
SMTP_PORT SMTP server port (ie: 587)
SMTP_DOMAIN SMTP domain (usually the application's domain)
SMTP_USER_NAME SMTP username
SMTP_PASSWORD SMTP password
SMTP_AUTHENTICATION SMTP authentication method plain
SMTP_ENABLE_STARTTLS_AUTO Enable STARTTLS true
SMTP_OPENSSL_VERIFY_MODE OpenSSL verify mode none
AWS_ACCESS_KEY_ID AWS access key ID (only if STORAGE_PROVIDER is amazon)
AWS_SECRET_ACCESS_KEY AWS secret access key (only if STORAGE_PROVIDER is amazon)
AWS_BUCKET AWS bucket name (only if STORAGE_PROVIDER is amazon)
AWS_REGION AWS region (only if STORAGE_PROVIDER is amazon)
ADMINS Space separated list of emails for the superadmins (ie: [email protected]

@microstudi microstudi changed the base branch from develop to ruby_3 February 5, 2024 21:14
@microstudi microstudi changed the title setup dockerfile, readme and optimize for production Adds a production ready docker environment Feb 5, 2024
Copy link
Collaborator

@markets markets left a comment

Choose a reason for hiding this comment

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

Thanks @microstudi! Seems fine to me ✅, at least as far as I know Docker 😅

.env.example Outdated Show resolved Hide resolved
Dockerfile Outdated Show resolved Hide resolved
Gemfile Show resolved Hide resolved
Gemfile Show resolved Hide resolved
config/database.yml Outdated Show resolved Hide resolved
@markets
Copy link
Collaborator

markets commented Feb 12, 2024

@microstudi I added some small comments 🙏🏼 and I see there is also 1 failing test: https://github.com/coopdevs/timeoverflow/actions/runs/7800180296/job/21272472836?pr=730#step:5:25. The rest seems good to me 👌🏼.

@microstudi
Copy link
Contributor Author

@markets the failing test is due the update of the imagemagik library. I've fixed it but something happened with the upload coverage.
The rest is applied!

@markets markets merged commit b925110 into coopdevs:ruby_3 Feb 12, 2024
1 of 2 checks passed
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.

2 participants