capistrano-vps 0.10.0

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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +22 -0
  5. data/README.md +105 -0
  6. data/Rakefile +2 -0
  7. data/bootstrap.sh +64 -0
  8. data/capistrano-vps.gemspec +19 -0
  9. data/lib/capistrano-vps.rb +1 -0
  10. data/lib/capistrano-vps/recipes/base.rb +32 -0
  11. data/lib/capistrano-vps/recipes/check.rb +15 -0
  12. data/lib/capistrano-vps/recipes/elasticsearch.rb +29 -0
  13. data/lib/capistrano-vps/recipes/haproxy.rb +30 -0
  14. data/lib/capistrano-vps/recipes/imagemagick.rb +10 -0
  15. data/lib/capistrano-vps/recipes/libcurl.rb +11 -0
  16. data/lib/capistrano-vps/recipes/libxml.rb +11 -0
  17. data/lib/capistrano-vps/recipes/mongodb.rb +21 -0
  18. data/lib/capistrano-vps/recipes/nginx.rb +29 -0
  19. data/lib/capistrano-vps/recipes/nodejs.rb +11 -0
  20. data/lib/capistrano-vps/recipes/postgresql_client.rb +114 -0
  21. data/lib/capistrano-vps/recipes/postgresql_server.rb +41 -0
  22. data/lib/capistrano-vps/recipes/rabbitmq.rb +23 -0
  23. data/lib/capistrano-vps/recipes/rbenv.rb +50 -0
  24. data/lib/capistrano-vps/recipes/redis.rb +28 -0
  25. data/lib/capistrano-vps/recipes/resque.rb +27 -0
  26. data/lib/capistrano-vps/recipes/ssh_agent.rb +17 -0
  27. data/lib/capistrano-vps/recipes/templates/haproxy.erb +1 -0
  28. data/lib/capistrano-vps/recipes/templates/haproxy_conf.erb +58 -0
  29. data/lib/capistrano-vps/recipes/templates/nginx_haproxy.erb +44 -0
  30. data/lib/capistrano-vps/recipes/templates/nginx_unicorn.erb +37 -0
  31. data/lib/capistrano-vps/recipes/templates/postgresql.yml.erb +8 -0
  32. data/lib/capistrano-vps/recipes/templates/redis.conf.erb +1 -0
  33. data/lib/capistrano-vps/recipes/templates/resque.rake.erb +97 -0
  34. data/lib/capistrano-vps/recipes/templates/unicorn.rb.erb +32 -0
  35. data/lib/capistrano-vps/recipes/templates/unicorn_init.erb +84 -0
  36. data/lib/capistrano-vps/recipes/thin.rb +35 -0
  37. data/lib/capistrano-vps/recipes/unicorn.rb +30 -0
  38. data/lib/capistrano-vps/recipes/web.rb +15 -0
  39. data/lib/capistrano-vps/recipes/wkhtmltoimage.rb +16 -0
  40. data/lib/capistrano-vps/version.rb +3 -0
  41. data/lib/rails/generators/vps/recipes/install/install_generator.rb +25 -0
  42. data/lib/rails/generators/vps/recipes/install/templates/deploy.rb +46 -0
  43. data/lib/rails/generators/vps/recipes/install/templates/production.rb +1 -0
  44. data/lib/rails/generators/vps/recipes/install/templates/staging.rb +1 -0
  45. metadata +99 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cc9857a8b34b8fd3cf827802aa234163b37179ea
