cap_bootstrap 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cap_bootstrap.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Chris Saylor
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,99 @@
1
+ # Cap Bootstrap
2
+
3
+ Capistrano tasks for deploying Rails applications using Ubuntu 10.04, rbenv, nginx, Unicorn and PostgreSQL. Based on the excellent Railscasts by Ryan Bates, with permission of course. If you are new to Capistrano or setting up a VPS, I highly recommend subscribing to his pro screencasts and watching the following:
4
+
5
+ * [Deploying to a VPS](http://railscasts.com/episodes/335-deploying-to-a-vps) (Pro)
6
+ * [Capistrano Tasks](http://railscasts.com/episodes/133-capistrano-tasks-revised) (Free)
7
+ * [Capistrano Recipes](http://railscasts.com/episodes/337-capistrano-recipes) (Pro)
8
+
9
+ I am not affiliated with Railscasts, I'm just a fan.
10
+
11
+ ## Requirements
12
+
13
+ * Capistrano
14
+ * Fresh Ubuntu 10.04 or 11.10 install
15
+
16
+ ## Installation
17
+
18
+ Add these lines to your application's Gemfile:
19
+
20
+ gem 'capistrano'
21
+ gem 'cap_bootstrap'
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ ## Usage
28
+
29
+ Setup a new Ubuntu 10.04 slice. Add a user called deployer with sudo privileges.
30
+
31
+ In your project, run the following:
32
+
33
+ capify .
34
+
35
+ Overwrite the default deploy.rb with the following:
36
+
37
+ require "bundler/capistrano"
38
+ require "cap_bootstrap/capistrano"
39
+ server "99.99.99.99", :web, :app, :db, primary: true
40
+ set :user, "deployer"
41
+ set :application, "blog"
42
+ set :deploy_to, "/home/#{user}/apps/#{application}"
43
+ set :deploy_via, :remote_cache
44
+ set :use_sudo, false
45
+ set :scm, "git"
46
+ set :repository, "git@github.com:GITHUB_USER/#{application}.git"
47
+ set :branch, "master"
48
+ default_run_options[:pty] = true
49
+ ssh_options[:forward_agent] = true
50
+ after "deploy", "deploy:cleanup" # keep only the last 5 releases
51
+
52
+ Customize the server IP address, the application name, and the repository.
53
+
54
+ Back in your project:
55
+
56
+ cap deploy:install
57
+ cap deploy:setup
58
+ cap deploy:cold
59
+
60
+ ## Advanced Options
61
+
62
+ ### PostgreSQL
63
+
64
+ set :postgresql_host, "localhost"
65
+ set :postgresql_user { application }
66
+ set :postgresql_database { "#{application}_production" }
67
+
68
+ ### Ruby
69
+
70
+ set :ruby_version, "1.9.3-p125"
71
+ set :rbenv_bootstrap, "bootstrap-ubuntu-10-04" # Or bootstrap-ubuntu-11-10
72
+
73
+ ### Unicorn
74
+
75
+ set :unicorn_user { user }
76
+ set :unicorn_pid { "#{current_path}/tmp/pids/unicorn.pid" }
77
+ set :unicorn_config { "#{shared_path}/config/unicorn.rb" }
78
+ set :unicorn_log { "#{shared_path}/log/unicorn.log" }
79
+ set :unicorn_workers, 2
80
+
81
+ ## Future Plans
82
+
83
+ Version 0.1 uses Ryan's recipes pulled directly from Railscast episode #337 Capistrano Recipes. You will always be able to access this version
84
+ with tag v0.1. Future versions will incorporate optional installs such as MySQL, Apache, Phusion Passenger and additional server config such as setting a hostname and installing a firewall.
85
+
86
+ ## Alternatives
87
+
88
+ * [Chef](http://www.opscode.com/chef/)
89
+ * [Puppet](http://puppetlabs.com/)
90
+ * [deprec](http://deprec.org/)
91
+
92
+ ## Contributing
93
+
94
+ 1. Fork it
95
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
96
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
97
+ 4. Push to the branch (`git push origin my-new-feature`)
98
+ 5. Create new Pull Request
99
+
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
+ require File.expand_path('../lib/cap_bootstrap/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Christopher Saylor"]
6
+ gem.email = ["chris@justhack.com"]
7
+ gem.description = %q{Capistrano tasks for deploying Rails applications using Ubuntu 10.04, rbenv, nginx, Unicorn and PostgreSQL.}
8
+ gem.summary = %q{Capistrano tasks for deploying Rails applications using Ubuntu 10.04, rbenv, nginx, Unicorn and PostgreSQL.}
9
+ gem.homepage = "http://github.com/cwsaylor/cap_bootstrap"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "cap_bootstrap"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = CapBootstrap::VERSION
17
+ end
@@ -0,0 +1,7 @@
1
+ require 'cap_bootstrap/recipes/base'
2
+ require 'cap_bootstrap/recipes/check'
3
+ require 'cap_bootstrap/recipes/nginx'
4
+ require 'cap_bootstrap/recipes/nodejs'
5
+ require 'cap_bootstrap/recipes/postgresql'
6
+ require 'cap_bootstrap/recipes/rbenv'
7
+ require 'cap_bootstrap/recipes/unicorn'
@@ -0,0 +1,18 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ def template(from, to)
3
+ erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
4
+ put ERB.new(erb).result(binding), to
5
+ end
6
+
7
+ def set_default(name, *args, &block)
8
+ set(name, *args, &block) unless exists?(name)
9
+ end
10
+
11
+ namespace :deploy do
12
+ desc "Install everything onto the server"
13
+ task :install do
14
+ run "#{sudo} apt-get -y update"
15
+ run "#{sudo} apt-get -y install python-software-properties"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :check do
3
+ desc "Make sure local git is in sync with remote."
4
+ task :revision, roles: :web do
5
+ unless `git rev-parse HEAD` == `git rev-parse origin/#{branch}`
6
+ puts "WARNING: HEAD is not the same as origin/#{branch}"
7
+ puts "Run `git push` to sync changes."
8
+ exit
9
+ end
10
+ end
11
+ before "deploy", "check:revision"
12
+ before "deploy:migrations", "check:revision"
13
+ before "deploy:cold", "check:revision"
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :nginx do
3
+ desc "Install latest stable release of nginx"
4
+ task :install, roles: :web do
5
+ run "#{sudo} add-apt-repository ppa:nginx/stable"
6
+ run "#{sudo} apt-get -y update"
7
+ run "#{sudo} apt-get -y install nginx"
8
+ end
9
+ after "deploy:install", "nginx:install"
10
+
11
+ desc "Setup nginx configuration for this application"
12
+ task :setup, roles: :web do
13
+ template "nginx_unicorn.erb", "/tmp/nginx_conf"
14
+ run "#{sudo} mv /tmp/nginx_conf /etc/nginx/sites-enabled/#{application}"
15
+ run "#{sudo} rm -f /etc/nginx/sites-enabled/default"
16
+ restart
17
+ end
18
+ after "deploy:setup", "nginx:setup"
19
+
20
+ %w[start stop restart].each do |command|
21
+ desc "#{command} nginx"
22
+ task command, roles: :web do
23
+ run "#{sudo} service nginx #{command}"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :nodejs do
3
+ desc "Install the latest relase of Node.js"
4
+ task :install, roles: :app do
5
+ run "#{sudo} add-apt-repository ppa:chris-lea/node.js"
6
+ run "#{sudo} apt-get -y update"
7
+ run "#{sudo} apt-get -y install nodejs"
8
+ end
9
+ after "deploy:install", "nodejs:install"
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ set_default(:postgresql_host, "localhost")
3
+ set_default(:postgresql_user) { application }
4
+ set_default(:postgresql_password) { Capistrano::CLI.password_prompt "PostgreSQL Password: " }
5
+ set_default(:postgresql_database) { "#{application}_production" }
6
+
7
+ namespace :postgresql do
8
+ desc "Install the latest stable release of PostgreSQL."
9
+ task :install, roles: :db, only: {primary: true} do
10
+ run "#{sudo} add-apt-repository ppa:pitti/postgresql"
11
+ run "#{sudo} apt-get -y update"
12
+ run "#{sudo} apt-get -y install postgresql libpq-dev"
13
+ end
14
+ after "deploy:install", "postgresql:install"
15
+
16
+ desc "Create a database for this application."
17
+ task :create_database, roles: :db, only: {primary: true} do
18
+ run %Q{#{sudo} -u postgres psql -c "create user #{postgresql_user} with password '#{postgresql_password}';"}
19
+ run %Q{#{sudo} -u postgres psql -c "create database #{postgresql_database} owner #{postgresql_user};"}
20
+ end
21
+ after "deploy:setup", "postgresql:create_database"
22
+
23
+ desc "Generate the database.yml configuration file."
24
+ task :setup, roles: :app do
25
+ run "mkdir -p #{shared_path}/config"
26
+ template "postgresql.yml.erb", "#{shared_path}/config/database.yml"
27
+ end
28
+ after "deploy:setup", "postgresql:setup"
29
+
30
+ desc "Symlink the database.yml file into latest release"
31
+ task :symlink, roles: :app do
32
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
33
+ end
34
+ after "deploy:finalize_update", "postgresql:symlink"
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ set_default :ruby_version, "1.9.3-p125"
3
+ set_default :rbenv_bootstrap, "bootstrap-ubuntu-10-04"
4
+
5
+ namespace :rbenv do
6
+ desc "Install rbenv, Ruby, and the Bundler gem"
7
+ task :install, roles: :app do
8
+ run "#{sudo} apt-get -y install curl git-core"
9
+ run "curl -L https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash"
10
+ bashrc = <<-BASHRC
11
+ if [ -d $HOME/.rbenv ]; then
12
+ export PATH="$HOME/.rbenv/bin:$PATH"
13
+ eval "$(rbenv init -)"
14
+ fi
15
+ BASHRC
16
+ put bashrc, "/tmp/rbenvrc"
17
+ run "cat /tmp/rbenvrc ~/.bashrc > ~/.bashrc.tmp"
18
+ run "mv ~/.bashrc.tmp ~/.bashrc"
19
+ run %q{export PATH="$HOME/.rbenv/bin:$PATH"}
20
+ run %q{eval "$(rbenv init -)"}
21
+ run "rbenv #{rbenv_bootstrap}"
22
+ run "rbenv install #{ruby_version}"
23
+ run "rbenv global #{ruby_version}"
24
+ run "gem install bundler --no-ri --no-rdoc"
25
+ run "rbenv rehash"
26
+ end
27
+ after "deploy:install", "rbenv:install"
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ upstream unicorn {
2
+ server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
3
+ }
4
+
5
+ server {
6
+ listen 80 default deferred;
7
+ # server_name example.com;
8
+ root <%= current_path %>/public;
9
+
10
+ location ^~ /assets/ {
11
+ gzip_static on;
12
+ expires max;
13
+ add_header Cache-Control public;
14
+ }
15
+
16
+ try_files $uri/index.html $uri @unicorn;
17
+ location @unicorn {
18
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19
+ proxy_set_header Host $http_host;
20
+ proxy_redirect off;
21
+ proxy_pass http://unicorn;
22
+ }
23
+
24
+ error_page 500 502 503 504 /500.html;
25
+ client_max_body_size 4G;
26
+ keepalive_timeout 10;
27
+ }
@@ -0,0 +1,8 @@
1
+ production:
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ database: <%= postgresql_database %>
5
+ pool: 5
6
+ username: <%= postgresql_user %>
7
+ password: <%= postgresql_password %>
8
+ host: <%= postgresql_host %>
@@ -0,0 +1,8 @@
1
+ working_directory "<%= current_path %>"
2
+ pid "<%= unicorn_pid %>"
3
+ stderr_path "<%= unicorn_log %>"
4
+ stdout_path "<%= unicorn_log %>"
5
+
6
+ listen "/tmp/unicorn.<%= application %>.sock"
7
+ worker_processes <%= unicorn_workers %>
8
+ timeout 30
@@ -0,0 +1,84 @@
1
+ #!/bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: unicorn
4
+ # Required-Start: $remote_fs $syslog
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: 0 1 6
8
+ # Short-Description: Manage unicorn server
9
+ # Description: Start, stop, restart unicorn server for a specific application.
10
+ ### END INIT INFO
11
+ set -e
12
+
13
+ # Feel free to change any of the following variables for your app:
14
+ TIMEOUT=${TIMEOUT-60}
15
+ APP_ROOT=<%= current_path %>
16
+ PID=<%= unicorn_pid %>
17
+ CMD="cd <%= current_path %>; bundle exec unicorn -D -c <%= unicorn_config %> -E production"
18
+ AS_USER=<%= unicorn_user %>
19
+ set -u
20
+
21
+ OLD_PIN="$PID.oldbin"
22
+
23
+ sig () {
24
+ test -s "$PID" && kill -$1 `cat $PID`
25
+ }
26
+
27
+ oldsig () {
28
+ test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
29
+ }
30
+
31
+ run () {
32
+ if [ "$(id -un)" = "$AS_USER" ]; then
33
+ eval $1
34
+ else
35
+ su -c "$1" - $AS_USER
36
+ fi
37
+ }
38
+
39
+ case "$1" in
40
+ start)
41
+ sig 0 && echo >&2 "Already running" && exit 0
42
+ run "$CMD"
43
+ ;;
44
+ stop)
45
+ sig QUIT && exit 0
46
+ echo >&2 "Not running"
47
+ ;;
48
+ force-stop)
49
+ sig TERM && exit 0
50
+ echo >&2 "Not running"
51
+ ;;
52
+ restart|reload)
53
+ sig HUP && echo reloaded OK && exit 0
54
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
55
+ run "$CMD"
56
+ ;;
57
+ upgrade)
58
+ if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
59
+ then
60
+ n=$TIMEOUT
61
+ while test -s $OLD_PIN && test $n -ge 0
62
+ do
63
+ printf '.' && sleep 1 && n=$(( $n - 1 ))
64
+ done
65
+ echo
66
+
67
+ if test $n -lt 0 && test -s $OLD_PIN
68
+ then
69
+ echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
70
+ exit 1
71
+ fi
72
+ exit 0
73
+ fi
74
+ echo >&2 "Couldn't upgrade, starting '$CMD' instead"
75
+ run "$CMD"
76
+ ;;
77
+ reopen-logs)
78
+ sig USR1
79
+ ;;
80
+ *)
81
+ echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
82
+ exit 1
83
+ ;;
84
+ esac
@@ -0,0 +1,28 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ set_default(:unicorn_user) { user }
3
+ set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
4
+ set_default(:unicorn_config) { "#{shared_path}/config/unicorn.rb" }
5
+ set_default(:unicorn_log) { "#{shared_path}/log/unicorn.log" }
6
+ set_default(:unicorn_workers, 2)
7
+
8
+ namespace :unicorn do
9
+ desc "Setup Unicorn initializer and app configuration"
10
+ task :setup, roles: :app do
11
+ run "mkdir -p #{shared_path}/config"
12
+ template "unicorn.rb.erb", unicorn_config
13
+ template "unicorn_init.erb", "/tmp/unicorn_init"
14
+ run "chmod +x /tmp/unicorn_init"
15
+ run "#{sudo} mv /tmp/unicorn_init /etc/init.d/unicorn_#{application}"
16
+ run "#{sudo} update-rc.d -f unicorn_#{application} defaults"
17
+ end
18
+ after "deploy:setup", "unicorn:setup"
19
+
20
+ %w[start stop restart].each do |command|
21
+ desc "#{command} unicorn"
22
+ task command, roles: :app do
23
+ run "service unicorn_#{application} #{command}"
24
+ end
25
+ after "deploy:#{command}", "unicorn:#{command}"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module CapBootstrap
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "cap_bootstrap/version"
2
+
3
+ module CapBootstrap
4
+ # Your code goes here...
5
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cap_bootstrap
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christopher Saylor
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-02 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Capistrano tasks for deploying Rails applications using Ubuntu 10.04,
15
+ rbenv, nginx, Unicorn and PostgreSQL.
16
+ email:
17
+ - chris@justhack.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - cap_bootstrap.gemspec
28
+ - lib/cap_bootstrap.rb
29
+ - lib/cap_bootstrap/capistrano.rb
30
+ - lib/cap_bootstrap/recipes/base.rb
31
+ - lib/cap_bootstrap/recipes/check.rb
32
+ - lib/cap_bootstrap/recipes/nginx.rb
33
+ - lib/cap_bootstrap/recipes/nodejs.rb
34
+ - lib/cap_bootstrap/recipes/postgresql.rb
35
+ - lib/cap_bootstrap/recipes/rbenv.rb
36
+ - lib/cap_bootstrap/recipes/templates/nginx_unicorn.erb
37
+ - lib/cap_bootstrap/recipes/templates/postgresql.yml.erb
38
+ - lib/cap_bootstrap/recipes/templates/unicorn.rb.erb
39
+ - lib/cap_bootstrap/recipes/templates/unicorn_init.erb
40
+ - lib/cap_bootstrap/recipes/unicorn.rb
41
+ - lib/cap_bootstrap/version.rb
42
+ homepage: http://github.com/cwsaylor/cap_bootstrap
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ segments:
55
+ - 0
56
+ hash: 4411615692156527513
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ segments:
64
+ - 0
65
+ hash: 4411615692156527513
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.11
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Capistrano tasks for deploying Rails applications using Ubuntu 10.04, rbenv,
72
+ nginx, Unicorn and PostgreSQL.
73
+ test_files: []