aktion_cap 0.1.2 → 0.1.3
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/CHANGELOG.md +5 -0
- data/aktion_cap.gemspec +1 -0
- data/lib/aktion_cap/recipe/base.rb +28 -0
- data/lib/aktion_cap/recipe/database.rb +4 -0
- data/lib/aktion_cap/recipe/nginx.rb +13 -0
- data/lib/aktion_cap/recipe/unicorn.rb +9 -0
- data/lib/aktion_cap/tasks.rb +50 -1
- data/lib/aktion_cap/version.rb +1 -1
- data/spec/capify_spec.rb +16 -0
- metadata +24 -4
data/CHANGELOG.md
CHANGED
data/aktion_cap.gemspec
CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = AktionCap::VERSION
|
17
17
|
|
18
|
+
gem.add_dependency 'activesupport', '~> 3.2.8'
|
18
19
|
gem.add_dependency 'capistrano', '~> 2.13.4'
|
19
20
|
gem.add_dependency 'capistrano-ext', '~> 1.2.1'
|
20
21
|
gem.add_dependency 'rvm-capistrano', '~> 1.2.7'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
def cset(name, *args, &block)
|
2
|
+
set(name, *args, &block) unless exists? name
|
3
|
+
end
|
4
|
+
|
5
|
+
def append(name, values)
|
6
|
+
if exists? name
|
7
|
+
raise "set_append requires an array value to append to" unless fetch(name).is_a? Array
|
8
|
+
set(name, fetch(name) + [values].flatten)
|
9
|
+
else
|
10
|
+
set(name, values)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Capistrano::Configuration.instance.load do
|
15
|
+
cset :shared_symlinks, []
|
16
|
+
cset :tasks_for_rake, []
|
17
|
+
|
18
|
+
namespace :deploy do
|
19
|
+
task :create_shared_symlinks do
|
20
|
+
run(shared_symlinks.map{|link| "ln -nfs #{shared_path}/#{link} #{release_path}/#{link}"}.join(' && '))
|
21
|
+
end
|
22
|
+
|
23
|
+
task :run_rake_tasks do
|
24
|
+
run "cd #{release_path} && RAILS_ENV=#{stage} bundle exec rake #{tasks_for_rake.join(' ')}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Capistrano::Configuration.instance.load do
|
2
|
+
namespace :nginx do
|
3
|
+
task :config do
|
4
|
+
remote_nginx_conf = "/etc/nginx/sites-enabled/#{application}_#{stage}"
|
5
|
+
run "sudo rm -f #{remote_nginx_conf} && sudo ln -nfs #{release_path}/config/nginx_#{stage}.conf #{remote_nginx_conf}"
|
6
|
+
restart
|
7
|
+
end
|
8
|
+
|
9
|
+
%w(start stop restart reload).each do |action|
|
10
|
+
task(action) { "sudo /etc/init.d/nginx #{action}" }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Capistrano::Configuration.instance.load do
|
2
|
+
append :shared_symlinks, 'config/unicorn.rb'
|
3
|
+
|
4
|
+
namespace :deploy do
|
5
|
+
%w(start stop restart).each do |action|
|
6
|
+
task(action, except: { no_release: true }) { run "cd #{current_path} && RAILS_ENV=#{stage} script/unicorn #{action}" }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/lib/aktion_cap/tasks.rb
CHANGED
@@ -54,6 +54,10 @@ require 'capistrano/ext/multistage'
|
|
54
54
|
require 'bundler/capistrano'
|
55
55
|
require 'rvm/capistrano'
|
56
56
|
require './config/boot'
|
57
|
+
require 'aktion_cap/recipe/base'
|
58
|
+
require 'aktion_cap/recipe/database'
|
59
|
+
require 'aktion_cap/recipe/nginx'
|
60
|
+
require 'aktion_cap/recipe/unicorn'
|
57
61
|
|
58
62
|
ssh_options[:username] = '#{opts[:ssh_user]}'
|
59
63
|
ssh_options[:forward_agent] = true
|
@@ -71,6 +75,7 @@ set :tasks_for_rake, %w(db:migrate)
|
|
71
75
|
|
72
76
|
after 'deploy:update_code', 'deploy:create_shared_symlinks'
|
73
77
|
before 'deploy:create_symlink', 'deploy:run_rake_tasks'
|
78
|
+
before 'deploy:restart', 'nginx:config'
|
74
79
|
after 'deploy', 'deploy:cleanup'
|
75
80
|
FILE
|
76
81
|
end
|
@@ -88,6 +93,47 @@ role :db, server_hostname, primary: true
|
|
88
93
|
end
|
89
94
|
end
|
90
95
|
|
96
|
+
def write_nginx(stage, opts)
|
97
|
+
File.open("config/nginx_#{stage.to_s}.conf", 'w') do |file|
|
98
|
+
file << <<-FILE
|
99
|
+
upstream #{opts[:application]}_#{stage.to_s} {
|
100
|
+
server unix:/tmp/unicorn-#{opts[:application]}_#{stage.to_s}.sock fail_timeout=0;
|
101
|
+
}
|
102
|
+
|
103
|
+
server {
|
104
|
+
listen 80;
|
105
|
+
|
106
|
+
server_name opts[stage][:server_hostname];
|
107
|
+
|
108
|
+
root /var/www/#{opts[:application]}/#{stage.to_s}/current/public;
|
109
|
+
access_log /var/log/nginx/#{opts[:application]}_#{stage.to_s}-access.log;
|
110
|
+
error_log /var/log/nginx/#{opts[:application]}_#{stage.to_s}-error.log;
|
111
|
+
|
112
|
+
location ~ ^/assets/ {
|
113
|
+
gzip_static on;
|
114
|
+
expires max;
|
115
|
+
add_header Cache-Control public;
|
116
|
+
}
|
117
|
+
|
118
|
+
location {
|
119
|
+
proxy_set_header X-Real-IP $remote_addr;
|
120
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
121
|
+
proxy_set_header Host $http_host;
|
122
|
+
proxy_redirect off;
|
123
|
+
|
124
|
+
if (!-f $request_filename) {
|
125
|
+
proxy_pass http://#{opts[:application]}_#{stage.to_s};
|
126
|
+
break;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
error_page 404 /404.html;
|
131
|
+
error_page 500 502 503 504 /500.html;
|
132
|
+
}
|
133
|
+
FILE
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
91
137
|
def install
|
92
138
|
desc 'capify'
|
93
139
|
task 'capify' do
|
@@ -95,7 +141,10 @@ role :db, server_hostname, primary: true
|
|
95
141
|
Dir.mkdir('config/deploy') unless Dir.exists?('config/deploy')
|
96
142
|
write_capfile
|
97
143
|
write_config_deploy opts
|
98
|
-
opts[:stages].each
|
144
|
+
opts[:stages].each do |stage|
|
145
|
+
write_stage_config_deploy(stage, opts)
|
146
|
+
write_nginx(stage, opts)
|
147
|
+
end
|
99
148
|
end
|
100
149
|
end
|
101
150
|
end
|
data/lib/aktion_cap/version.rb
CHANGED
data/spec/capify_spec.rb
CHANGED
@@ -69,6 +69,10 @@ describe 'capify' do
|
|
69
69
|
it { should contain_content "set :repository, '#{`git config --local remote.origin.url`.strip}'" }
|
70
70
|
it { should contain_content "set :scm, :git" }
|
71
71
|
it { should contain_content "ssh_options[:username] = 'deployer'" }
|
72
|
+
it { should contain_content "require 'aktion_cap/recipe/base'" }
|
73
|
+
it { should contain_content "require 'aktion_cap/recipe/database'" }
|
74
|
+
it { should contain_content "require 'aktion_cap/recipe/nginx'" }
|
75
|
+
it { should contain_content "require 'aktion_cap/recipe/unicorn'" }
|
72
76
|
end
|
73
77
|
|
74
78
|
describe 'dummy/config/deploy/production.rb' do
|
@@ -76,6 +80,10 @@ describe 'capify' do
|
|
76
80
|
it { should contain_content "set :port, 2222" }
|
77
81
|
it { should contain_content "set :server_hostname, 'localhost'" }
|
78
82
|
end
|
83
|
+
|
84
|
+
describe 'dummy/config/nginx_production.conf' do
|
85
|
+
it { should be_a_file_that_exists }
|
86
|
+
end
|
79
87
|
end
|
80
88
|
|
81
89
|
context 'custom' do
|
@@ -102,5 +110,13 @@ describe 'capify' do
|
|
102
110
|
it { should contain_content "set :port, 2323" }
|
103
111
|
it { should contain_content "set :server_hostname, 'staging.customapp.com'" }
|
104
112
|
end
|
113
|
+
|
114
|
+
describe 'dummy/config/nginx_production.conf' do
|
115
|
+
it { should be_a_file_that_exists }
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'dummy/config/nginx_staging.conf' do
|
119
|
+
it { should be_a_file_that_exists }
|
120
|
+
end
|
105
121
|
end
|
106
122
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aktion_cap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.8
|
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: 3.2.8
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: capistrano
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,6 +94,10 @@ files:
|
|
78
94
|
- aktion_cap.gemspec
|
79
95
|
- lib/aktion_cap.rb
|
80
96
|
- lib/aktion_cap/railtie.rb
|
97
|
+
- lib/aktion_cap/recipe/base.rb
|
98
|
+
- lib/aktion_cap/recipe/database.rb
|
99
|
+
- lib/aktion_cap/recipe/nginx.rb
|
100
|
+
- lib/aktion_cap/recipe/unicorn.rb
|
81
101
|
- lib/aktion_cap/tasks.rb
|
82
102
|
- lib/aktion_cap/version.rb
|
83
103
|
- lib/dummy_rails_template.rb
|
@@ -101,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
121
|
version: '0'
|
102
122
|
segments:
|
103
123
|
- 0
|
104
|
-
hash:
|
124
|
+
hash: 3571740651220432007
|
105
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
126
|
none: false
|
107
127
|
requirements:
|
@@ -110,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
130
|
version: '0'
|
111
131
|
segments:
|
112
132
|
- 0
|
113
|
-
hash:
|
133
|
+
hash: 3571740651220432007
|
114
134
|
requirements: []
|
115
135
|
rubyforge_project:
|
116
136
|
rubygems_version: 1.8.24
|