projectdx_pipeline 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,10 +1,7 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
2
+ gem 'capistrano', '~> 2.9.0'
3
+ gem 'capistrano-ext', '~> 1.2.1'
5
4
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
5
  group :development do
9
6
  gem "rspec", "~> 2.3.0"
10
7
  gem "bundler", "~> 1.0.0"
data/Gemfile.lock CHANGED
@@ -1,12 +1,28 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ capistrano (2.9.0)
5
+ highline
6
+ net-scp (>= 1.0.0)
7
+ net-sftp (>= 2.0.0)
8
+ net-ssh (>= 2.0.14)
9
+ net-ssh-gateway (>= 1.1.0)
10
+ capistrano-ext (1.2.1)
11
+ capistrano (>= 1.0.0)
4
12
  diff-lcs (1.1.3)
5
13
  git (1.2.5)
14
+ highline (1.6.8)
6
15
  jeweler (1.6.4)
7
16
  bundler (~> 1.0)
8
17
  git (>= 1.2.5)
9
18
  rake
19
+ net-scp (1.0.4)
20
+ net-ssh (>= 1.99.1)
21
+ net-sftp (2.0.5)
22
+ net-ssh (>= 2.0.9)
23
+ net-ssh (2.2.1)
24
+ net-ssh-gateway (1.1.0)
25
+ net-ssh (>= 1.99.1)
10
26
  rake (0.9.2.2)
11
27
  rcov (0.9.11)
12
28
  rspec (2.3.0)
@@ -23,6 +39,8 @@ PLATFORMS
23
39
 
24
40
  DEPENDENCIES
25
41
  bundler (~> 1.0.0)
42
+ capistrano (~> 2.9.0)
43
+ capistrano-ext (~> 1.2.1)
26
44
  jeweler (~> 1.6.4)
27
45
  rcov
