Skip to content
This repository has been archived by the owner on Dec 23, 2020. It is now read-only.

Commit

Permalink
Update to Ruby 2.4 and Rails 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjj committed Jun 16, 2017
1 parent a4c5ee2 commit ade64e7
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 362 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## orats 5.1.1 (June 17, 2017)

- Update Ruby to `2.4`
- Update rails to `5.1.1`
- Update sidekiq to `5.0`
- Update Puma to `3.9`
- Update pg to `0.21`
- Update redis-rails to `5.0`
- Bring back jQuery with `jquery-rails`
- Comment out Capybara in the `Gemfile` (Rails 5.1 has it enabled by default)
- Switch from Debian to Alpine as a base image in the `Dockerfile`
- Remove compiling assets inside of the `Dockerfile`
- Hard code `/app` in the `Dockerfile` and `docker-compose.yml` volumes
- Change the `MAINTAINER` instruction to use a `LABEL` in the `Dockerfile`

## orats 5.0.3 (December 21, 2016)

- Update Rails to `5.0.1`
Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ application on top of it.
It also happens to use Docker so that your app can be ran on any major
platform -- even without needing Ruby installed.

If you want to learn about Docker specifically then I recommend checking out
the [Dive Into Docker: The Complete Docker Course for Developers course](https://diveintodocker.com/courses/dive-into-docker). You can even watch the
first 20 videos for free.

## What versions are you targeting?

#### Ruby 2.3+
#### Ruby 2.4+

#### Rails 5+
#### Rails 5.1+

#### Docker 1.11+
#### Docker 1.11+ / Docker Compose API v2+

## Contents
- [Installation](#installation)
Expand Down Expand Up @@ -86,6 +90,8 @@ add it.
- Use `redis` as the cache backend
- Use `sidekiq` as a background worker through Active Job
- Use a standalone Action Cable server
- jQuery is installed with `jquery-rails`
- Capybara is commented out in the `Gemfile`
- **Features**:
- Add a `pages` controller with `home` action
- **Config**:
Expand Down Expand Up @@ -120,6 +126,8 @@ add it.
Check out the blog post
[Dockerize a Rails 5, Postgres, Redis, Sidekiq and Action Cable Application](http://nickjanetakis.com/blog/dockerize-a-rails-5-postgres-redis-sidekiq-action-cable-app-with-docker-compose).

Another option is to take my [Dive Into Docker course](https://diveintodocker.com/courses/dive-into-docker).

#### What do I do after I generate the application?

Start by reading the above blog post, because the Docker blog post explains
Expand Down Expand Up @@ -178,7 +186,7 @@ cp -r /tmp/orats/lib/orats/templates/base /tmp/foo_bar
# Swap a few custom values into the base project.
find /tmp/foo_bar -type f -exec sed -i -e 's/OratsBase/FooBar/g' {} \;
find /tmp/foo_bar -type f -exec sed -i -e 's/orats_base/foo_bar/g' {} \;
find /tmp/foo_bar -type f -exec sed -i -e 's/VERSION/5.0.3/g' {} \;
find /tmp/foo_bar -type f -exec sed -i -e 's/VERSION/5.1.1/g' {} \;

# Rename the example .env file since `.env` is git ignored.
mv /tmp/orats/.env.example /tmp/orats/.env
Expand Down
97 changes: 5 additions & 92 deletions lib/orats/templates/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,102 +1,15 @@
FROM ruby:2.3-slim
# Docker images can start off with nothing, but it's extremely
# common to pull in from a base image. In our case we're pulling
# in from the slim version of the official Ruby 2.3 image.
#
# Details about this image can be found here:
# https://hub.docker.com/_/ruby/
#
# Slim is pulling in from the official Debian Jessie image.
#
# You can tell it's using Debian Jessie by clicking the
# Dockerfile link next to the 2.3-slim bullet on the Docker hub.
#
# The Docker hub is the standard place for you to find official
# Docker images. Think of it like GitHub but for Docker images.
FROM ruby:2.4-alpine

MAINTAINER Nick Janetakis <nick.janetakis@gmail.com>
# It is good practice to set a maintainer for all of your Docker
# images. It's not necessary but it's a good habit.
RUN apk update && apk add build-base nodejs postgresql-dev

RUN apt-get update && apt-get install -qq -y --no-install-recommends \
build-essential nodejs libpq-dev
# Ensure that our apt package list is updated and install a few
# packages to ensure that we can compile assets (nodejs) and
# communicate with PostgreSQL (libpq-dev).

ENV INSTALL_PATH /orats_base
# The name of the application is orats_base and while there
# is no standard on where your project should live inside of the Docker
# image, I like to put it in the root of the image and name it
# after the project.
#
# We don't even need to set the INSTALL_PATH variable, but I like
# to do it because we're going to be referencing it in a few spots
# later on in the Dockerfile.
#
# The variable could be named anything you want.

RUN mkdir -p $INSTALL_PATH
# This just creates the folder in the Docker image at the
# install path we defined above.

WORKDIR $INSTALL_PATH
# We're going to be executing a number of commands below, and
# having to CD into the /orats_base folder every time would be
# lame, so instead we can set the WORKDIR to be /orats_base.
#
# By doing this, Docker will be smart enough to execute all
# future commands from within this directory.
RUN mkdir /app
WORKDIR /app

COPY Gemfile Gemfile.lock ./
# This is going to copy in the Gemfile and Gemfile.lock from our
# work station at a path relative to the Dockerfile to the
# orats_base/ path inside of the Docker image.
#
# It copies it to /orats_base because of the WORKDIR being set.
#
# We copy in our Gemfile before the main app because Docker is
# smart enough to cache "layers" when you build a Docker image.
#
# You see, each command we have in the Dockerfile is going to be
# ran and then saved as a separate layer. Docker is smart enough
# to only re-build pieces that change, in order from top to bottom.
#
# This is an advanced concept but it means that we'll be able to
# cache all of our gems so that if we make an application code
# change, it won't re-run bundle install unless a gem changed.

RUN bundle install --binstubs
# We want binstubs to be available so we can directly call sidekiq and
# potentially other binaries as command overrides without depending on
# bundle exec.
# This is mainly due for production compatibility assurance.

COPY . .
# This might look a bit alien but it's copying in everything from
# the current directory relative to the Dockerfile, over to the
# /orats_base folder inside of the Docker image.
#
# We can get away with using the . for the second argument because
# this is how the unix command cp (copy) works. It stands for the
# current directory.

RUN bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:pass@127.0.0.1/dbname ACTION_CABLE_ALLOWED_REQUEST_ORIGINS=foo,bar SECRET_TOKEN=dummytoken assets:precompile
# Provide a dummy DATABASE_URL and more to Rails so it can pre-compile
# assets. The values do not need to be real, just valid syntax.
#
# If you're saving your assets to a CDN and are working with multiple
# app instances, you may want to remove this step and deal with asset
# compilation at a different stage of your deployment.

VOLUME ["$INSTALL_PATH/public"]
# In production you will very likely reverse proxy Rails with nginx.
# This sets up a volume so that nginx can read in the assets from
# the Rails Docker image without having to copy them to the Docker host.
LABEL maintainer="Nick Janetakis <nick.janetakis@gmail.com>"

CMD puma -C config/puma.rb
# This is the command that's going to be ran by default if you run the
# Docker image without any arguments.
#
# In our case, it will start the Puma app server while passing in
# its config file.
27 changes: 18 additions & 9 deletions lib/orats/templates/base/Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
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

# Looking to use the Edge version? gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.1'
gem 'rails', '~> 5.1.1'

# Use Puma as the app server
gem 'puma', '~> 3.0'
gem 'puma', '~> 3.9'

# Use Rack Timeout. Read more: https://github.com/heroku/rack-timeout
gem 'rack-timeout', '~> 0.4'
Expand All @@ -13,19 +18,19 @@ gem 'rack-timeout', '~> 0.4'
gem 'jbuilder', '~> 2.5'

# Use PostgreSQL as the database for Active Record
gem 'pg', '~> 0.18'
gem 'pg', '~> 0.21'

# Use Redis Rails to set up a Redis backed Cache and / or Session
gem 'redis-rails', '~> 5.0.0.pre'
gem 'redis-rails', '~> 5.0'

# Use Sidekiq as a background job processor through Active Job
gem 'sidekiq', '~> 4.2'
gem 'sidekiq', '~> 5.0'

# Use Clockwork for recurring background tasks without needing cron
# gem 'clockwork', '~> 2.0'

# Use Kaminari for pagination
# gem 'kaminari', '~> 0.16'
# gem 'kaminari', '~> 0.17'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
Expand All @@ -34,7 +39,7 @@ gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'

# Use jQuery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-rails', '~> 4.3'

# Use Turbolinks. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
Expand All @@ -48,6 +53,10 @@ gem 'font-awesome-rails', '~> 4.7'
group :development, :test do
# Call 'byebug' anywhere in your code to drop into a debugger console
gem 'byebug', platform: :mri

# End to end testing of your rails apps (Rails 5.1+ supports this)
# gem 'capybara', '~> 2.13'
# gem 'selenium-webdriver'
end

group :development do
Expand All @@ -58,12 +67,12 @@ group :development do
gem 'web-console', '~> 3.3.0'

# Get notified of file changes. Read more: https://github.com/guard/listen
gem 'listen', '~> 3.0.5'
gem 'listen', '>= 3.0.5', '< 3.2'

# Use Spring. 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]
gem 'tzinfo-data'
Loading

0 comments on commit ade64e7

Please sign in to comment.