debot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create use 1.9.3@debot
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * First release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in debot.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ikenna Okpala
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.
@@ -0,0 +1,74 @@
1
+ # Debot
2
+
3
+ Custom recipes that extend capistrano for provisioning and deploying rails application to a VPS..
4
+
5
+ This gem originates from Railscasts (Ryan Bates) excellent series of screencasts on deployment.. I
6
+ suggest you should check it out..
7
+
8
+ 1. [Capistrano Recipes](http://railscasts.com/episodes/337-capistrano-recipes)
9
+ 2. [Deploying to a VPS](http://railscasts.com/episodes/335-deploying-to-a-vps)
10
+ 3. [Deployment etc..](http://railscasts.com/?tag_id=21)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'debot'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install debot
25
+
26
+ $ capify .
27
+
28
+ Next generate the stages and deploy files by typing:
29
+
30
+ $ rake debot:setup
31
+
32
+ NB: You need to require debot in you deploy.rb file, this if you don't want debot to generate the stages and deploy files for you.
33
+
34
+
35
+ ## Usage
36
+ For a detailed list of all the the task availble:
37
+
38
+ $ cap -vT
39
+
40
+ To provision an ubuntu based VPS:
41
+
42
+ $ cap debot:install
43
+
44
+ To setup your application/website:
45
+
46
+ $ cap deploy:setup
47
+
48
+ NB: this will setup your postgres database, nginx and unicorn config for the application.
49
+
50
+ If you need to work on a bug in production first:
51
+
52
+ $ cap go:down
53
+
54
+ And then after the bug is fixed:
55
+
56
+ $ cap go:live
57
+
58
+ If you need to undo the application setup (i.e nginx, unicorn and postgres) configs
59
+
60
+ $ cap debot:takedown
61
+
62
+ ##Version
63
+
64
+ 0.0.1.alpha
65
+
66
+ (I am just pouring out ideas on this gem, as i use it on multiple projects. it is under constant development. You are welcome to contribute, try it out and give feeback)
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "debot/version"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.platform = Gem::Platform::RUBY
7
+ gem.authors = ["Ikenna Okpala"]
8
+ gem.email = ["ikennaokpala@gmail.com"]
9
+ gem.description = %q{Custom recipes that extend capisttrno for provisioning and deploying rails application to a VPS..}
10
+ gem.summary = %q{Home made capistrano recipes bundle into a gem..}
11
+ gem.homepage = "http://github.com/kengimel/debot"
12
+
13
+ gem.required_rubygems_version = ">= #{Debot::VERSION}"
14
+ gem.rubyforge_project = "debot"
15
+
16
+
17
+ gem.files = `git ls-files`.split($\)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.name = "debot"
21
+ gem.require_paths = ["lib"]
22
+ gem.version = Debot::VERSION
23
+ gem.extra_rdoc_files = [
24
+ "LICENSE",
25
+ "README.md"
26
+ ]
27
+
28
+ gem.add_dependency "rake"
29
+ gem.add_dependency "capistrano", ">= 2.12.0"
30
+ gem.add_dependency "capistrano-ext", ">= 1.2.1"
31
+ end
@@ -0,0 +1,34 @@
1
+ # config/deploy.rb
2
+ require "bundler/capistrano"
3
+
4
+ require 'debot'
5
+
6
+ server "<%=@server%>", :domain, :web, :app, :db, primary: true
7
+
8
+ set :user, "<%=@user%>"
9
+ set :group, "<%=@group%>"
10
+ set :use_sudo, false
11
+ set :keep_releases, <%=@number_of_releases%> # keep only the last 7 releases
12
+
13
+ set :application, "<%=@application_name%>"
14
+ set :stages, %w(<%=@stage_names.join(" ")%>)
15
+ set :default_stage, "<%=@stage_names.first%>"
16
+
17
+ # This needs to be after the stages variable declaration
18
+ require "capistrano/ext/multistage"
19
+
20
+ set :default_shell, "bash -l" # set the cap shell to be same as user's SSH environment
21
+
22
+ default_run_options[:pty] = true
23
+ ssh_options[:forward_agent] = true
24
+
25
+ set :scm, :<%=@scm%>
26
+ set :scm_verbose, true
27
+ set :repository, "<%=@repository%>"
28
+ set :migrate_target, :current
29
+ set :normalize_asset_timestamps, false
30
+ set :deploy_via, :remote_cache
31
+
32
+ #ssh_options[:verbose] = :debug # don't remove it's very important and meant for debugging capistrano
33
+
34
+ after "deploy", "deploy:cleanup"
@@ -0,0 +1,27 @@
1
+ upstream <%= domain %> {
2
+ server unix:<%= shared_path %>/unicorn/tmp/sockets/unicorn.sock fail_timeout=0;
3
+ }
4
+
5
+ server {
6
+ listen 80;
7
+ server_name <%= domains.join(" ") %>;
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 @<%= domain %>;
17
+ location @<%= domain %>{
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://<%= domain %>;
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
+ <%= stage %>:
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,5 @@
1
+ class RedirectController < ApplicationController
2
+ def index
3
+ redirect_to "/"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ match '*path', :controller => 'redirect', :action => 'index'
3
+ end
@@ -0,0 +1,12 @@
1
+ set :domain, "<%=@domain%>"
2
+
3
+ set :branch, "<%=@branch%>"
4
+
5
+ set :app_parent_directory, "<%=@app_parent_directory %>"
6
+ set :deploy_to, "<%=@deploy_to%>"
7
+
8
+ set :rails_env, "<%=@stage_name%>"
9
+ set :environment, "<%=@stage_name%>"
10
+
11
+ set_default(:stage, "<%=@stage_name%>")
12
+ set_default(:stage_db_user, "<%=@application_name%>_<%=@stage_name%>")
@@ -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 "<%= shared_path %>/unicorn/tmp/sockets/unicorn.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 <%= stage %> "
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,2 @@
1
+ require 'debot/debot_recipes'
2
+ require 'debot/railtie' if defined?(Rails)
@@ -0,0 +1,10 @@
1
+ require 'capistrano'
2
+ require 'capistrano/cli'
3
+
4
+ Capistrano::Configuration::Namespaces::Namespace.class_eval do
5
+ def capture(*args)
6
+ parent.capture *args
7
+ end
8
+ end #this is a work around for issue 168 https://github.com/capistrano/capistrano/issues/168#issuecomment-4144687
9
+
10
+ Dir[File.expand_path('../recipes/*.rb', __FILE__)].sort.each { |f| load f }
@@ -0,0 +1,88 @@
1
+ require 'erb'
2
+
3
+ def template_rake(from, to)
4
+ File.open(to, 'w') { |f| f.write(ERB.new(erb_path(from)).result(binding)) }
5
+ end
6
+
7
+ def template(from, to)
8
+ put ERB.new(erb_path(from)).result(binding), to
9
+ end
10
+
11
+ def erb_path(from)
12
+ File.read(File.expand_path("../../../../generators/templates/#{from}", __FILE__))
13
+ end
14
+
15
+ def set_default(name, *args, &block)
16
+ set(name, *args, &block) unless exists?(name)
17
+ end
18
+
19
+ require 'rails'
20
+
21
+ module Setup
22
+ def self.ask(question)
23
+ process(question)
24
+ end
25
+
26
+ def self.ask?(question)
27
+ %w[yes y yeah yep true].include?(process(question))
28
+ end
29
+
30
+ def self.run
31
+ puts "Kindly provide the following details:"
32
+ puts
33
+ @server = ask("Your server name or IP address:")
34
+ @application_name = ask("Your application name:")
35
+ @user = ask("Your deployment user's name:")
36
+ @group = ask("Our deployment user's system group ?")
37
+ @number_of_releases = ask("How many releases would like to keep?")
38
+ @scm = ask("Your choosen scm (git or svn)?")
39
+ @repository = ask("Enter your repository's url/location:")
40
+ @stage_names = []
41
+
42
+ begin
43
+ puts
44
+ puts "Provide details for creating a multi-stage file:"
45
+ puts
46
+ @stage_name = ask("What would you like to call this stage file?")
47
+ @stage_names << @stage_name
48
+ @domain = ask("What is your #{@stage_name} domain name?")
49
+ @app_parent_directory = ask("What is the parent directory for #{@stage_name} stage? (Given full path details)")
50
+ @deploy_to = ask("Where on your server would #{@stage_name} be located? (Give file path)")
51
+ @branch = ask("What #{@scm} branch would you like to deploy for this stage?")
52
+ stages_directory = File.join(Rails.root, "config/deploy")
53
+
54
+ puts "Creating stage file #{stages_directory}/#{@stage_name}.rb"
55
+
56
+ if File.directory?(stages_directory)
57
+ template_rake("stages.rb.erb", "#{stages_directory}/#{@stage_name}.rb")
58
+ else
59
+ system "mkdir -p #{stages_directory}"
60
+ template_rake("stages.rb.erb", "#{stages_directory}/#{@stage_name}.rb")
61
+ end
62
+ end while(ask?("Would you like to create a (another) stage file? (yes/no)"))
63
+
64
+ deploy_directory = File.join(Rails.root, "config")
65
+
66
+ puts "Creating your deploy file #{deploy_directory}/deploy.rb"
67
+
68
+ template_rake("deploy.rb.erb", "#{deploy_directory}/deploy.rb")
69
+
70
+ end
71
+
72
+ private
73
+ def self.process(question)
74
+ puts question
75
+ STDIN.gets.chomp.downcase #returns user input
76
+ end
77
+
78
+ def self.parse_domain(domain)
79
+ split_domain = domain.split('.')
80
+ if split_domain.include?('www')
81
+ return [domain]
82
+ elsif split_domain.size >= 3
83
+ return [domain]
84
+ else
85
+ return [domain, "www.#{domain}"]
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,9 @@
1
+ require 'debot'
2
+ require 'rails'
3
+ module Debot
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load File.expand_path("../tasks/debot.rake",__FILE__)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,45 @@
1
+ require_relative '../helpers/utils'
2
+
3
+ begin
4
+ Capistrano::Configuration.instance.load do
5
+ namespace :debot do
6
+ desc "Install everything onto the server"
7
+ task :install do
8
+ run "#{sudo} apt-get -y update"
9
+ run "#{sudo} apt-get -y install python-software-properties"
10
+ end
11
+
12
+ desc "Remove application from server"
13
+ task :takedown do
14
+ run "#{sudo} rm /etc/init.d/unicorn_#{domain}"
15
+ run "#{sudo} rm /etc/nginx/sites-enabled/#{domain}"
16
+ run "cd #{app_parent_directory}/#{domain}/ && #{sudo} rm -r *"
17
+ run %Q{#{sudo} -u postgres psql -c "drop database #{postgresql_database};"}
18
+ run %Q{#{sudo} -u postgres psql -c "drop role #{postgresql_user};"}
19
+ end
20
+ before "debot:takedown","unicorn:stop"
21
+ after "debot:takedown", "nginx:restart"
22
+ end
23
+
24
+ namespace :go do
25
+ desc "Switch to maintenance page and move routes file"
26
+ task :down do
27
+ run "mv #{current_path}/config/routes.rb #{current_path}/config/routes_down.rb"
28
+ template "redirect_controller.rb.erb", "#{current_path}/app/controllers/redirect_controller.rb"
29
+ template "routes.rb.erb", "#{current_path}/config/routes.rb"
30
+ run "mv #{current_path}/public/index_live.html #{current_path}/public/index.html"
31
+ end
32
+ after "go:down", "debot:restart"
33
+
34
+ desc "Switch to live content and re-instate routes file"
35
+ task :live do
36
+ run "rm #{current_path}/config/routes.rb #{current_path}/app/controllers/redirect_controller.rb"
37
+ run "mv #{current_path}/config/routes_down.rb #{current_path}/config/routes.rb"
38
+ run "mv #{current_path}/public/index.html #{current_path}/public/index_live.html"
39
+ end
40
+ after "go:live", "debot:restart"
41
+ end
42
+ end
43
+
44
+ rescue
45
+ end
@@ -0,0 +1,18 @@
1
+ begin
2
+ Capistrano::Configuration.instance.load do
3
+ namespace :check do
4
+ desc "Make sure local git is in sync with remote."
5
+ task :revision, roles: :web do
6
+ unless `git rev-parse HEAD` == `git rev-parse origin/#{branch}`
7
+ puts "WARNING: HEAD is not the same as origin/#{branch}"
8
+ puts "Run `git push` to sync changes."
9
+ exit
10
+ end
11
+ end
12
+ #before "debot", "check:revision"
13
+ #before "debot:migrations", "check:revision"
14
+ #before "debot:cold", "check:revision"
15
+ end
16
+ end
17
+ rescue
18
+ end
@@ -0,0 +1,33 @@
1
+ begin
2
+ Capistrano::Configuration.instance.load do
3
+ set_default :assets_dependencies, %w(public app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb)
4
+ set_default :asset_env, "RAILS_GROUPS=assets"
5
+
6
+ namespace :debot do
7
+ namespace :assets do
8
+ desc <<-DESC
9
+ Run the asset precompilation rake task. You can specify the full path \
10
+ to the rake executable by setting the rake variable. You can also \
11
+ specify additional environment variables to pass to rake via the \
12
+ asset_env variable. The defaults are:
13
+
14
+ set :rake, "rake"
15
+ set :rails_env, "production"
16
+ set :asset_env, "RAILS_GROUPS=assets"
17
+ set :assets_dependencies, fetch(:assets_dependencies) + %w(config/locales/js)
18
+ DESC
19
+ task :precompile, :roles => :web, :except => { :no_release => true } do
20
+ #from = source.next_revision(current_revision)
21
+ #if capture("cd #{latest_release} && #{source.local.log(from)} #{assets_dependencies.join ' '} | wc -l").to_i > 0
22
+ run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
23
+ #else
24
+ #logger.info "Skipping asset pre-compilation because there were no asset changes"
25
+ #end
26
+ end
27
+ after "deploy", "debot:assets:precompile"
28
+ after "debot:assets:precompile", "unicorn:restart"
29
+ end
30
+ end
31
+ end
32
+ rescue
33
+ end
@@ -0,0 +1,13 @@
1
+ begin
2
+ Capistrano::Configuration.instance.load do
3
+ namespace :imagemagick do
4
+ desc "Installing ImageMagick"
5
+ task :install, roles: :web do
6
+ run "#{sudo} apt-get -y update"
7
+ run "#{sudo} apt-get -y install libmagickwand-dev imagemagick"
8
+ end
9
+ after "debot:install", "imagemagick:install"
10
+ end
11
+ end
12
+ rescue
13
+ end
@@ -0,0 +1,34 @@
1
+ begin
2
+ Capistrano::Configuration.instance.load do
3
+ set_default(:domains) { Setup.parse_domain(domain)}
4
+
5
+ namespace :nginx do
6
+ desc "Install latest stable release of nginx"
7
+ task :install, roles: :web do
8
+ run "#{sudo} add-apt-repository -y ppa:nginx/stable"
9
+ run "#{sudo} apt-get -y update"
10
+ run "#{sudo} apt-get -y install nginx"
11
+ end
12
+ after "debot:install", "nginx:install"
13
+
14
+ desc "Setup nginx configuration for this application"
15
+ task :setup, roles: :web do
16
+ run "mkdir -p #{shared_path}/nginx"
17
+ template "nginx_unicorn.erb", "#{shared_path}/nginx/nginx_conf"
18
+ run "#{sudo} mv #{shared_path}/nginx/nginx_conf /etc/nginx/sites-enabled/#{domain}"
19
+ #run "#{sudo} rm -f /etc/nginx/sites-enabled/default"
20
+ restart
21
+ end
22
+ after "deploy:setup", "nginx:setup"
23
+
24
+ %w[start stop restart].each do |command|
25
+ desc "#{command} nginx"
26
+ task command, roles: :web do
27
+ run "#{sudo} service nginx #{command}"
28
+ end
29
+ #after "deploy:#{command}", "nginx:#{command}"
30
+ end
31
+ end
32
+ end
33
+ rescue
34
+ end
@@ -0,0 +1,14 @@
1
+ begin
2
+ Capistrano::Configuration.instance.load do
3
+ namespace :nodejs do
4
+ desc "Install the latest relase of Node.js"
5
+ task :install, roles: :app do
6
+ run "#{sudo} add-apt-repository -y ppa:chris-lea/node.js"
7
+ run "#{sudo} apt-get -y update"
8
+ run "#{sudo} apt-get -y install nodejs"
9
+ end
10
+ after "debot:install", "nodejs:install"
11
+ end
12
+ end
13
+ rescue
14
+ end
@@ -0,0 +1,39 @@
1
+ begin
2
+ Capistrano::Configuration.instance.load do
3
+ set_default(:postgresql_host, "localhost")
4
+ set_default(:postgresql_user) { stage_db_user }
5
+ set_default(:postgresql_password) { Capistrano::CLI.password_prompt "PostgreSQL Password: " }
6
+ set_default(:postgresql_database) { "#{application}_#{stage}" }
7
+
8
+ namespace :postgresql do
9
+ desc "Install the latest stable release of PostgreSQL."
10
+ task :install, roles: :db, only: {primary: true} do
11
+ run "#{sudo} add-apt-repository -y ppa:pitti/postgresql"
12
+ run "#{sudo} apt-get -y update"
13
+ run "#{sudo} apt-get -y install postgresql libpq-dev"
14
+ end
15
+ after "debot:install", "postgresql:install"
16
+
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
37
+ end
38
+ rescue
39
+ end
@@ -0,0 +1,34 @@
1
+ begin
2
+ Capistrano::Configuration.instance.load do
3
+ set_default :ruby_version, "1.9.3-p125"
4
+ #set_default :rbenv_bootstrap, "bootstrap-ubuntu-11-10"
5
+
6
+ namespace :rbenv do
7
+ desc "Install rbenv, Ruby, and the Bundler gem"
8
+ task :install, roles: :app do
9
+ run "#{sudo} apt-get -y install curl git-core"
10
+ run "curl -L https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash"
11
+ bashrc = <<-BASHRC
12
+ if [ -d $HOME/.rbenv ]; then
13
+ export PATH="$HOME/.rbenv/bin:$PATH"
14
+ eval "$(rbenv init -)"
15
+ fi
16
+ BASHRC
17
+ put bashrc, "/tmp/rbenvrc"
18
+ run "cat /tmp/rbenvrc ~/.bashrc > ~/.bashrc.tmp"
19
+ run "mv ~/.bashrc.tmp ~/.bashrc"
20
+ run %q{export PATH="$HOME/.rbenv/bin:$PATH"}
21
+ run %q{eval "$(rbenv init -)"}
22
+ #run "rbenv #{rbenv_bootstrap}" # the next two lines are workarounds from .rbenv/plugins/rbenv-installer/bin/rbenv-bootstrap-ubuntu-11-10
23
+ run "#{sudo} apt-get -y update"
24
+ run "#{sudo} apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-gplv2-dev"
25
+ run "rbenv install #{ruby_version}"
26
+ run "rbenv global #{ruby_version}"
27
+ run "gem install bundler --no-ri --no-rdoc"
28
+ run "rbenv rehash"
29
+ end
30
+ after "debot:install", "rbenv:install"
31
+ end
32
+ end
33
+ rescue
34
+ end
@@ -0,0 +1,32 @@
1
+ begin
2
+ Capistrano::Configuration.instance.load do
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
+ namespace :unicorn do
10
+ desc "Setup Unicorn initializer and app configuration"
11
+ task :setup, roles: :app do
12
+ run "mkdir -p #{shared_path}/config"
13
+ run "mkdir -p #{shared_path}/unicorn/tmp/sockets"
14
+ template "unicorn.rb.erb", unicorn_config
15
+ template "unicorn_init.erb", "#{shared_path}/unicorn/unicorn_init"
16
+ run "chmod +x #{shared_path}/unicorn/unicorn_init"
17
+ run "#{sudo} mv #{shared_path}/unicorn/unicorn_init /etc/init.d/unicorn_#{domain}"
18
+ run "#{sudo} update-rc.d -f unicorn_#{domain} 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_#{domain} #{command}"
26
+ end
27
+ after "deploy:#{command}", "unicorn:#{command}"
28
+ end
29
+ end
30
+ end
31
+ rescue
32
+ end
@@ -0,0 +1,8 @@
1
+ require_relative '../helpers/utils'
2
+
3
+ namespace :debot do
4
+ desc "Setup deploy.rb file and stages"
5
+ task :setup do
6
+ Setup.run
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Debot
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: debot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ikenna Okpala
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
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
+ - !ruby/object:Gem::Dependency
31
+ name: capistrano
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 2.12.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.12.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: capistrano-ext
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.1
62
+ description: Custom recipes that extend capisttrno for provisioning and deploying
63
+ rails application to a VPS..
64
+ email:
65
+ - ikennaokpala@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files:
69
+ - LICENSE
70
+ - README.md
71
+ files:
72
+ - .gitignore
73
+ - .rvmrc
74
+ - CHANGLOG.md
75
+ - Gemfile
76
+ - LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - debot.gemspec
80
+ - generators/templates/deploy.rb.erb
81
+ - generators/templates/nginx_unicorn.erb
82
+ - generators/templates/postgresql.yml.erb
83
+ - generators/templates/redirect_controller.rb.erb
84
+ - generators/templates/routes.rb.erb
85
+ - generators/templates/stages.rb.erb
86
+ - generators/templates/unicorn.rb.erb
87
+ - generators/templates/unicorn_init.erb
88
+ - lib/debot.rb
89
+ - lib/debot/debot_recipes.rb
90
+ - lib/debot/helpers/utils.rb
91
+ - lib/debot/railtie.rb
92
+ - lib/debot/recipes/base.rb
93
+ - lib/debot/recipes/check.rb
94
+ - lib/debot/recipes/debot_assets.rb
95
+ - lib/debot/recipes/imagemagick.rb
96
+ - lib/debot/recipes/nginx.rb
97
+ - lib/debot/recipes/nodejs.rb
98
+ - lib/debot/recipes/postgresql.rb
99
+ - lib/debot/recipes/rbenv.rb
100
+ - lib/debot/recipes/unicorn.rb
101
+ - lib/debot/tasks/debot.rake
102
+ - lib/debot/version.rb
103
+ homepage: http://github.com/kengimel/debot
104
+ licenses: []
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ segments:
116
+ - 0
117
+ hash: 1093380634535250194
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: 0.0.1
124
+ requirements: []
125
+ rubyforge_project: debot
126
+ rubygems_version: 1.8.24
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: Home made capistrano recipes bundle into a gem..
130
+ test_files: []