capistrano-elobuff 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jason Coene
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # ELOBUFF Capistrano Recipes
2
+
3
+ These are some of the capistrano recipes we use at ELOBUFF. Hopefully you like them.
4
+
5
+ ## Usage
6
+
7
+ Require it in your deploy.rb file:
8
+
9
+ ```ruby
10
+ require "capistrano/elobuff"
11
+ ```
12
+
13
+ Then set some defaults:
14
+
15
+ ```ruby
16
+ set :application, "myapp"
17
+ set :user, "myuser"
18
+ set :repository, "git@github.com/mycompany/myapp.git"
19
+ ```
20
+
21
+ ## MIT License
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
24
+
25
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
26
+
27
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.authors = ["Jason Coene"]
4
+ gem.email = ["jcoene@gmail.com"]
5
+ gem.description = "Capistrano recipes we use at ELOBUFF"
6
+ gem.summary = "Capistrano recipes we use at ELOBUFF"
7
+ gem.homepage = "https://github.com/elobuff/capistrano_elobuff"
8
+
9
+ gem.files = `git ls-files`.split($\)
10
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
11
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
+ gem.name = "capistrano-elobuff"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = "0.1.0"
15
+
16
+ gem.add_dependency "capistrano"
17
+ end
@@ -0,0 +1,8 @@
1
+ require "capistrano"
2
+ require "capistrano/cli"
3
+
4
+ require "capistrano/elobuff/helpers"
5
+ require "capistrano/elobuff/base"
6
+ require "capistrano/elobuff/defaults"
7
+
8
+ Dir.glob(File.join(File.dirname(__FILE__), "/elobuff/recipes/*.rb")).sort.each {|f| load f }
@@ -0,0 +1,28 @@
1
+ Capistrano::Configuration.instance.load do
2
+ desc "Setup the application"
3
+ task :setup do; end
4
+
5
+ [:start, :stop, :restart, :status].each do |command|
6
+ desc "#{command.to_s.capitalize} services"
7
+ task command do; end
8
+ end
9
+
10
+ namespace :deploy do
11
+ desc "Perform a simple deployment"
12
+ task :default do
13
+ update_code
14
+ web.restart
15
+ end
16
+
17
+ desc "Perform a full deploy with database migrations"
18
+ task :full do
19
+ top.stop
20
+ update_code
21
+ upgrade_database
22
+ top.start
23
+ end
24
+
25
+ task :update_code do; end
26
+ task :upgrade_database do; end
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :application, :user, :repository
3
+
4
+ set_default(:env) { "production" }
5
+ set_default(:user_home) { "/home/#{user}" }
6
+ set_default(:current_path) { "#{user_home}/#{application}" }
7
+ set_default(:branch) { "origin/master" }
8
+ set_default(:scm) { :git }
9
+
10
+ set :default_environment, { "PATH" => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH" }
11
+
12
+ ssh_options[:forward_agent] = true
13
+ end
@@ -0,0 +1,37 @@
1
+ def act_as(name, &block)
2
+ normal_user = user
3
+ set :user, name.to_s
4
+ yield
5
+ set :user, normal_user
6
+ end
7
+
8
+ def runtime_environment_exports
9
+ file = "deploy/#{env}/env"
10
+ raise "Missing deployment file: #{file}" unless File.exists?(file)
11
+
12
+ File.read(file).split("\n").map do |line|
13
+ k, v = line.split("=")
14
+ %Q(export #{k}="#{v}";)
15
+ end.join(" ")
16
+ end
17
+
18
+ def upload_template(template_name, destination)
19
+ file = "deploy/#{env}/#{template_name}.erb"
20
+ raise "Missing deployment file: #{file}" unless File.exists?(file)
21
+
22
+ erb = File.read(file)
23
+ result = ERB.new(erb).result(binding)
24
+ put result, destination
25
+ end
26
+
27
+ def require_settings(*methods)
28
+ methods.each do |method|
29
+ set_default(method.to_sym) { raise "Please set #{method} "}
30
+ end
31
+ end
32
+
33
+ def set_default(name, *args, &block)
34
+ unless exists?(name)
35
+ set(name, *args, &block)
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :current_path
3
+ set_default(:bundle_without) { "assets test development" }
4
+
5
+ after "deploy:update_code", "bundler:bundle"
6
+
7
+ namespace :bundler do
8
+ desc "Update the bundle"
9
+ task :bundle do
10
+ run "cd #{current_path} && bundle install --deployment --binstubs --without '#{bundle_without}'"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :current_path, :repository, :branch
3
+
4
+ before "setup", "code:setup"
5
+ before "deploy:update_code", "code:update"
6
+
7
+ namespace :code do
8
+ desc "Clone the repository"
9
+ task :setup do
10
+ run "git clone #{repository} #{current_path}"
11
+ end
12
+
13
+ desc "Update the repository"
14
+ task :update do
15
+ run "cd #{current_path} && git fetch origin && git reset --hard #{branch}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :current_path
3
+
4
+ namespace :console do
5
+ desc "Open a remote console"
6
+ task :default do
7
+ server = find_servers(roles: [:db]).first
8
+ exec "ssh -t -l #{user} #{server.host} -t 'source ~/.bash_profile && cd #{current_path} && foreman run bundle exec rails console'"
9
+ end
10
+
11
+ desc "Run a local console"
12
+ task :local do
13
+ exec "#{runtime_environment_exports} bundle exec rails console"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :application, :env, :current_path
3
+
4
+ after "deploy:update_code", "cron:update"
5
+ after "stop", "cron:clear"
6
+
7
+ namespace :cron do
8
+ desc "Update the crontab"
9
+ task :update, roles: :db, on_no_matching_servers: :continue do
10
+ run "cd #{current_path}; bundle exec whenever --update-crontab #{application}_#{env} --set environment=#{env}"
11
+ end
12
+
13
+ desc "Clear the crontab"
14
+ task :clear, roles: :db, on_no_matching_servers: :continue do
15
+ run "cd #{current_path}; bundle exec whenever --clear-crontab #{application}_#{env} --set environment=#{env}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :current_path
3
+
4
+ after "deploy:upgrade_database", "database:migrate"
5
+ after "deploy:upgrade_database", "database:seed"
6
+
7
+ namespace :database do
8
+ desc "Migrate the database"
9
+ task :migrate, roles: :db, on_no_matching_servers: :continue do
10
+ run "cd #{current_path}; foreman run bundle exec rake db:migrate"
11
+ end
12
+
13
+ desc "Seed the database"
14
+ task :seed, roles: :db, on_no_matching_servers: :continue do
15
+ run "cd #{current_path}; foreman run bundle exec rake db:seed"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :current_path, :application, :env, :user
3
+
4
+ after "deploy:update_code", "foreman:update_config"
5
+ after "deploy:update_code", "foreman:export"
6
+
7
+ namespace :foreman do
8
+ desc "Upload the foreman configuration files"
9
+ task :update_config do
10
+ upload "deploy/#{env}/foreman", "#{current_path}/.foreman"
11
+ upload "deploy/#{env}/env", "#{current_path}/.env"
12
+ end
13
+
14
+ desc "Export the system init files"
15
+ task :export do
16
+ run "cd #{current_path}; sudo foreman export upstart /etc/init -a #{application} -u #{user} -l #{current_path}/log"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,42 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :current_path, :user
3
+
4
+ namespace :logs do
5
+ desc "See free space"
6
+ task :space do
7
+ run "df -alh /"
8
+ end
9
+
10
+ desc "Recycle log files"
11
+ task :recycle do
12
+ run "cd #{current_path}/log; sudo chown #{user}:#{user} *; for f in *.log; do echo '' >$f; done"
13
+ end
14
+
15
+ namespace :tail do
16
+ desc "Watch the log files with tail"
17
+ task :default do
18
+ run "tail -f -q #{current_path}/log/*.log"
19
+ end
20
+
21
+ desc "Watch the merger files with tail"
22
+ task :merger, roles: :db, on_no_matching_servers: :continue do
23
+ run "tail -f -q #{current_path}/log/merger*.log"
24
+ end
25
+
26
+ desc "Watch the scheduler files with tail"
27
+ task :scheduler, roles: :db, on_no_matching_servers: :continue do
28
+ run "tail -f -q #{current_path}/log/scheduler*.log"
29
+ end
30
+
31
+ desc "Watch the web log files with tail"
32
+ task :web, roles: :web, on_no_matching_servers: :continue do
33
+ run "tail -f -q #{current_path}/log/web*.log #{current_path}/log/production*.log"
34
+ end
35
+
36
+ desc "Watch the worker files with tail"
37
+ task :worker, roles: :worker, on_no_matching_servers: :continue do
38
+ run "tail -f -q #{current_path}/log/worker*.log"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,13 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :application
3
+
4
+ namespace :merger do
5
+ [:start, :stop, :restart, :status].each do |command|
6
+ desc "#{command.to_s.capitalize} the merger service"
7
+ task command, roles: :db, on_no_matching_servers: :continue do
8
+ run "sudo service #{application}-merger #{command} || true"
9
+ end
10
+ after command, "merger:#{command}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :current_path
3
+
4
+ after "deploy:update_code", "nginx:update_config"
5
+ before "setup", "nginx:stop"
6
+ after "setup", "nginx:update_config"
7
+ after "setup", "nginx:start"
8
+
9
+ namespace :nginx do
10
+ desc "Upload the nginx configuration file"
11
+ task :update_config, roles: :web, on_no_matching_servers: :continue do
12
+ run "mkdir -p #{current_path}/deploy || true"
13
+ upload_template "nginx.conf", "#{current_path}/deploy/nginx.conf"
14
+ end
15
+
16
+ [:start, :stop, :restart].each do |command|
17
+ desc "#{command.to_s.capitalize} the nginx service"
18
+ task command, roles: :web, on_no_matching_servers: :continue do
19
+ run "sudo service nginx #{command} || true"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :current_path
3
+
4
+ set_default(:ntp_server) { "time.apple.com" }
5
+
6
+ before "setup", "ntp:sync"
7
+
8
+ namespace :ntp do
9
+ desc "Sync time with a remote time server"
10
+ task :sync do
11
+ run "sudo ntpdate #{ntp_server}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :ps do
3
+ desc "Show running processes"
4
+ task :default do
5
+ run "ps x"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ Capistrano::Configuration.instance.load do
2
+ set_default(:ruby_version) { "1.9.3p194" }
3
+
4
+ after "setup", "ruby:setup"
5
+
6
+ namespace :ruby do
7
+ desc "Setup Ruby"
8
+ task :setup, roles: [:web, :db, :worker], on_no_matching_servers: :continue do
9
+ run "cd #{current_path} && rbenv local #{ruby_version} && gem install bundler foreman"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :application
3
+
4
+ namespace :scheduler do
5
+ [:start, :stop, :restart, :status].each do |command|
6
+ desc "#{command.to_s.capitalize} the scheduler service"
7
+ task command, roles: :db, on_no_matching_servers: :continue do
8
+ run "sudo service #{application}-scheduler #{command} || true"
9
+ end
10
+ after command, "scheduler:#{command}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :application, :env
3
+
4
+ before "setup", "ssh:setup"
5
+
6
+ namespace :ssh do
7
+ desc "Install staff SSH keys"
8
+ task :setup do
9
+ upload "deploy/#{env}/authorized_keys", "#{user_home}/.ssh/authorized_keys"
10
+ run "chmod 600 #{user_home}/.ssh/authorized_keys"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :application, :current_path
3
+
4
+ set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
5
+ set_default(:unicorn_socket) { "#{current_path}/tmp/sockets/unicorn.sock" }
6
+ set_default(:unicorn_log) { "#{current_path}/log/unicorn.log" }
7
+
8
+ after "setup", "unicorn:setup"
9
+ after "deploy:update_code", "unicorn:update_config"
10
+
11
+ namespace :unicorn do
12
+ desc "Setup a unicorn environment"
13
+ task :setup, roles: :web, on_no_matching_servers: :continue do
14
+ run "cd #{current_path}; mkdir -p tmp/pids tmp/sockets"
15
+ end
16
+
17
+ desc "Export the unicorn server configuration"
18
+ task :update_config, roles: :web, on_no_matching_servers: :continue do
19
+ upload_template "unicorn.rb", "#{current_path}/config/unicorn.rb"
20
+ upload_template "unicorn_init.sh", "/tmp/unicorn_init"
21
+ run "sudo chmod 700 /tmp/unicorn_init; sudo chown 0:0 /tmp/unicorn_init; sudo rm -f /etc/init.d/#{application}-web; sudo mv /tmp/unicorn_init /etc/init.d/#{application}-web; sudo update-rc.d -f #{application}-web defaults"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :application
3
+
4
+ namespace :web do
5
+ [:start, :stop, :restart, :status].each do |command|
6
+ desc "#{command.to_s.capitalize} the web service"
7
+ task command, roles: :web, on_no_matching_servers: :continue do
8
+ run "sudo service #{application}-web #{command} || true"
9
+ end
10
+ after command, "web:#{command}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ Capistrano::Configuration.instance.load do
2
+ require_settings :application
3
+
4
+ namespace :worker do
5
+ [:start, :stop, :restart, :status].each do |command|
6
+ desc "#{command.to_s.capitalize} the worker service"
7
+ task command, roles: :worker, on_no_matching_servers: :continue do
8
+ run "sudo service #{application}-worker #{command} || true"
9
+ end
10
+ after command, "worker:#{command}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1 @@
1
+ require "capistrano/elobuff"
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-elobuff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Coene
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Capistrano recipes we use at ELOBUFF
31
+ email:
32
+ - jcoene@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - elobuff_capistrano.gemspec
43
+ - lib/capistrano/elobuff.rb
44
+ - lib/capistrano/elobuff/base.rb
45
+ - lib/capistrano/elobuff/defaults.rb
46
+ - lib/capistrano/elobuff/helpers.rb
47
+ - lib/capistrano/elobuff/recipes/bundler.rb
48
+ - lib/capistrano/elobuff/recipes/code.rb
49
+ - lib/capistrano/elobuff/recipes/console.rb
50
+ - lib/capistrano/elobuff/recipes/cron.rb
51
+ - lib/capistrano/elobuff/recipes/database.rb
52
+ - lib/capistrano/elobuff/recipes/foreman.rb
53
+ - lib/capistrano/elobuff/recipes/logs.rb
54
+ - lib/capistrano/elobuff/recipes/merger.rb
55
+ - lib/capistrano/elobuff/recipes/nginx.rb
56
+ - lib/capistrano/elobuff/recipes/ntp.rb
57
+ - lib/capistrano/elobuff/recipes/ps.rb
58
+ - lib/capistrano/elobuff/recipes/ruby.rb
59
+ - lib/capistrano/elobuff/recipes/scheduler.rb
60
+ - lib/capistrano/elobuff/recipes/ssh.rb
61
+ - lib/capistrano/elobuff/recipes/unicorn.rb
62
+ - lib/capistrano/elobuff/recipes/web.rb
63
+ - lib/capistrano/elobuff/recipes/worker.rb
64
+ - lib/capistrano_elobuff.rb
65
+ homepage: https://github.com/elobuff/capistrano_elobuff
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.23
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Capistrano recipes we use at ELOBUFF
89
+ test_files: []