28
46
  rspec (~> 2.3.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 1.0.0
@@ -0,0 +1,59 @@
1
+
2
+ Capistrano::Configuration.instance.load do
3
+ ######################
4
+ ## Multistage setup ##
5
+ ######################
6
+
7
+ set(:stages, %w[alpha beta staging production])
8
+
9
+ # branches that must ask for a commit, and have that commit in their history
10
+ set(:branch_stages, %w[staging production])
11
+
12
+ # stages that will reset the database to a reference database before running
13
+ # migrations
14
+ set(:reference_db_stages, %w[alpha beta staging])
15
+
16
+ desc "This task is just for testing loading of the recipes and multistage requirements in an app"
17
+ task :testing do
18
+ puts "You are testing task loading for #{stage}. #{stage_loaded}"
19
+ end
20
+
21
+ ####################
22
+ # General Settings #
23
+ ####################
24
+
25
+ set(:use_sudo, false)
26
+ set(:deploy_via, :remote_cache)
27
+ set(:ssh_options, {:forward_agent => true})
28
+ set(:scm, :git)
29
+ set(:copy_exclude, %w[.git])
30
+ set(:repository) { "git@github.com:projectdx/#{application}.git" }
31
+ set(:user) { application }
32
+ set(:deploy_to) { "/var/www/#{application}" }
33
+ set(:db_username) { application }
34
+ set(:db_server, 'db1.renewfund.com')
35
+ set(:db_password) { abort "You must set the database password for this application with `set :db_password, 'foo'." }
36
+ set(:db_port, '5432')
37
+ set(:db_name) { application }
38
+ set(:rails_env) { stage }
39
+
40
+ #############
41
+ # Callbacks #
42
+ #############
43
+
44
+ before 'deploy:update', 'deploy:get_revision'
45
+ after 'deploy:update_code', 'deploy:migrate'
46
+
47
+ ############################
48
+ # Additional Files to Load #
49
+ ############################
50
+
51
+ load_paths << File.expand_path(File.join(File.dirname(__FILE__), 'capistrano'))
52
+ require 'bundler/capistrano'
53
+ require 'capistrano/ext/multistage'
54
+ load 'passenger'
55
+ load 'database_configuration'
56
+ load 'git_revision'
57
+ load 'deploy/assets'
58
+ load 'maintenance'
59
+ end
@@ -0,0 +1,5 @@
1
+ set :stage_loaded, 'The alpha stage was loaded.'
2
+
3
+ role :app, 'alpha1.renewfund.com'
4
+ role :web, 'alpha1.renewfund.com'
5
+ role :db, 'alpha1.renewfund.com', :primary => true, :source => true
@@ -0,0 +1,7 @@
1
+ set :stage_loaded, 'The beta stage was loaded.'
2
+ set :db_server, 'prod-db1.renewfund.com'
3
+ set :db_port, '5433'
4
+
5
+ role :app, 'beta1.renewfund.com'
6
+ role :web, 'beta1.renewfund.com'
7
+ role :db, 'beta1.renewfund.com', :primary => true, :source => true
@@ -0,0 +1 @@
1
+ set :stage_loaded, 'The production stage was loaded.'
@@ -0,0 +1 @@
1
+ set :stage_loaded, 'The staging stage was loaded.'
@@ -0,0 +1,83 @@
1
+ set(:db_defaults) do
2
+ {
3
+ 'username' => db_username,
4
+ 'password' => db_password,
5
+ 'adapter' => 'postgresql',
6
+ 'encoding' => 'UTF8',
7
+ 'host' => db_server,
8
+ 'database' => db_name,
9
+ 'port' => db_port
10
+ }
11
+ end
12
+
13
+ namespace :deploy do
14
+ def with_tempfile_on_remote_server(&block)
15
+ tempfile_name = capture('mktemp -t preparedb.XXXXXXXX').strip
16
+
17
+ yield tempfile_name
18
+ ensure
19
+ run "rm #{tempfile_name}"
20
+ end
21
+
22
+ def db_connection
23
+ fetch(:db_connection, {})
24
+ end
25
+
26
+ def dbinfo
27
+ @dbinfo ||= db_defaults.merge(db_connection)
28
+ unless stage == :production
29
+ @dbinfo['database'] = '%s-%s' % [db_name, stage]
30
+ end
31
+ @dbinfo
32
+ end
33
+
34
+ def run_with_password(cmd, pwd)
35
+ once = false
36
+ run cmd do |ch, stream, data|
37
+ $stdout.write(data)
38
+ unless once
39
+ ch.send_data pwd + "\n"
40
+ $stdout.write('[not shown]')
41
+ once = true
42
+ end
43
+ end
44
+ end
45
+
46
+ namespace :db do
47
+ desc "Regenerate deployment database.yml"
48
+ task :copy_database_yml do
49
+ put({ rails_env.to_s => dbinfo }.to_yaml, "#{release_path}/config/database.yml")
50
+ end
51
+
52
+ desc "Drop and recreate stage DB"
53
+ task :create do
54
+ if reference_db_stages.include? stage.to_s
55
+ puts "Cloning reference database!"
56
+ raise "Your database name #{dbinfo['database']} looks wrong" unless dbinfo['database'] =~ /^[\w-]+-#{stage}$/
57
+
58
+ with_tempfile_on_remote_server do |tf|
59
+ referencedb = "%s-reference" % db_name
60
+
61
+ popt = [['host', 'h'], ['username', 'U'], ['port', 'p']].
62
+ select { |key, flag| dbinfo[key] }.
63
+ map { |key, flag| '-%s "%s"' % [flag, dbinfo[key]] } * ' ' +
64
+ ' -W'
65
+
66
+ sql = <<-SQL % [referencedb, dbinfo['database'], dbinfo['database']]
67
+ select killusers('%s','%s');
68
+ drop database "%s";
69
+ SQL
70
+ put sql, tf
71
+
72
+ run_with_password %{psql postgres #{popt} -a -f #{tf} 2>&1}, dbinfo['password']
73
+ run_with_password %{createdb "#{dbinfo['database']}" #{popt} -T "#{referencedb}" 2>&1}, dbinfo['password']
74
+ end
75
+ else
76
+ puts "Not cloning reference database, because the #{stage} stage is not in reference_db_stages (#{reference_db_stages})."
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ before 'deploy:migrate', 'deploy:db:copy_database_yml'
83
+ before 'deploy:migrate', 'deploy:db:create'
@@ -0,0 +1,69 @@
1
+ namespace :deploy do
2
+ desc "Return SHA-1 commit ID of deployed branch"
3
+ task :show_revision do
4
+ puts capture("cat #{deploy_to}/current/REVISION")
5
+ end
6
+
7
+ desc "Determine commit to use (may default to HEAD)."
8
+ task :get_revision do
9
+ def stage
10
+ variables[:stage] && variables[:stage].to_s
11
+ end
12
+
13
+ def changed_in_git(filename)
14
+ `git diff --name-only`.grep(/^#{filename}$/).length > 0 ? true : false
15
+ end
16
+
17
+ def commit_of_rev(branch)
18
+ x=`git rev-parse --revs-only #{branch}`.chomp
19
+ return nil if x.empty?
20
+ return x
21
+ end
22
+
23
+ def commit_in_remote_branch?(commit,branch)
24
+ return false if commit.nil?
25
+ if %x{git branch -r --contains #{commit}}.grep(/^\s*origin\/#{branch}/).empty?
26
+ puts ""
27
+ puts "no rev matches #{commit} in the remote #{branch} branch(es)"
28
+ return false
29
+ end
30
+ true
31
+ end
32
+
33
+ def valid_commit?(commit)
34
+ return false if commit.nil?
35
+ if branch_stages.include? stage.to_s
36
+ return false unless commit_in_remote_branch?(commit,fetch(:deploy_branch, stage.to_s))
37
+ end
38
+ return true
39
+ end
40
+
41
+ # returns the actual branch name, if it exists. nil if it does not
42
+ def remote_branch_name(branch)
43
+ return nil if branch.nil?
44
+ rem_branch = `git branch -r`.grep(/^\s*origin\/(v|)#{branch}$/)[0]
45
+ return nil if rem_branch.nil?
46
+ return rem_branch.sub(/^\s*origin\//, '').chomp
47
+ end
48
+
49
+ set :revision, begin
50
+ deploy_version = ENV[ 'DEPLOY_VERSION' ]
51
+ deploy_version ||= 'HEAD' unless branch_stages.include?(stage.to_s)
52
+
53
+ commit = commit_of_rev(deploy_version)
54
+ until valid_commit?(commit) do
55
+ deploy_version=Capistrano::CLI.ui.ask( 'Enter release number to deploy: ' )
56
+ commit = commit_of_rev(deploy_version)
57
+ end
58
+ commit
59
+ end
60
+
61
+ set :branch do
62
+ revision
63
+ end
64
+
65
+ set :release_commit do
66
+ branch
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,53 @@
1
+ namespace :deploy do
2
+ namespace :web do
3
+ set(:maint_files) {["#{shared_path}/system/maintenance.html"]}
4
+
5
+ desc <<-DESC
6
+ Present a maintenance page to visitors. Disables your application's web \
7
+ interface by writing a "maintenance.html" file to each web server. The \
8
+ servers must be configured to detect the presence of this file, and if \
9
+ it is present, always display it instead of performing the request.
10
+
11
+ By default, the maintenance page will just say the site is down for \
12
+ "maintenance", and will be back "shortly", but you can customize the \
13
+ page by specifying the REASON environment variable:
14
+
15
+ $ cap deploy:web:disable \\
16
+ REASON="hardware upgrade"
17
+
18
+ Further customization will require that you write your own task.
19
+ DESC
20
+ task :disable, :roles => :web, :except => { :no_release => true } do
21
+ require 'erb'
22
+ on_rollback { maint_files.each do |file|
23
+ run "if [ -e #{file} ]; then rm #{file}; fi"
24
+ end
25
+ }
26
+
27
+ reason = ENV['REASON']
28
+
29
+ template = File.read("public/maintenance.rhtml")
30
+ result = ERB.new(template).result(binding)
31
+ maint_files.each do |file|
32
+ dir=File.dirname(file)
33
+ tmpfile=%x{mktemp -u /tmp/capXXXXXXXX} # this seems like the quickest way to just get a name.
34
+ tmpfile.chomp!
35
+ put result, tmpfile, :mode => 0644
36
+ run "if [ -d #{dir} -a \! -e #{file} ]; then mv #{tmpfile} #{file}; fi"
37
+ run "chcon -t httpd_sys_content_t #{file}; true" # we ignore this since some hosts have home on nfs
38
+ end
39
+ end
40
+
41
+ desc <<-DESC
42
+ Makes the application web-accessible again. Removes the \
43
+ "maintenance.html" page generated by deploy:web:disable, which (if your \
44
+ web servers are configured correctly) will make your application \
45
+ web-accessible again.
46
+ DESC
47
+ task :enable, :roles => :web, :except => { :no_release => true } do
48
+ maint_files.each do |file|
49
+ run "if [ -e #{file} ]; then rm #{file}; fi"
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,8 @@
1
+ namespace :deploy do
2
+ task :start do ; end
3
+ task :stop do ; end
4
+ task :restart, :roles => :app, :except => { :no_release => true } do
5
+ puts "Telling Passenger to restart the app."
6
+ run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
7
+ end
8
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{projectdx_pipeline}
8
- s.version = "0.2.0"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Renewable Funding"]
12
- s.date = %q{2011-12-07}
12
+ s.date = %q{2011-12-14}
13
13
  s.description = %q{Common pipeline tasks and libraries to be used for all components of the ProjectDX platform}
14
14
  s.email = %q{devteam@renewfund.com}
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,15 @@ Gem::Specification.new do |s|
27
27
  "Rakefile",
28
28
  "VERSION",
29
29
  "lib/projectdx_pipeline.rb",
30
+ "lib/projectdx_pipeline/capistrano.rb",
31
+ "lib/projectdx_pipeline/capistrano/config/deploy/alpha.rb",
32
+ "lib/projectdx_pipeline/capistrano/config/deploy/beta.rb",
33
+ "lib/projectdx_pipeline/capistrano/config/deploy/production.rb",
34
+ "lib/projectdx_pipeline/capistrano/config/deploy/staging.rb",
35
+ "lib/projectdx_pipeline/capistrano/database_configuration.rb",
36
+ "lib/projectdx_pipeline/capistrano/git_revision.rb",
37
+ "lib/projectdx_pipeline/capistrano/maintenance.rb",
38
+ "lib/projectdx_pipeline/capistrano/passenger.rb",
30
39
  "lib/projectdx_pipeline/database_configuration_template.rb",
31
40
  "lib/projectdx_pipeline/file.rb",
32
41
  "lib/projectdx_pipeline/railtie.rb",
@@ -47,17 +56,23 @@ Gem::Specification.new do |s|
47
56
  s.specification_version = 3
48
57
 
49
58
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
+ s.add_runtime_dependency(%q<capistrano>, ["~> 2.9.0"])
60
+ s.add_runtime_dependency(%q<capistrano-ext>, ["~> 1.2.1"])
50
61
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
51
62
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
63
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
53
64
  s.add_development_dependency(%q<rcov>, [">= 0"])
54
65
  else
66
+ s.add_dependency(%q<capistrano>, ["~> 2.9.0"])
67
+ s.add_dependency(%q<capistrano-ext>, ["~> 1.2.1"])
55
68
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
56
69
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
70
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
58
71
  s.add_dependency(%q<rcov>, [">= 0"])
59
72
  end
60
73
  else
74
+ s.add_dependency(%q<capistrano>, ["~> 2.9.0"])
75
+ s.add_dependency(%q<capistrano-ext>, ["~> 1.2.1"])
61
76
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
62
77
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
78
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
metadata CHANGED
@@ -4,10 +4,10 @@ version: !ruby/object:Gem::Version
4
4
  hash: 23
5
5
  prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 2
9
9
  - 0
10
- version: 0.2.0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Renewable Funding
@@ -15,14 +15,46 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-07 00:00:00 -08:00
18
+ date: 2011-12-14 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ type: :runtime
24
+ name: capistrano
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 43
31
+ segments:
32
+ - 2
33
+ - 9
34
+ - 0
35
+ version: 2.9.0
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ prerelease: false
39
+ type: :runtime
40
+ name: capistrano-ext
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ hash: 29
47
+ segments:
48
+ - 1
49
+ - 2
50
+ - 1
51
+ version: 1.2.1
52
+ requirement: *id002
21
53
  - !ruby/object:Gem::Dependency
22
54
  prerelease: false
23
55
  type: :development
24
56
  name: rspec
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
57
+ version_requirements: &id003 !ruby/object:Gem::Requirement
26
58
  none: false
27
59
  requirements:
28
60
  - - ~>
@@ -33,12 +65,12 @@ dependencies:
33
65
  - 3
34
66
  - 0
35
67
  version: 2.3.0
36
- requirement: *id001
68
+ requirement: *id003
37
69
  - !ruby/object:Gem::Dependency
38
70
  prerelease: false
39
71
  type: :development
40
72
  name: bundler
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
73
+ version_requirements: &id004 !ruby/object:Gem::Requirement
42
74
  none: false
43
75
  requirements:
44
76
  - - ~>
@@ -49,12 +81,12 @@ dependencies:
49
81
  - 0
50
82
  - 0
51
83
  version: 1.0.0
52
- requirement: *id002
84
+ requirement: *id004
53
85
  - !ruby/object:Gem::Dependency
54
86
  prerelease: false
55
87
  type: :development
56
88
  name: jeweler
57
- version_requirements: &id003 !ruby/object:Gem::Requirement
89
+ version_requirements: &id005 !ruby/object:Gem::Requirement
58
90
  none: false
59
91
  requirements:
60
92
  - - ~>
@@ -65,12 +97,12 @@ dependencies:
65
97
  - 6
66
98
  - 4
67
99
  version: 1.6.4
68
- requirement: *id003
100
+ requirement: *id005
69
101
  - !ruby/object:Gem::Dependency
70
102
  prerelease: false
71
103
  type: :development
72
104
  name: rcov
73
- version_requirements: &id004 !ruby/object:Gem::Requirement
105
+ version_requirements: &id006 !ruby/object:Gem::Requirement
74
106
  none: false
75
107
  requirements:
76
108
  - - ">="
@@ -79,7 +111,7 @@ dependencies:
79
111
  segments:
80
112
  - 0
81
113
  version: "0"
82
- requirement: *id004
114
+ requirement: *id006
83
115
  description: Common pipeline tasks and libraries to be used for all components of the ProjectDX platform
84
116
  email: devteam@renewfund.com
85
117
  executables: []
@@ -100,6 +132,15 @@ files:
100
132
  - Rakefile
101
133
  - VERSION
102
134
  - lib/projectdx_pipeline.rb
135
+ - lib/projectdx_pipeline/capistrano.rb
136
+ - lib/projectdx_pipeline/capistrano/config/deploy/alpha.rb
137
+ - lib/projectdx_pipeline/capistrano/config/deploy/beta.rb
138
+ - lib/projectdx_pipeline/capistrano/config/deploy/production.rb
139
+ - lib/projectdx_pipeline/capistrano/config/deploy/staging.rb
140
+ - lib/projectdx_pipeline/capistrano/database_configuration.rb
141
+ - lib/projectdx_pipeline/capistrano/git_revision.rb
142
+ - lib/projectdx_pipeline/capistrano/maintenance.rb
143
+ - lib/projectdx_pipeline/capistrano/passenger.rb
103
144
  - lib/projectdx_pipeline/database_configuration_template.rb
104
145
  - lib/projectdx_pipeline/file.rb
105
146
  - lib/projectdx_pipeline/railtie.rb