Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit

Permalink
Capistrano deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
afischer committed Aug 23, 2018
1 parent a8f1806 commit b4e49f8
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 26 deletions.
40 changes: 40 additions & 0 deletions Capfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Load DSL and set up stages
require "capistrano/setup"

# Include default deployment tasks
require "capistrano/deploy"

# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
require 'capistrano/rails'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/puma'
require 'capistrano/scm/git'
require 'capistrano/rails/console'

set :rvm_type, :user
set :rvm_ruby_version, '2.4.1'
install_plugin Capistrano::Puma
install_plugin Capistrano::SCM::Git
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ group :development do
gem 'better_errors'
gem 'rails_layout'
end
group :development do
gem 'capistrano'
gem 'capistrano-rails'
gem 'capistrano-rvm'
gem 'capistrano3-puma', github: 'seuros/capistrano-puma'
gem 'capistrano-bundler'
gem 'capistrano-rails-console'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'bootstrap-sass'
gem 'jquery-rails'
Expand Down
44 changes: 43 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ GIT
sprockets (>= 3.0, < 4.1)
sprockets-es6 (>= 0.9.2)

GIT
remote: https://github.com/seuros/capistrano-puma.git
revision: 81647bc8402ff1cb485e81d9ec803dfec31aa851
specs:
capistrano3-puma (3.1.1)
capistrano (~> 3.7)
capistrano-bundler
puma (~> 3.4)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -65,6 +74,8 @@ GEM
tzinfo (~> 1.1)
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
airbrussh (1.3.0)
sshkit (>= 1.6.1, != 1.7.0)
arbre (1.1.1)
activesupport (>= 3.0.0)
arel (8.0.0)
Expand All @@ -87,6 +98,23 @@ GEM
momentjs-rails (>= 2.8.1)
builder (3.2.3)
byebug (9.0.6)
capistrano (3.11.0)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
sshkit (>= 1.9.0)
capistrano-bundler (1.3.0)
capistrano (~> 3.1)
sshkit (~> 1.2)
capistrano-rails (1.4.0)
capistrano (~> 3.1)
capistrano-bundler (~> 1.1)
capistrano-rails-console (2.3.0)
capistrano (>= 3.5.0, < 4.0.0)
sshkit-interactive (~> 0.3.0)
capistrano-rvm (0.1.2)
capistrano (~> 3.0)
sshkit (~> 1.2)
capybara (2.15.1)
addressable
mini_mime (>= 0.1.3)
Expand Down Expand Up @@ -174,6 +202,9 @@ GEM
multi_xml (0.6.0)
multipart-post (2.0.0)
mysql2 (0.4.9)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (5.0.2)
nio4r (2.1.0)
nokogiri (1.8.0)
mini_portile2 (~> 2.2.0)
Expand Down Expand Up @@ -280,6 +311,11 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
sshkit (1.17.0)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
sshkit-interactive (0.3.0)
sshkit (~> 1.12)
thor (0.20.0)
thread_safe (0.3.6)
tilt (2.0.8)
Expand Down Expand Up @@ -318,6 +354,12 @@ DEPENDENCIES
bootstrap-sass
bootstrap3-datetimepicker-rails (~> 4.17.47)
byebug
capistrano
capistrano-bundler
capistrano-rails
capistrano-rails-console
capistrano-rvm
capistrano3-puma!
capybara (~> 2.13)
fb_graph2
filterrific
Expand Down Expand Up @@ -352,4 +394,4 @@ RUBY VERSION
ruby 2.4.1p111