4
+ data.tar.gz: 902326e0855253222c12ddbd0ae2ffbfefaaf373
5
+ SHA512:
6
+ metadata.gz: e2723a28ca8f64b6da995f351aa7564d794ddff8e35433a669d0a0302f0d5c3090579769e74cf0edd21d2ad727485b31a650a3b8385cb63cce8911e2371a8e33
7
+ data.tar.gz: 5e88a4bb1a913efb14f0e85251756c253076c4f423d07f1544d73eaa7b3e75df7dd1aa3a58c2b56fe9b2c389be119daba90db929c42c7fdf71000d53dfca7696
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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activelabs-recipes.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Stephane Busso
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,105 @@
1
+ # Capistrano VPS
2
+
3
+ Based on Capistrano recipes railscast: http://railscasts.com/episodes/337-capistrano-recipes?view=asciicast
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+ gem 'capistrano'
9
+ gem 'capistrano-vps', :git => "git://github.com/sbusso/capistrano-vps.git", :group => :development
10
+
11
+ $ capify .
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Generate the config files:
18
+
19
+ rails g vps:recipes:install
20
+
21
+ ## Setup
22
+
23
+ Connect to the server:
24
+ ```
25
+ ssh root@72.14.183.209
26
+ bash < <(curl -s https://raw.github.com/sbusso/capistrano-vps/master/bootstrap.sh)
27
+ ```
28
+
29
+ On your local project:
30
+ ```
31
+ ssh-add # -K on Mac OS X
32
+ cap cap_vps:install
33
+
34
+ # OR
35
+
36
+ cap cap_vps:prepare
37
+ cap deploy:setup
38
+ cap deploy:cold
39
+ cap deploy:migrations
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ Deploy file example:
45
+ ```ruby
46
+ # =============================================================================
47
+ # GENERAL SETTINGS
48
+ # =============================================================================
49
+ set :application, "myproject"
50
+ set :user, "deployer"
51
+
52
+ set :deploy_to, "/home/#{user}/apps/#{application}"
53
+ set :use_sudo, false
54
+ set :deploy_via, :remote_cache
55
+ set :scm, :git
56
+ set :repository, "git@github.com:myuser/#{application}.git"
57
+ set :git_enable_submodules, 1
58
+ set :keep_releases, 3
59
+ set :branch, "master"
60
+
61
+ default_run_options[:pty] = true
62
+ ssh_options[:forward_agent] = true
63
+ # ssh_options[:paranoid] = false
64
+
65
+ after "deploy", "deploy:cleanup" # keep only the last 3 releases
66
+
67
+ server "#production_address", :web, :app, :db, primary: true
68
+
69
+ # =============================================================================
70
+ # RECIPE INCLUDES
71
+ # =============================================================================
72
+
73
+ require "bundler/capistrano"
74
+ require "capistrano-vps/recipes/base"
75
+ require "capistrano-vps/recipes/nginx"
76
+ require "capistrano-vps/recipes/unicorn"
77
+ require "capistrano-vps/recipes/postgresql_server"
78
+ require "capistrano-vps/recipes/postgresql_client"
79
+ require "capistrano-vps/recipes/nodejs"
80
+ require "capistrano-vps/recipes/redis"
81
+ require "capistrano-vps/recipes/rbenv"
82
+ require "capistrano-vps/recipes/libxml"
83
+ require "capistrano-vps/recipes/imagemagick"
84
+ ```
85
+
86
+ ## TODO
87
+
88
+ * add config.yml, configure everything from this file
89
+ * only install new packages
90
+ * extend capify
91
+ * uncomment assets in capify
92
+ * load as independant gem / gemfile (last have error with rake)
93
+ * check unicorn in gemfile
94
+ * use capistrano stage to configure environment (unicorn, db, etc..)
95
+ * add maintenance tasks + page
96
+ * add test for version 1.0 - look at carpet (https://github.com/sbusso/carpet/blob/master/spec/capistrano/deploy/remote_dependency_spec.rb, https://github.com/technicalpickles/capistrano-spec)
97
+ * rename to 'capistrano-provisonner'
98
+
99
+ ## Contributing
100
+
101
+ 1. Fork it
102
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
103
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
104
+ 4. Push to the branch (`git push origin my-new-feature`)
105
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bootstrap.sh ADDED
@@ -0,0 +1,64 @@
1
+ # postinstall.sh
2
+
3
+ date > /etc/box_build_time
4
+
5
+
6
+ # Apt-install various things necessary for Ruby, guest additions,
7
+ # etc., and remove optional things to trim down the machine.
8
+ apt-get -y update
9
+ apt-get -y upgrade
10
+
11
+ echo 'LC_ALL=en_US.UTF-8' > /etc/environment
12
+ echo 'LC_CTYPE=en_US.UTF-8' > /etc/environment
13
+
14
+ export LANGUAGE=en_US.UTF-8
15
+ export LANG=en_US.UTF-8
16
+ locale-gen en_US.UTF-8
17
+ dpkg-reconfigure locales
18
+
19
+ apt-get -y install linux-headers-$(uname -r) build-essential
20
+ apt-get -y install zlib1g-dev libssl-dev libreadline-gplv2-dev
21
+ apt-get -y install nano htop
22
+ apt-get clean
23
+
24
+
25
+ # Setup sudo to allow no-password sudo for "admin"
26
+ groupadd -r admin
27
+ useradd -d /home/deployer --password `date +s% | sha256sum | base64 | head -c 32` --groups admin -m deployer
28
+ usermod -s /bin/bash deployer
29
+ cp /etc/sudoers /etc/sudoers.orig
30
+ sed -i -e '/Defaults\s\+env_reset/a Defaults\texempt_group=admin' /etc/sudoers
31
+ sed -i -e 's/%admin ALL=(ALL) ALL/%admin ALL=(ALL) NOPASSWD: ALL/g' /etc/sudoers
32
+
33
+
34
+ # Installing ssh keys
35
+ mkdir /home/deployer/.ssh
36
+ chmod 700 /home/deployer/.ssh
37
+ cd /home/deployer/.ssh
38
+ wget --no-check-certificate 'https://raw.github.com/sbusso/my_files/master/id_rsa.pub' -O authorized_keys
39
+ chmod 600 /home/deployer/.ssh/authorized_keys
40
+ chown -R deployer /home/deployer/.ssh
41
+
42
+ # Remove items used for building, since they aren't needed anymore
43
+ # apt-get -y remove linux-headers-$(uname -r) build-essential
44
+ # apt-get -y autoremove
45
+
46
+ # Zero out the free space to save space in the final image:
47
+ dd if=/dev/zero of=/EMPTY bs=1M
48
+ rm -f /EMPTY
49
+
50
+ # Removing leftover leases and persistent rules
51
+ echo "cleaning up dhcp leases"
52
+ rm /var/lib/dhcp3/*
53
+
54
+ # Make sure Udev doesn't block our network
55
+ # http://6.ptmc.org/?p=164
56
+ echo "cleaning up udev rules"
57
+ rm /etc/udev/rules.d/70-persistent-net.rules
58
+ mkdir /etc/udev/rules.d/70-persistent-net.rules
59
+ rm -rf /dev/.udev/
60
+ rm /lib/udev/rules.d/75-persistent-net-generator.rules
61
+
62
+ echo "Adding a 2 sec delay to the interface up, to make the dhclient happy"
63
+ echo "pre-up sleep 2" >> /etc/network/interfaces
64
+ exit
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/capistrano-vps/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Stephane Busso"]
6
+ gem.email = "stephane.busso@gmail.com"
7
+ gem.date = %q{2012-04-03}
8
+ gem.description = %q{keeping vps recipes for ruby application}
9
+ gem.summary = %q{bootstrap from railscast #335}
10
+ gem.homepage = "http://activelabs.fr"
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ # gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ # gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "capistrano-vps"
16
+ gem.require_paths = ["lib"]
17
+ gem.add_runtime_dependency 'capistrano'
18
+ gem.version = CapistranoVps::VERSION
19
+ end
@@ -0,0 +1 @@
1
+ Dir[File.join(File.dirname(__FILE__), 'capistrano-vps/recipes/*.rb')].sort.each { |lib| load lib }
@@ -0,0 +1,32 @@
1
+ Capistrano::Configuration.instance(true).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
+
12
+ namespace :cap_vps do
13
+ desc "Prepare server for installation"
14
+ task :prepare do
15
+ run "#{sudo} apt-get -y update"
16
+ run "#{sudo} apt-get -y install python-software-properties autoconf"
17
+ end
18
+
19
+ desc "Install everything onto the server"
20
+ task :install do
21
+ cap_vps.prepare
22
+ deploy.setup
23
+ deploy.cold
24
+ deploy.migrations
25
+ end
26
+ end
27
+
28
+
29
+
30
+ end
31
+
32
+ #dpkg-reconfigure locales
@@ -0,0 +1,15 @@
1
+ Capistrano::Configuration.instance(true).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,29 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+ namespace :es do
3
+
4
+ desc "Install the latest release of ElasticSearch"
5
+ task :install, roles: :app do
6
+ run "#{sudo} apt-get install openjdk-7-jre -y"
7
+ run "wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.1.tar.gz -O elasticsearch.tar.gz"
8
+ run "tar -xf elasticsearch.tar.gz"
9
+ run "rm elasticsearch.tar.gz"
10
+ run "#{sudo} mv elasticsearch-* elasticsearch"
11
+ run "#{sudo} mv elasticsearch /usr/local/share"
12
+
13
+ run "curl -L http://github.com/elasticsearch/elasticsearch-servicewrapper/tarball/master | tar -xz"
14
+ run "mv *servicewrapper*/service /usr/local/share/elasticsearch/bin/"
15
+ run "rm -Rf *servicewrapper*"
16
+ run "#{sudo} /usr/local/share/elasticsearch/bin/service/elasticsearch install"
17
+ run "#{sudo} ln -s `readlink -f /usr/local/share/elasticsearch/bin/service/elasticsearch` /usr/local/bin/rcelasticsearch"
18
+ end
19
+ after "cap_vps:prepare", "es:install"
20
+
21
+ %w[start stop restart].each do |command|
22
+ desc "#{command} elasticsearch"
23
+ task command, roles: :web do
24
+ run "#{sudo} service elasticsearch #{command}"
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+ namespace :haproxy do
3
+ desc "Install latest stable release of haproxy"
4
+ task :install, roles: :front do
5
+ run "DEBIAN_FRONTEND=noninteractive #{sudo} apt-get -y install haproxy"
6
+ end
7
+ after "cap_vps:prepare", "haproxy:install"
8
+
9
+ desc "Setup haproxy default configuration"
10
+ task :setup, roles: :front do
11
+ template "haproxy.erb", "/tmp/haproxy_default_conf"
12
+ run "#{sudo} mv /tmp/haproxy_default_conf /etc/default/haproxy"
13
+ template "haproxy_conf.erb", "/tmp/haproxy_conf"
14
+ run "#{sudo} mv /tmp/haproxy_conf /etc/haproxy/haproxy.cfg"
15
+ # !!! /etc/init.d/haproxy > ENABLED=1
16
+ restart
17
+ template "nginx_haproxy.erb", "/tmp/nginx_conf"
18
+ run "#{sudo} mv /tmp/nginx_conf /etc/nginx/sites-enabled/#{application}"
19
+ nginx.restart
20
+ end
21
+ after "deploy:setup", "haproxy:setup"
22
+
23
+ %w[start stop restart].each do |command|
24
+ desc "#{command} haproxy"
25
+ task command, roles: :front do
26
+ run "#{sudo} service haproxy #{command}"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+ namespace :imagemagick do
3
+
4
+ desc "Install the latest release of Imagemagick"
5
+ task :install, roles: :app do
6
+ run "#{sudo} apt-get install imagemagick libmagickwand-dev -y"
7
+ end
8
+ after "cap_vps:prepare", "imagemagick:install"
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+ namespace :libcurl do
3
+
4
+ desc "Install the latest release of libcurl"
5
+ task :install, roles: :app do
6
+ run "#{sudo} apt-get -y install curl libcurl3 libcurl3-dev"
7
+ end
8
+ after "cap_vps:prepare", "libcurl:install"
9
+
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+ namespace :libxml do
3
+
4
+ desc "Install the latest release of libxml"
5
+ task :install, roles: :app do
6
+ run "#{sudo} apt-get -y install libxml2 libxml2-dev libxslt1-dev"
7
+ end
8
+ after "cap_vps:prepare", "libxml:install"
9
+
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ Capistrano::Configuration.instance(true).load do
2
+ namespace :mongodb do
3
+
4
+ desc "Install the latest release of MongoDB"
5
+ task :install, roles: :app do
6
+ run "#{sudo} apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10"
7
+ run %q{#{sudo} echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" >> /etc/apt/sources.list}
8
+ run "#{sudo} apt-get -y update"
9
+ run "#{sudo} apt-get -y install mongodb-10gen"
10
+ end
11
+ after "cap_vps:prepare", "mongodb:install"
12
+
13
+ %w[start stop restart].each do |command|
14
+ desc "#{command} mongodb"
15
+ task command, roles: :web do
16
+ run "#{sudo} service mongodb #{command}"
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ Capistrano::Configuration.instance(true).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 -y ppa:nginx/stable"
6
+ run "#{sudo} apt-get -y update"
7
+ run "#{sudo} apt-get -y install nginx"
8
+ end
9
+ after "cap_vps:prepare", "nginx:install"
10
+
11
+ desc "Setup nginx configuration for this application"
12
+ task :setup, roles: :web do
13
+ # send to nginx_conf
14
+ # http {
15
+ # server_names_hash_bucket_size 32;
16
+ # }
17
+ run "#{sudo} rm -f /etc/nginx/sites-enabled/default"
18
+ restart
19
+ end
20
+ after "deploy:setup", "nginx:setup"
21
+
22
+ %w[start stop restart].each do |command|
23
+ desc "#{command} nginx"
24
+ task command, roles: :web do
25
+ run "#{sudo} service nginx #{command}"
26
+ end
27
+ end
28
+ end
29
+ end