Capistrano config deploy

This commit is contained in:
Jesse C. Fisher 2015-08-21 02:13:30 -07:00
parent 9ff5259cb1
commit 3c60a9b896
6 changed files with 224 additions and 122 deletions

12
Capfile
View File

@ -4,6 +4,18 @@ require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
require 'capistrano/puma'
require 'capistrano/puma/workers'
require 'capistrano/puma/jungle'
require 'capistrano/puma/monit'
require 'capistrano/rbenv'
require 'capistrano/bundler'
require 'capistrano/nginx'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
#require 'capistrano/bower'
# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:

10
Gemfile
View File

@ -23,11 +23,15 @@ group :development do
gem 'rubocop', require: false
gem 'haml-lint', require: false
gem 'binding_of_caller'
gem 'capistrano', '~> 3.0.1'
gem 'capistrano'
gem 'capistrano-bundler'
gem 'capistrano-rails', '~> 1.1.0'
gem 'capistrano-rails'
gem 'capistrano-rails-console'
gem 'capistrano-rvm', '~> 0.1.1'
#gem 'capistrano-rvm'
gem 'capistrano3-puma'
gem 'capistrano-rbenv'
gem 'capistrano-nginx', github: 'koenpunt/capistrano-nginx'
gem "capistrano-db-tasks", require: false
gem 'foreman'
gem 'guard-bundler'
gem 'guard-rails'

View File

