deploy-recipes2 0.0.2

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,20 @@
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
+ *~
19
+ *#*
20
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in deploy-recipes.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 liuhui
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,31 @@
1
+ # Deploy::Recipes
2
+
3
+ Capistano and Rake tasks recipes
4
+
5
+ For Nginx unicorn ...
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'deploy-recipes'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install deploy-recipes
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'deploy-recipes/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "deploy-recipes2"
8
+ gem.version = Deploy::Recipes::VERSION
9
+ gem.authors = ["liuhui"]
10
+ gem.email = ["liuhui998@gmail.com"]
11
+ gem.description = %q{ Cap recipes }
12
+ gem.summary = %q{ nginx unicorn}
13
+ gem.homepage = "https://github.com/liuhui998/deploy-recipes"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,8 @@
1
+ require "deploy-recipes/version"
2
+
3
+
4
+ module Deploy
5
+ module Recipes
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ def template(from, to)
4
+ erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
5
+ put ERB.new(erb).result(binding), to
6
+ end
7
+
8
+ def set_default(name, *args, &block)
9
+ set(name, *args, &block) unless exists?(name)
10
+ end
11
+
12
+
13
+ namespace :deploy do
14
+ desc "Install everything onto the server"
15
+ task :install do
16
+ run "#{sudo} apt-get -y update"
17
+ run "#{sudo} apt-get -y install python-software-properties"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ Capistrano::Configuration.instance.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,41 @@
1
+ Capistrano::Configuration.instance.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
+
17
+
18
+ template "static_nginx.erb", "/tmp/static_nginx_conf"
19
+ run "#{sudo} mv /tmp/static_nginx_conf /etc/nginx/sites-enabled/#{application}_static_file"
20
+
21
+ run "mkdir -p #{shared_path}/uploads"
22
+ restart
23
+ end
24
+ after "deploy:setup", "nginx:setup"
25
+
26
+ desc "Symlink the uploads directory into latest release"
27
+ task :symlink, roles: :app do
28
+ run "rm -rf #{release_path}/public/uploads"
29
+ run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
30
+ end
31
+
32
+ after "deploy:finalize_update", "nginx:symlink"
33
+
34
+ %w[start stop restart].each do |command|
35
+ desc "#{command} nginx"
36
+ task command, roles: :web do
37
+ run "#{sudo} service nginx #{command}"
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,11 @@
1
+ Capistrano::Configuration.instance.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.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.load do
2
+ set_default :ruby_version, "1.9.3-p125"
3
+ set_default :rbenv_bootstrap, "bootstrap-ubuntu-12-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,9 @@
1
+ namespace :help do
2
+ namespace :db do
3
+
4
+ desc "Backup the database"
5
+ task :backup do
6
+ puts "Backing up database with Rake"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :deploy do
3
+ namespace :db do
4
+
5
+ desc "Backup the database"
6
+ task :backup do
7
+ puts "Backing up database with Capistrano"
8
+ end
9
+
10
+ end
11
+ end
12
+ 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,15 @@
1
+ server {
2
+
3
+ # listen 8086 default deferred;
4
+ server_name <%= static_server_name %>;
5
+ root <%= current_path %>/public;
6
+ location ^~ /assets/ {
7
+ gzip_static on;
8
+ expires max;
9
+ add_header Cache-Control public;
10
+ }
11
+
12
+ # error_page 500 502 503 504 /500.html;
13
+ client_max_body_size 4G;
14
+ keepalive_timeout 10;
15
+ }
@@ -0,0 +1,12 @@
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
9
+
10
+ before_exec do |server|
11
+ ENV["BUNDLE_GEMFILE"] = "<%= current_path %>/Gemfile"
12
+ end
@@ -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,30 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ set_default(:unicorn_user) { user }
4
+ set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
5
+ set_default(:unicorn_config) { "#{shared_path}/config/unicorn.rb" }
6
+ set_default(:unicorn_log) { "#{shared_path}/log/unicorn.log" }
7
+ set_default(:unicorn_workers, 2)
8
+
9
+
10
+ namespace :unicorn do
11
+ desc "Setup Unicorn initializer and app configuration"
12
+ task :setup, roles: :app do
13
+ run "mkdir -p #{shared_path}/config"
14
+ template "unicorn.rb.erb", unicorn_config
15
+ template "unicorn_init.erb", "/tmp/unicorn_init"
16
+ run "chmod +x /tmp/unicorn_init"
17
+ run "#{sudo} mv /tmp/unicorn_init /etc/init.d/unicorn_#{application}"
18
+ run "#{sudo} update-rc.d -f unicorn_#{application} defaults"
19
+ end
20
+ after "deploy:setup", "unicorn:setup"
21
+
22
+ %w[start stop restart].each do |command|
23
+ desc "#{command} unicorn"
24
+ task command, roles: :app do
25
+ run "service unicorn_#{application} #{command}"
26
+ end
27
+ after "deploy:#{command}", "unicorn:#{command}"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Deploy
2
+ module Recipes
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deploy-recipes2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - liuhui
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! ' Cap recipes '
15
+ email:
16
+ - liuhui998@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - deploy-recipes.gemspec
27
+ - lib/deploy-recipes.rb
28
+ - lib/deploy-recipes/base.rb
29
+ - lib/deploy-recipes/check.rb
30
+ - lib/deploy-recipes/nginx.rb
31
+ - lib/deploy-recipes/nodejs.rb
32
+ - lib/deploy-recipes/postgresql.rb
33
+ - lib/deploy-recipes/rbenv.rb
34
+ - lib/deploy-recipes/recipes/db.rake
35
+ - lib/deploy-recipes/recipes/db.rb
36
+ - lib/deploy-recipes/templates/nginx_unicorn.erb
37
+ - lib/deploy-recipes/templates/postgresql.yml.erb
38
+ - lib/deploy-recipes/templates/static_nginx.erb
39
+ - lib/deploy-recipes/templates/unicorn.rb.erb
40
+ - lib/deploy-recipes/templates/unicorn_init.erb
41
+ - lib/deploy-recipes/unicorn.rb
42
+ - lib/deploy-recipes/version.rb
43
+ homepage: https://github.com/liuhui998/deploy-recipes
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.24
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: nginx unicorn
67
+ test_files: []
68
+ has_rdoc: