Skip to content

Instantly share code, notes, and snippets.

@ferrerluis
Last active April 30, 2017 20:52
Show Gist options
  • Save ferrerluis/7c396cd509c24c78a658f319631ebf76 to your computer and use it in GitHub Desktop.
Save ferrerluis/7c396cd509c24c78a658f319631ebf76 to your computer and use it in GitHub Desktop.
Basic Docker containerization for Ruby (2.4) on Rails (5.0.0.1)
# MySQL. Versions 5.0 and up are supported.
#
# Install the MySQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.7/en/old-client.html
#
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
host: db
development:
<<: *default
database: app_development
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: app_test
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: app_production
username: app
password: <%= ENV['APP_DATABASE_PASSWORD'] %>
version: '2'
services:
rails:
image: rails5
build: .
command: /bin/bash ./entrypoint.sh
env_file: .env
volumes:
- .:/app
ports:
- "3000:3000"
volumes_from:
- bundle
depends_on:
- db
bundle:
image: rails5
command: echo "I'm a little data container"
volumes:
- /bundle
db:
image: mysql:5.7.17
volumes:
- ./db_data:/var/lib/mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=true
- MYSQL_DATABASE=app_development
FROM ruby:2.4.0
# Installing NodeJS for some Ruby gems needed by Rails
RUN apt-get update && apt-get install -y nodejs
ENV APP /app
RUN mkdir $APP
WORKDIR $APP
ENV BUNDLE_GEMFILE=$APP/Gemfile \
BUNDLE_JOBS=2 \
BUNDLE_PATH=/bundle
# Copies Gemfile and Gemfile.lock
COPY Gemfile* $APP/
RUN bundle install --without development test
COPY . $APP
# Precompiling assets
RUN bundle exec rake assets:precompile
# If running on Elastic Beanstalk. Heroku automatically sets the $PORT env variable
EXPOSE 3000
CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]
#!/bin/bash
if [ -f "tmp/pids/server.pid" ]; then
rm tmp/pids/server.pid
fi
bundle check || bundle install
bundle exec rails s -b 0.0.0.0
# Gems for pry debugging and rspec testing
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.2'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.18', '< 0.5'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem 'rack-cors'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'rspec'
gem 'rspec-rails', '~> 3.5'
gem 'pry'
end
group :development do
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment