capistrano_j10io 0.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.
@@ -0,0 +1,13 @@
1
+ if defined?(Capistrano::Configuration) && Capistrano::Configuration.instance
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ set :rails_root, Dir.pwd
4
+ require 'bundler/capistrano' if File.exists?(File.join(fetch(:rails_root), 'Gemfile'))
5
+
6
+ # Load base defaults unless disabled.
7
+ if fetch(:base_defaults, true)
8
+ load File.join(File.dirname(__FILE__), "capistrano_j10io/recipes/base.rb")
9
+ end
10
+
11
+ end
12
+ end
13
+
@@ -0,0 +1,26 @@
1
+ load File.join(File.dirname(__FILE__), "helper.rb")
2
+ load File.join(File.dirname(__FILE__), "nginx.rb")
3
+ load File.join(File.dirname(__FILE__), "nodejs.rb")
4
+ load File.join(File.dirname(__FILE__), "postgresql.rb")
5
+ load File.join(File.dirname(__FILE__), "unicorn.rb")
6
+ load File.join(File.dirname(__FILE__), "rbenv.rb")
7
+ load File.join(File.dirname(__FILE__), "env_vars.rb")
8
+
9
+ set_default :application, "appname"
10
+ set_default :git_user, "gituser"
11
+ set_default :base_domain, "example.com"
12
+ set_default :user, 'deployer'
13
+ set_default :deploy_to, "/home/#{user}/apps/#{application}"
14
+ set_default :branch, "master"
15
+ set_default :ruby_version, "2.0.0-p247"
16
+
17
+ set :deploy_via, :remote_cache
18
+ set :use_sudo, false
19
+
20
+ set :scm, "git"
21
+ set :repository, "git@github.com:#{git_user}/#{application}.git"
22
+
23
+ default_run_options[:pty] = true
24
+ ssh_options[:forward_agent] = true
25
+
26
+ default_run_options[:pty] = true
@@ -0,0 +1,9 @@
1
+ namespace :env do
2
+ desc "Add Environment Variables"
3
+ task :setup, roles: :app do
4
+ template "bashrc.erb", "/tmp/bashrc"
5
+ run "cat /tmp/bashrc ~/.bashrc > ~/.bashrc.tmp"
6
+ run "mv ~/.bashrc.tmp ~/.bashrc"
7
+ end
8
+ after "deploy:setup", "env:setup"
9
+ end
@@ -0,0 +1,51 @@
1
+ def template(from, to)
2
+ erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
3
+ put ERB.new(erb).result(binding), to
4
+ end
5
+
6
+ def nginx_template
7
+ if is_https?
8
+ "nginx_https.conf.erb"
9
+ else
10
+ "nginx_http.conf.erb"
11
+ end
12
+ end
13
+
14
+ def set_default(name, *args, &block)
15
+ set(name, *args, &block) unless exists?(name)
16
+ end
17
+
18
+ def add_apt_repository(repo)
19
+ run "#{sudo} add-apt-repository #{repo}", :pty => true do |ch, stream, data|
20
+ if data =~ /Press.\[ENTER\].to.continue/
21
+ ch.send_data("\n")
22
+ else
23
+ Capistrano::Configuration.default_io_proc.call(ch, stream, data)
24
+ end
25
+ end
26
+ end
27
+
28
+ namespace :deploy do
29
+ desc "Install everything onto the server"
30
+ task :install do
31
+ run "#{sudo} apt-get -y update"
32
+ # The following line relplaces 'run "#{sudo} apt-get -y upgrade"' to ensure a silent upgrade with default options
33
+ # More information available: http://askubuntu.com/questions/146921/how-do-i-apt-get-y-dist-upgrade-without-a-grub-config-prompt
34
+ run "#{sudo} DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" upgrade"
35
+ run "#{sudo} apt-get -y install python-software-properties software-properties-common ufw"
36
+ end
37
+ end
38
+
39
+ namespace :check do
40
+ desc "Make sure local git is in sync with remote."
41
+ task :revision, roles: :web do
42
+ unless `git rev-parse HEAD` == `git rev-parse origin/#{branch}`
43
+ puts "WARNING: HEAD is not the same as origin/#{branch}"
44
+ puts "Run `git push` to sync changes."
45
+ exit
46
+ end
47
+ end
48
+ before "deploy", "check:revision"
49
+ before "deploy:migrations", "check:revision"
50
+ before "deploy:cold", "check:revision"
51
+ end
@@ -0,0 +1,27 @@
1
+ namespace :freshinstall do
2
+ desc "Install latest stable release of nginx"
3
+ task :nginx, roles: :web do
4
+ add_apt_repository 'ppa:nginx/stable'
5
+ run "#{sudo} apt-get -y update"
6
+ run "#{sudo} apt-get -y install nginx"
7
+ end
8
+ after "deploy:install", "freshinstall:nginx"
9
+ end
10
+
11
+ namespace :nginx do
12
+ desc "Setup nginx configuration for this application"
13
+ task :setup, roles: :web do
14
+ template nginx_template, "/tmp/nginx_conf"
15
+ run "#{sudo} mv /tmp/nginx_conf /etc/nginx/sites-enabled/#{application}"
16
+ run "#{sudo} rm -f /etc/nginx/sites-enabled/default"
17
+ restart
18
+ end
19
+ after "deploy:setup", "nginx:setup"
20
+
21
+ %w[start stop restart].each do |command|
22
+ desc "#{command} nginx"
23
+ task command, roles: :web do
24
+ run "#{sudo} service nginx #{command}"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ namespace :freshinstall do
2
+ desc "Install the latest relase of Node.js"
3
+ task :nodejs, roles: :app do
4
+ add_apt_repository 'ppa:chris-lea/node.js'
5
+ run "#{sudo} apt-get -y update"
6
+ run "#{sudo} apt-get -y install nodejs"
7
+ end
8
+ after "deploy:install", "freshinstall:nodejs"
9
+ end
@@ -0,0 +1,36 @@
1
+ set_default(:postgresql_host, "localhost")
2
+ set_default(:postgresql_user) { application }
3
+ set_default(:postgresql_password) { Capistrano::CLI.password_prompt "PostgreSQL Password: " }
4
+ set_default(:postgresql_database) { "#{application}_production" }
5
+
6
+ namespace :freshinstall do
7
+ desc "Install the latest stable release of PostgreSQL."
8
+ task :postgresql, roles: :db, only: {primary: true} do
9
+ add_apt_repository 'ppa:pitti/postgresql'
10
+ run "#{sudo} apt-get -y update"
11
+ run "#{sudo} apt-get -y install postgresql libpq-dev"
12
+ end
13
+ after "deploy:install", "freshinstall:postgresql"
14
+ end
15
+
16
+ namespace :postgresql do
17
+ desc "Create a database for this application."
18
+ task :create_database, roles: :db, only: {primary: true} do
19
+ run %Q{#{sudo} -u postgres psql -c "create user #{postgresql_user} with password '#{postgresql_password}';"}
20
+ run %Q{#{sudo} -u postgres psql -c "create database #{postgresql_database} owner #{postgresql_user};"}
21
+ end
22
+ after "deploy:setup", "postgresql:create_database"
23
+
24
+ desc "Generate the database.yml configuration file."
25
+ task :setup, roles: :app do
26
+ run "mkdir -p #{shared_path}/config"
27
+ template "postgresql.yml.erb", "#{shared_path}/config/database.yml"
28
+ end
29
+ after "deploy:setup", "postgresql:setup"
30
+
31
+ desc "Symlink the database.yml file into latest release"
32
+ task :symlink, roles: :app do
33
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
34
+ end
35
+ after "deploy:finalize_update", "postgresql:symlink"
36
+ end
@@ -0,0 +1,30 @@
1
+ namespace :freshinstall do
2
+
3
+ desc "Install rbenv, Ruby, and the Bundler gem"
4
+ task :rbenv, roles: :app do
5
+ run "#{sudo} apt-get -y install curl git-core"
6
+ run "curl https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash"
7
+ bashrc = <<-BASHRC
8
+ export RAILS_ENV=production
9
+ export RBENV_ROOT="${HOME}/.rbenv"
10
+
11
+ if [ -d "${RBENV_ROOT}" ]; then
12
+ export PATH="${RBENV_ROOT}/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
+ # Manual bootstrap due to this script using it's own sudo https://github.com/fesplugas/rbenv-bootstrap/blob/master/bin/rbenv-bootstrap-ubuntu-12-04
22
+ run "#{sudo} apt-get -y install build-essential tklib zlib1g-dev libssl-dev libreadline-gplv2-dev libxml2 libxml2-dev libxslt1-dev"
23
+ run "rbenv install #{ruby_version}"
24
+ run "rbenv global #{ruby_version}"
25
+ run "gem install bundler --no-ri --no-rdoc"
26
+ run "rbenv rehash"
27
+ end
28
+ after "deploy:install", "freshinstall:rbenv"
29
+
30
+ end
@@ -0,0 +1,26 @@
1
+ set_default(:unicorn_user) { user }
2
+ set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
3
+ set_default(:unicorn_config) { "#{shared_path}/config/unicorn.rb" }
4
+ set_default(:unicorn_log) { "#{shared_path}/log/unicorn.log" }
5
+ set_default(:unicorn_workers, 2)
6
+
7
+ namespace :unicorn do
8
+ desc "Setup Unicorn initializer and app configuration"
9
+ task :setup, roles: :app do
10
+ run "mkdir -p #{shared_path}/config"
11
+ template "unicorn.rb.erb", unicorn_config
12
+ template "unicorn_init.sh.erb", "/tmp/unicorn_init"
13
+ run "chmod +x /tmp/unicorn_init"
14
+ run "#{sudo} mv /tmp/unicorn_init /etc/init.d/unicorn_#{application}"
15
+ run "#{sudo} update-rc.d -f unicorn_#{application} defaults"
16
+ end
17
+ after "deploy:setup", "unicorn:setup"
18
+
19
+ %w[start stop restart].each do |command|
20
+ desc "#{command} unicorn"
21
+ task command, roles: :app do
22
+ run "service unicorn_#{application} #{command}"
23
+ end
24
+ after "deploy:#{command}", "unicorn:#{command}"
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano_j10io
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Tennant
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-25 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: 2.14.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: 2.14.0
30
+ description: Recipes for deploying a rails app to a close-to-fresh Ubuntu install.
31
+ Can deploy NGINX, Postgres, Unicorn, rbenv and more.
32
+ email:
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/capistrano_j10io.rb
38
+ - lib/capistrano_j10io/recipes/base.rb
39
+ - lib/capistrano_j10io/recipes/helper.rb
40
+ - lib/capistrano_j10io/recipes/nginx.rb
41
+ - lib/capistrano_j10io/recipes/nodejs.rb
42
+ - lib/capistrano_j10io/recipes/postgresql.rb
43
+ - lib/capistrano_j10io/recipes/rbenv.rb
44
+ - lib/capistrano_j10io/recipes/unicorn.rb
45
+ - lib/capistrano_j10io/recipes/env_vars.rb
46
+ homepage: http://github.com/j10io/capistrano_j10io
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.23
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: j10io's Capistrano Recipes
70
+ test_files: []