Skip to content

Commit

Permalink
Switch from Thin to Puma server to make Docker setup easier
Browse files Browse the repository at this point in the history
(and because I know Puma better)
  • Loading branch information
subelsky committed Jul 20, 2017
1 parent 64bdc80 commit 83606d6
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 38 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM ruby:2.3.4
FROM ruby:2.3.1
MAINTAINER Mike Subelsky <[email protected]>
RUN mkdir -p /var/app
COPY Gemfile /var/app/Gemfile
WORKDIR /var/app
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /coyote
WORKDIR /coyote
ADD Gemfile /coyote/Gemfile
ADD Gemfile.lock /coyote/Gemfile.lock
RUN bundle install
ADD . /coyote
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ gem 'cocoon' #nested forms
gem 'analytical' #analytics
gem 'metamagic' #meta
gem 'oj' #optimized json
gem "thin", ">= 1.6.3" # webserver
gem "puma"
gem 'turbolinks' #crazy fake ajax
gem 'responders' #respond_with ala http://www.justinweiss.com/blog/2014/11/03/respond-to-without-all-the-pain/
gem 'redcarpet'
Expand Down
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ GEM
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
puma (3.9.1)
quiet_assets (1.1.0)
railties (>= 3.1, < 5.0)
rack (1.6.4)
Expand Down Expand Up @@ -556,6 +557,7 @@ DEPENDENCIES
modular-scale
mysql2 (~> 0.3.18)
oj
puma
quiet_assets
rails (= 4.2.5.1)
rails_12factor
Expand All @@ -579,7 +581,6 @@ DEPENDENCIES
spring-commands-rspec
sprockets
sprockets-rails (~> 3.0.3)
thin (>= 1.6.3)
tilt
turbolinks
uglifier (>= 2.7.1)
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: bin/rails server thin -p $PORT
web: bundle exec puma -C config/puma.rb
17 changes: 17 additions & 0 deletions bin/puma
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'puma' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("puma", "puma")
17 changes: 17 additions & 0 deletions bin/pumactl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'pumactl' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("puma", "pumactl")
1 change: 1 addition & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
default: &default
adapter: mysql2
pool: <%= ENV["COYOTE_DB_POOL_SIZE"] || ENV["COYOTE_NUM_THREADS"] || 5 %>
development:
<<: *default
database: <%= ENV.fetch("COYOTE_DEV_DATABASE_NAME","coyote_dev") %>
Expand Down
16 changes: 16 additions & 0 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
worker_count = ENV.fetch("COYOTE_PUMA_WORKERS",1).to_i
thread_count = ENV.fetch("COYOTE_NUM_THREADS",5).to_i

workers worker_count
threads thread_count, thread_count

tag "coyote"
preload_app!

rackup DefaultRackup
port ENV["PORT"] || 3000
environment ENV["RACK_ENV"] || "development"

on_worker_boot do
ActiveRecord::Base.establish_connection
end
14 changes: 0 additions & 14 deletions config/thin/production.yml

This file was deleted.

14 changes: 0 additions & 14 deletions config/thin/staging.yml

This file was deleted.

6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# NOTE: this is a work-in-progress. So far it can't start rails properly.
version: '2'
version: '3'
services:
web:
build: .
ports:
- 3000:3000
env_file: .env
volumes:
- .:/opt/webapp
command: ["bundle","exec","rails","server","-b","0.0.0.0"]
- .:/coyote
command: bin/rails server thin -b 0.0.0.0
depends_on:
- db
db:
Expand Down
2 changes: 2 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ASSET_SYNC_GZIP_COMPRESSION=true
ASSET_SYNC_MANIFEST=true
BOOKMARKLET=false
COYOTE_PUMA_WORKERS=1
COYOTE_NUM_THREADS=5
DATABASE_URL=mysql2://root:@localhost:5432/
FLOWDOCK_API_TOKEN=
FLOWDOCK_PROJECT_NAME=
Expand Down

0 comments on commit 83606d6

Please sign in to comment.