@ -1,3 +1,10 @@
GIT
remote: git://github.com/koenpunt/capistrano-nginx.git
revision: 5a91aed41c16fb38b6d9d9462ba1ddfe76dede55
specs:
capistrano-nginx (0.2.1)
capistrano (~> 3.1)
GEM
remote: https://rubygems.org/
specs:
@ -27,181 +34,183 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
addressable (2.3.6)
addressable (2.3.8)
arel (5.0.1.20140414130214)
ast (2.0.0)
astrolabe (1.3.0)
parser (>= 2.2.0.pre.3, < 3.0)
bcrypt (3.1.9)
better_errors (2.1.0)
ast (2.1.0)
astrolabe (1.3.1)
parser (~> 2.2)
bcrypt (3.1.10)
better_errors (2.1.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
rack (>= 0.9.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
capistrano (3.0.1)
capistrano (3.4.0)
i18n
rake (>= 10.0.0)
sshkit (>= 0.0.23)
capistrano-bundler (1.1.2)
capistrano (~> 3.0)
sshkit (~> 1.3)
capistrano-bundler (1.1.4)
capistrano (~> 3.1)
sshkit (~> 1.2)
capistrano-rails (1.1.0)
capistrano-db-tasks (0.4)
capistrano (>= 3.0.0)
capistrano-bundler (>= 1.0.0)
capistrano-rails-console (0.3.0)
capistrano (>= 3.0.0)
capistrano-rvm (0.1.2)
capistrano-rails (1.1.3)
capistrano (~> 3.1)
capistrano-bundler (~> 1.1)
capistrano-rails-console (1.0.0)
capistrano (>= 3.1.0, < 4.0.0)
capistrano-rbenv (2.0.3)
capistrano (~> 3.1)
sshkit (~> 1.3)
capistrano3-puma (1.2.1)
capistrano (~> 3.0)
sshkit (~> 1.2)
puma (>= 2.6)
capybara (2.4.4)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
celluloid (0.16.0)
timers (~> 4.0.0)
childprocess (0.5.6)
ffi (~> 1.0, >= 1.0.11)
coderay (1.1.0)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.3.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.8.0)
colorize (0.7.5)
database_cleaner (1.3.0)
coffee-script-source (1.9.1.1)
colorize (0.7.7)
database_cleaner (1.4.1)
debug_inspector (0.0.2)
devise (3.4.1)
devise (3.5.2)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
responders
thread_safe (~> 0.1)
warden (~> 1.2.3)
devise_invitable (1.4.0)
devise_invitable (1.5.2)
actionmailer (>= 3.2.6, < 5)
devise (>= 3.2.0)
diff-lcs (1.2.5)
dotenv (1.0.2)
erubis (2.7.0)
execjs (2.2.2)
execjs (2.6.0)
factory_girl (4.5.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.5.0)
factory_girl (~> 4.5.0)
railties (>= 3.0.0)
faker (1.4.3)
faker (1.5.0)
i18n (~> 0.5)
ffi (1.9.10)
foreman (0.76.0)
dotenv (~> 1.0.2)
foreman (0.78.0)
thor (~> 0.19.1)
formatador (0.2.5)
guard (2.10.5)
guard (2.13.0)
formatador (>= 0.2.4)
listen (~> 2.7)
listen (>= 2.7, <= 4.0)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-bundler (2.1.0)
bundler (~> 1.0)
guard (~> 2.2)
guard-compat (~> 1.1)
guard-compat (1.2.0)
guard-compat (1.2.1)
guard-ctags-bundler (1.4.0)
guard (>= 2.0)
guard-compat (>= 0.1.0)
guard-rails (0.7.0)
guard (~> 2.0)
guard-rspec (4.5.0)
guard-rails (0.7.2)
guard (~> 2.11)
guard-compat (~> 1.0)
guard-rspec (4.6.4)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
haml (4.1.0.beta.1)
haml (4.0.7)
tilt
haml-lint (0.12.0)
haml-lint (0.13.0)
haml (~> 4.0)
rubocop (>= 0.25.0)
sysexits (~> 1.1)
haml-rails (0.6.0)
haml-rails (0.9.0)
actionpack (>= 4.0.1)
activesupport (>= 4.0.1)
haml (>= 3.1, < 5.0)
haml (>= 4.0.6, < 5.0)
html2haml (>= 1.0.1)
railties (>= 4.0.1)
high_voltage (2.2.1)
high_voltage (2.4.0)
hike (1.2.3)
hitimes (1.2.2)
hpricot (0.8.6)
html2haml (1.0.1)
html2haml (2.0.0)
erubis (~> 2.7.0)
haml (>= 4.0.0.rc.1)
hpricot (~> 0.8.6)
ruby_parser (~> 3.1.1)
haml (~> 4.0.0)
nokogiri (~> 1.6.0)
ruby_parser (~> 3.5)
hub (1.12.4)
i18n (0.7.0)
interception (0.5)
jbuilder (2.2.6)
jbuilder (2.3.1)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (3.1.2)
jquery-rails (3.1.3)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
kaminari (0.16.1)
kaminari (0.16.3)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
launchy (2.4.3)
addressable (~> 2.3)
listen (2.8.4)
celluloid (>= 0.15.2)
listen (3.0.3)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
lumberjack (1.0.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.4.3)
mime-types (2.6.1)
mini_portile (0.6.2)
minitest (5.5.0)
minitest (5.8.0)
multi_json (1.11.2)
nenv (0.1.1)
nenv (0.2.0)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.9.1)
nokogiri (1.6.5)
net-ssh (2.9.2)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
notiffany (0.0.7)
nenv (~> 0.1)
shellany (~> 0.0)
orm_adapter (0.5.0)
parser (2.2.0.1)
parser (2.2.2.6)
ast (>= 1.1, < 3.0)
slop (~> 3.4, >= 3.4.5)
pg (0.17.1)
polyamorous (1.1.0)
pg (0.18.2)
polyamorous (1.2.0)
activerecord (>= 3.0)
powerpack (0.0.9)
powerpack (0.1.1)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-rails (0.3.2)
pry-rails (0.3.4)
pry (>= 0.9.10)
pry-rescue (1.4.1)
pry-rescue (1.4.2)
interception (>= 0.5)
pry
puma (2.10.2)
rack (>= 1.1, < 2.0)
pundit (0.3.0)
puma (2.13.4)
pundit (1.0.1)
activesupport (>= 3.0.0)
quiet_assets (1.1.0)
railties (>= 3.1, < 5.0)
rack (1.5.2)
rack-test (0.6.2)
rack (1.5.5)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.1.8)
actionmailer (= 4.1.8)
@ -213,7 +222,7 @@ GEM
bundler (>= 1.3.0, < 2.0)
railties (= 4.1.8)
sprockets-rails (~> 2.0)
rails_layout (1.0.24)
rails_layout (1.0.26)
railties (4.1.8)
actionpack (= 4.1.8)
activesupport (= 4.1.8)
@ -221,49 +230,50 @@ GEM
thor (>= 0.18.1, < 2.0)
rainbow (2.0.0)
rake (10.4.2)
ransack (1.5.1)
ransack (1.7.0)
actionpack (>= 3.0)
activerecord (>= 3.0)
activesupport (>= 3.0)
i18n
polyamorous (~> 1.1)
polyamorous (~> 1.2)
rb-fchange (0.0.6)
ffi
rb-fsevent (0.9.4)
rb-fsevent (0.9.5)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
rdoc (4.2.0)
json (~> 1.4)
responders (1.1.2)
railties (>= 3.2, < 4.2)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
rspec (3.3.0)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-core (3.3.2)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-rails (3.1.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
rubocop (0.28.0)
rspec-support (~> 3.3.0)
rspec-mocks (3.3.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-rails (3.3.3)
actionpack (>= 3.0, < 4.3)
activesupport (>= 3.0, < 4.3)
railties (>= 3.0, < 4.3)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
rubocop (0.33.0)
astrolabe (~> 1.3)
parser (>= 2.2.0.pre.7, < 3.0)
powerpack (~> 0.0.6)
parser (>= 2.2.2.5, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-progressbar (1.7.1)
ruby_parser (3.1.3)
ruby-progressbar (1.7.5)
ruby_parser (3.7.1)
sexp_processor (~> 4.1)
rubyzip (1.1.7)
sass (3.2.19)
@ -280,38 +290,37 @@ GEM
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0)
sexp_processor (4.4.4)
sexp_processor (4.6.0)
shellany (0.0.1)
simple_form (3.1.0)
actionpack (~> 4.0)
activemodel (~> 4.0)
slop (3.6.0)
spring (1.2.0)
spring (1.3.6)
spring-commands-rspec (1.0.4)
spring (>= 0.9.1)
sprockets (2.12.3)
sprockets (2.12.4)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.2.2)
sprockets-rails (2.3.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sshkit (1.6.1)
sshkit (1.7.1)
colorize (>= 0.7.0)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
sysexits (1.2.0)
thor (0.19.1)
thread_safe (0.3.4)
thread_safe (0.3.5)
tilt (1.4.1)
timers (4.0.1)
hitimes
turbolinks (2.5.3)
coffee-rails
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.6.1)
uglifier (2.7.1)
execjs (>= 0.3.0)
json (>= 1.8.0)
upmin-admin (0.1.01)
@ -333,11 +342,14 @@ PLATFORMS
DEPENDENCIES
better_errors
binding_of_caller
capistrano (~> 3.0.1)
capistrano
capistrano-bundler
capistrano-rails (~> 1.1.0)
capistrano-db-tasks
capistrano-nginx!
capistrano-rails
capistrano-rails-console
capistrano-rvm (~> 0.1.1)
capistrano-rbenv
capistrano3-puma
capybara
coffee-rails (~> 4.0.0)
database_cleaner

View File

@ -1,21 +1,52 @@
set :application, 'my_app_name'
set :repo_url, 'git@example.com:me/my_repo.git'
set :application, 'thirteen-tien-len'
set :repo_url, 'git@bitbucket.org:jessecfisher/thirteen-tien-len.git'
# If you want to import assets, you can change default asset dir (default = system)
# This directory must be in your shared directory on the server
set :assets_dir, %w(public/assets public/system)
#set :local_assets_dir, %w(public/assets public/att)
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
# set :deploy_to, '/var/www/my_app'
set :deploy_to, '/home/jesse/web/thirteen-tien-len'
# set :scm, :git
# set :format, :pretty
# set :log_level, :debug
# set :pty, true
# set :linked_files, %w{config/database.yml}
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :linked_files, %w{config/database.yml config/application.yml db/data.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/lift-calculator}
set :rbenv_type, :user # or :system, depends on your rbenv setup
set :rbenv_ruby, '2.2.3'
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
set :rbenv_roles, :all # default value
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# set :keep_releases, 5
set :nginx_path, '/etc/nginx' # directory containing sites-available and sites-enabled
set :nginx_template, 'config/deploy/nginx_conf.erb' # configuration template
#set :nginx_server_name, 'example.com' # optional, defaults to :application
#set :nginx_upstream, 'example-app' # optional, defaults to :application
set :nginx_listen, 80 # optional, default is not set
set :nginx_roles, :all
namespace :db do
desc 'Setup the database'
task :setup do
on roles(:app), in: :sequence, wait: 5 do
within release_path do
with rails_env: (fetch(:rails_env) || fetch(:stage)) do
execute :rake, 'db:setup'
end
end
end
end
end
namespace :deploy do
desc 'Restart application'
task :restart do

View File

@ -0,0 +1,40 @@
upstream <%= fetch(:nginx_upstream) %> {
server unix:///home/jesse/web/thirteen-tien-len/shared/tmp/sockets/puma.sock fail_timeout=0;
}
server {
<% if fetch(:nginx_listen, false) %>
listen <%= fetch(:nginx_listen) %>;
<% end %>
server_name <%= fetch(:nginx_server_name) %>;
root <%= current_path.join('public') %>;
try_files $uri/index.html $uri.html $uri @<%= fetch(:nginx_upstream) %>;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location @<%= fetch(:nginx_upstream) %> {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://<%= fetch(:nginx_upstream) %>;
}
if (-f $document_root/system/maintenance.html) {
return 503;
}
error_page 500 502 504 /500.html;
location = /500.html {
root <%= current_path.join('public') %>;
}
error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$ /system/maintenance.html break;
}
}

View File

@ -1,13 +1,15 @@
set :stage, :production
set :nginx_server_name, 'thirteen.cowabon.ga' # optional, defaults to :application
# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary
# server in each group is considered to be the first
# unless any hosts have the primary property set.
role :app, %w{deploy@example.com}
role :web, %w{deploy@example.com}
role :db, %w{deploy@example.com}
role :app, %w{jesse@ssh.cowabon.ga}
role :web, %w{jesse@ssh.cowabon.ga}
role :db, %w{jesse@ssh.cowabon.ga}
# Extended Server Syntax
# ======================
@ -15,17 +17,18 @@ role :db, %w{deploy@example.com}
# definition into the server list. The second argument
# something that quacks like a hash can be used to set
# extended properties on the server.
server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
server 'ssh.cowabon.ga', user: 'jesse', roles: %w{web app db}, my_property: :my_value
# you can set custom ssh options
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
# set it globally
# set :ssh_options, {
set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
port: 27997
}
# and/or per server
# server 'example.com',
# user: 'user_name',