Coder Social home page Coder Social logo

richardxia / docker-rails Goto Github PK

View Code? Open in Web Editor NEW

This project forked from combostrikehq/docker-rails

0.0 0.0 0.0 104 KB

An opinionated docker image for running Rails apps in production.

License: MIT License

Shell 44.99% Ruby 28.61% Dockerfile 26.40%

docker-rails's Introduction

Docker-Rails

[Circle CI] (https://circleci.com/gh/ComboStrikeHQ/docker-rails)

An opinionated docker image for running Rails apps in production.

Uses Puma, Sidekiq, Clockwork and rails_migrate_mutex. Everything is optional.

Quick Example

  • Create a new Rails app ($ rails new my_blog)
  • Create a Dockerfile in the app root with this content: FROM combostrikehq/docker-rails:latest
  • Add gem 'puma' to the Gemfile and run bundle install
  • Build the docker container: $ docker build -t my_blog .
  • Run the container: $ docker run -p 8080:8080 -e RAILS_ENV=development my_blog
  • Open http://localhost:8080
  • Enjoy!

This example is for demo purposes only. Docker-Rails is intended for production use, not local development. Please read the whole README before using.

Docker Image

The image is built by us, squashed into a single layer and pushed to Docker Hub.

To use it in your app, create a Dockerfile with the following content:

FROM combostrikehq/docker-rails:<VERSION>

and replace <VERSION> with the current version number. You can also use the latest version tag which would give you the latest unreleased version. This might be useful if you want to test against the bleeding edge in your testing/beta environment.

From version 3.0 docker-rails uses ruby 2.5. If you still use ruby 2.4 you have to use docker-rails versions 2.x. We also provide ruby-2.5 and ruby-2.4 tags that will point to the latest released docker-rails version for that ruby version.

Add more docker steps if needed (usually not), build and deploy to your infrastructure.

We use eb_deployer to deploy our apps to AWS Elastic Beanstalk.

Contents

Rails App Server / Puma

Puma is used as the web server for your app. For this to work properly, please add the following gems to your Gemfile:

gem 'puma'
gem 'rack-timeout', group: :production
gem 'rails_12factor', group: :production  # only for Rails < 5

You can configure Puma:

Environment Variable Description Default Value
PUMA_WORKERS Number of worker processes [number of CPU cores]
PUMA_MAX_THREADS Maximum number of threads per process 16
PUMA_MIN_THREADS Minimum number of threads per process PUMA_MAX_THREADS

You can also create a config/puma.rb file in your app that contains additional configuration.

Have a look at the Puma configuration file for more details.

Sidekiq

Sidekiq is used for processing background jobs. A sidekiq process will be automatically started when the sidekiq gem is present in your app. Using sidekiq is optional.

You can configure sidekiq:

Environment Variable Description Default Value
SIDEKIQ_THREADS Number of threads 16

You can also create a config/sidekiq.yml file in your app that contains additional configuration.

The default configuration enables the default and mailers queues.

Clockwork

Clockwork is used for scheduling background jobs. A clockwork process will be automatically started when the clockwork gem is present in your app. Using clockwork is optional.

You need to create a config/clockwork.rb file using the following schema:

module Clockwork
  every(1.hour, 'my_job') { MyWorker.perform_async }
end

Note that the clockwork process is started in every container. We recommend using sidekiq-unique-jobs to ensure that jobs are scheduled only once.

Custom services

You can run additional services by putting their executable files in the application bin/services folder.

Rails Migrations / rails_migrate_mutex

rails_migrate_mutex is used to run Rails migrations. If you have the gem installed in you app, migrations are automatically run on container startup. Using rails_migrate_mutex is optional.

Ruby / Packages

The latest ruby version is included in the container. It is compiled from source and uses jemalloc. The latest rubygems and bundler versions are installed as well.

The following tools are installed: git, nodejs, imagemagick, curl, bower. Development packages for compiling the following gems are included: sqlite3, pg, mysql2, nokogiri.

Have a look at the Base Dockerfile for more details.

App Installation / Docker ONBUILD

The final docker image has ONBUILD hooks that set up your application. It installs all gems except those in the development and test groups.

If the sprockets gem is present (default for Rails apps), it also precompiles assets. If you need any environment variables set for compiling assets, you can specify them in a .env file in your app root. This file will be sourced before running the task. Newer versions of sprockets will also automatically created gzipped versions of the assets. Rails then uses these static gzip files to serve assets.

Have a look at the ONBUILD Dockerfile for more details.

Environment Variables

All environment variables are passed on the application. Both RAILS_ENV and RACK_ENV are set to production and should not be changed.

Both RAILS_SERVE_STATIC_FILES and RAILS_LOG_TO_STDOUT are set, so you don't need to include the rails_12factor gem anymore if you're using Rails 5 or above and have updated your config/environments/production.rb file.

License

MIT, see LICENSE.txt

Contributing

Please create a new GitHub Issue if you encounter a bug or have a feature request.

Feel free to fork and submit pull requests!

docker-rails's People

Contributors

dziemba avatar tsujigiri avatar guigs avatar hwartig avatar ndreynolds avatar alanwilhelm avatar gaurish avatar rkushnir avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.