BUNDLED WITH
1.16.0
1.16.1
8 changes: 4 additions & 4 deletions app/assets/javascripts/ads.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
document.addEventListener('turbolinks:load', () => {
googletag.cmd.push(() => googletag.display('div-gpt-ad-1529280717739-0'));
googletag.cmd.push(() => googletag.display('div-gpt-ad-1529280717739-1'));
googletag.cmd.push(() => googletag.display('div-gpt-ad-1529280717739-2'));
document.addEventListener('turbolinks:load', function() {
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1529280717739-0') });
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1529280717739-1') });
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1529280717739-2') });
})
44 changes: 44 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# config valid for current version and patch releases of Capistrano
lock "~> 3.11.0"

set :forward_agent, true
set :bundle_flags, '--deployment' # verbose bundler output
set :application, "eventsatpenn"
set :repo_url, "[email protected]:dailypenn/eventsatpenn.git"

# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp

# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, "/home/rails/html"

# Default value for :format is :airbrussh.
# set :format, :airbrussh

# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto

# Default value for :pty is false
set :pty, true

# puma configuration
set :puma_conf, "#{shared_path}/config/puma.rb"

# Default value for :linked_files is []
append :linked_files, "config/database.yml", "config/secrets.yml", ".env"

# Default value for linked_dirs is []
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

# Default value for local_user is ENV['USER']
# set :local_user, -> { `git config user.name`.chomp }

# Default value for keep_releases is 5
# set :keep_releases, 5

# Uncomment the following to require manually verifying the host key before first deploy.
# set :ssh_options, verify_host_key: :secure
63 changes: 63 additions & 0 deletions config/deploy/production.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# server-based syntax
# ======================
# Defines a single server with a list of roles and multiple properties.
# You can define all roles on a single server, or split them:

server '35.194.71.134', user: 'rails', roles: %w{app db web}

# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value
# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value
# server "db.example.com", user: "deploy", roles: %w{db}



# role-based syntax
# ==================

# Defines a role with one or multiple servers. The primary server in each
# group is considered to be the first unless any hosts have the primary
# property set. Specify the username and a domain or IP for the server.
# Don't use `:all`, it's a meta role.

# role :app, %w{[email protected]}, my_property: :my_value
# role :web, %w{[email protected] [email protected]}, other_property: :other_value
# role :db, %w{[email protected]}



# Configuration
# =============
# You can set any configuration variable like in config/deploy.rb
# These variables are then only loaded and set in this stage.
# For available Capistrano configuration variables see the documentation page.
# http://capistranorb.com/documentation/getting-started/configuration/
# Feel free to add new variables to customise your setup.



# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
#
# The server-based syntax can be used to override options:
# ------------------------------------
# server "example.com",
# user: "user_name",
# roles: %w{web app},
# ssh_options: {
# user: "user_name", # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: "please use keys"
# }
61 changes: 61 additions & 0 deletions config/deploy/staging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# server-based syntax
# ======================
# Defines a single server with a list of roles and multiple properties.
# You can define all roles on a single server, or split them:

# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value
# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value
# server "db.example.com", user: "deploy", roles: %w{db}



# role-based syntax
# ==================

# Defines a role with one or multiple servers. The primary server in each
# group is considered to be the first unless any hosts have the primary
# property set. Specify the username and a domain or IP for the server.
# Don't use `:all`, it's a meta role.

# role :app, %w{[email protected]}, my_property: :my_value
# role :web, %w{[email protected] [email protected]}, other_property: :other_value
# role :db, %w{[email protected]}



# Configuration
# =============
# You can set any configuration variable like in config/deploy.rb
# These variables are then only loaded and set in this stage.
# For available Capistrano configuration variables see the documentation page.
# http://capistranorb.com/documentation/getting-started/configuration/
# Feel free to add new variables to customise your setup.



# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
#
# The server-based syntax can be used to override options:
# ------------------------------------
# server "example.com",
# user: "user_name",
# roles: %w{web app},
# ssh_options: {
# user: "user_name", # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: "please use keys"
# }
37 changes: 16 additions & 21 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
#!/usr/bin/env puma
if ENV.fetch('RAILS_ENV') == 'production'
# Change to match your CPU core count
workers 1

# Min and Max threads per worker
threads 1, 6
directory '/home/rails/html/current'
rackup "/home/rails/html/current/config.ru"
environment 'production'

app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"
tag ''

# Default to production
rails_env = ENV['RAILS_ENV'] || "production"
environment rails_env
pidfile "/home/rails/html/shared/tmp/pids/puma.pid"
state_path "/home/rails/html/shared/tmp/pids/puma.state"
stdout_redirect '/home/rails/html/shared/log/puma_access.log', '/home/rails/html/shared/log/puma_error.log', true

# Set up socket location
bind "unix://#{shared_dir}/sockets/puma.sock"
threads 0,16

# Logging
stdout_redirect "#{app_dir}/log/production.log", "#{app_dir}/log/production.log", true
bind 'unix:///home/rails/html/shared/tmp/sockets/puma.sock'

# Set master PID and state locations
pidfile "#{shared_dir}/pids/puma.pid"
state_path "#{shared_dir}/pids/puma.state"
activate_control_app
workers 0

on_worker_boot do
require "active_record"
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
prune_bundler

on_restart do
puts 'Refreshing Gemfile'
ENV["BUNDLE_GEMFILE"] = "/home/rails/html/current/Gemfile"
end
else
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
Expand Down

0 comments on commit b4e49f8

Please sign in to comment.