capistrano-kyan 0.2.10
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.
- checksums.yaml +7 -0
- data/.gitignore +41 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +2 -0
- data/capistrano-kyan.gemspec +25 -0
- data/lib/capistrano-kyan/capistrano_integration.rb +200 -0
- data/lib/capistrano-kyan/version.rb +3 -0
- data/lib/capistrano-kyan.rb +2 -0
- data/templates/vhost.conf.erb +15 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f90cdf9ffdea5aa1252cc080bebd70f433bf6bd8
|
4
|
+
data.tar.gz: 18a7cea51bf15c2989130a95d58831911bff9fd0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 744495bd147632d31375f6bc52ac4f91ef3ea4bd02f79d3dbdc913058d531d871e2d97bcb715632bafa31e96007891833a31a8c6d9c2e87ad27d45f3d03f59b2
|
7
|
+
data.tar.gz: e9e3f017ccac238dd000abb7a2cb6dc3ac44787e1c8020f29bae55e69e378ddf4cd48156b57b9e0a826d1f4308d7a62ee28575101dc9a3e0129e76418beaa338
|
data/.gitignore
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
!.gitignore
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
*.sw[a-p]
|
5
|
+
*.tmproj
|
6
|
+
*.tmproject
|
7
|
+
*.un~
|
8
|
+
*~
|
9
|
+
.DS_Store
|
10
|
+
.Spotlight-V100
|
11
|
+
.Trashes
|
12
|
+
._*
|
13
|
+
.bundle
|
14
|
+
.config
|
15
|
+
.directory
|
16
|
+
.elc
|
17
|
+
.redcar
|
18
|
+
.yardoc
|
19
|
+
/.emacs.desktop
|
20
|
+
/.emacs.desktop.lock
|
21
|
+
Desktop.ini
|
22
|
+
Gemfile.lock
|
23
|
+
Icon?
|
24
|
+
InstalledFiles
|
25
|
+
Session.vim
|
26
|
+
Thumbs.db
|
27
|
+
\#*\#
|
28
|
+
_yardoc
|
29
|
+
auto-save-list
|
30
|
+
coverage
|
31
|
+
doc/
|
32
|
+
lib/bundler/man
|
33
|
+
pkg
|
34
|
+
pkg/*
|
35
|
+
rdoc
|
36
|
+
spec/reports
|
37
|
+
test/tmp
|
38
|
+
test/version_tmp
|
39
|
+
tmp
|
40
|
+
tmtags
|
41
|
+
tramp
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Duncan Robertson
|
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,73 @@
|
|
1
|
+
# Capistrano Kyan
|
2
|
+
|
3
|
+
Capistrano plugin that includes a collection of tasks we find useful here at Kyan.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
### Setup
|
8
|
+
|
9
|
+
Add the library to your `Gemfile`:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
group :development do
|
13
|
+
gem 'capistrano-kyan', :git => "https://github.com/kyan/capistrano-kyan.git", :require => false
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
And load it into your deployment script `config/deploy.rb`:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'capistrano-kyan'
|
21
|
+
```
|
22
|
+
|
23
|
+
Add kyan vhost task hook:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
after "deploy:setup", "kyan:vhost:setup"
|
27
|
+
```
|
28
|
+
|
29
|
+
Add kyan db task hook:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
after "deploy:setup", "kyan:db:setup"
|
33
|
+
```
|
34
|
+
|
35
|
+
### Test
|
36
|
+
|
37
|
+
First, make sure you're running the latest release:
|
38
|
+
|
39
|
+
```
|
40
|
+
cap deploy:setup
|
41
|
+
```
|
42
|
+
|
43
|
+
Then you can test each individual task:
|
44
|
+
|
45
|
+
```
|
46
|
+
cap kyan:db:setup
|
47
|
+
cap kyan:vhost:setup
|
48
|
+
```
|
49
|
+
|
50
|
+
## Configuration
|
51
|
+
|
52
|
+
You can modify any of the following options in your `deploy.rb` config.
|
53
|
+
|
54
|
+
- `vhost_env` - Set vhost environment. Default to `rails_env` variable.
|
55
|
+
- `vhost_tmpl_path` - Set vhost template path. Default to `config/deploy`.
|
56
|
+
- `vhost_tmpl_name` - Set vhost template name. Default to `vhost.conf.erb`.
|
57
|
+
- `vhost_server_path` - Set vhost server path. Default to `/etc/nginx/sites-enabled`.
|
58
|
+
- `vhost_server_name` - Set vhost server name. Default to `File.basename(deploy_to)`.
|
59
|
+
|
60
|
+
I'm assuming you are using capistrano multistage.
|
61
|
+
|
62
|
+
## Available Tasks
|
63
|
+
|
64
|
+
To get a list of all capistrano tasks, run `cap -T`:
|
65
|
+
|
66
|
+
```
|
67
|
+
cap kyan:db:setup # Creates a database.yml file in the apps shared path.
|
68
|
+
cap kyan:vhost:setup # Creates and symlinks an Nginx virtualhost entry.
|
69
|
+
```
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
See LICENSE file for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'capistrano-kyan/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.name = "capistrano-kyan"
|
9
|
+
gem.version = CapistranoKyan::VERSION
|
10
|
+
gem.authors = ["Duncan Robertson"]
|
11
|
+
gem.email = ["duncan@kyan.com"]
|
12
|
+
gem.description = %q{Capistrano tasks for database.yml and vhost creation}
|
13
|
+
gem.summary = %q{A bunch of useful Capistrano tasks}
|
14
|
+
gem.homepage = "http://github.com/kyan/capistrano-kyan"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
|
22
|
+
gem.add_development_dependency 'rake'
|
23
|
+
|
24
|
+
gem.add_runtime_dependency 'capistrano'
|
25
|
+
end
|
@@ -0,0 +1,200 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require 'capistrano/version'
|
3
|
+
|
4
|
+
module CapistranoKyan
|
5
|
+
class CapistranoIntegration
|
6
|
+
TASKS = [
|
7
|
+
'deploy:seed',
|
8
|
+
'deploy:add_env',
|
9
|
+
'kyan:db:setup',
|
10
|
+
'kyan:vhost:setup',
|
11
|
+
'kyan:vhost:show',
|
12
|
+
'nginx:start',
|
13
|
+
'nginx:stop',
|
14
|
+
'nginx:restart',
|
15
|
+
'nginx:reload',
|
16
|
+
'foreman:export',
|
17
|
+
'foreman:start',
|
18
|
+
'foreman:stop',
|
19
|
+
'foreman:restart'
|
20
|
+
]
|
21
|
+
|
22
|
+
def self.load_into(capistrano_config)
|
23
|
+
capistrano_config.load do
|
24
|
+
before(CapistranoIntegration::TASKS) do
|
25
|
+
_cset(:app_env) { (fetch(:rails_env) rescue 'staging') }
|
26
|
+
_cset(:vhost_env) { fetch(:app_env) }
|
27
|
+
_cset(:vhost_tmpl_path) { 'config/vhosts' }
|
28
|
+
_cset(:vhost_tmpl_name) { 'vhost.conf.erb' }
|
29
|
+
_cset(:vhost_server_path) { '/etc/nginx/sites-enabled' }
|
30
|
+
_cset(:vhost_server_name) { File.basename(deploy_to) rescue fetch(:app_env) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def appize(app, prefix = 'staging')
|
34
|
+
"#{app.gsub('.','_')}_#{prefix}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def tmpl_server_location
|
38
|
+
run "mkdir -p #{shared_path}/config"
|
39
|
+
File.join(shared_path, 'config', "#{File.basename(deploy_to)}.conf")
|
40
|
+
end
|
41
|
+
|
42
|
+
def symlink(target, link)
|
43
|
+
run "ln -nfs #{target} #{link}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_template(template)
|
47
|
+
ERB.new(File.read(template), nil , '-').result(binding)
|
48
|
+
end
|
49
|
+
|
50
|
+
def build_vhost(path, name)
|
51
|
+
[
|
52
|
+
File.join(path, name),
|
53
|
+
File.join(File.dirname(__FILE__),'../../templates/vhost.conf.erb')
|
54
|
+
].each do |template|
|
55
|
+
if File.file? template
|
56
|
+
return parse_template(template)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
namespace :deploy do
|
62
|
+
desc "Load the database with seed data"
|
63
|
+
task :seed do
|
64
|
+
run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=#{app_env}"
|
65
|
+
end
|
66
|
+
|
67
|
+
task :add_env do
|
68
|
+
put "RAILS_ENV=#{app_env}", "#{release_path}/.env"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
after "deploy:finalize_update", "deploy:add_env"
|
73
|
+
|
74
|
+
namespace :nginx do
|
75
|
+
task :start, :roles => :app, :except => { :no_release => true } do
|
76
|
+
run "sudo /etc/init.d/nginx start"
|
77
|
+
end
|
78
|
+
|
79
|
+
task :stop, :roles => :app, :except => { :no_release => true } do
|
80
|
+
run "sudo /etc/init.d/nginx stop"
|
81
|
+
end
|
82
|
+
|
83
|
+
task :restart, :roles => :app, :except => { :no_release => true } do
|
84
|
+
run "sudo /etc/init.d/nginx restart"
|
85
|
+
end
|
86
|
+
|
87
|
+
task :reload, :roles => :app, :except => { :no_release => true } do
|
88
|
+
run "sudo /etc/init.d/nginx reload"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
namespace :foreman do
|
93
|
+
desc "Export the Procfile to Ubuntu's upstart scripts"
|
94
|
+
task :export, :roles => :app do
|
95
|
+
run "cd #{release_path} && sudo foreman export upstart /etc/init -a #{vhost_server_name} -u #{user} -l #{shared_path}/log"
|
96
|
+
end
|
97
|
+
desc "Start the application services"
|
98
|
+
task :start, :roles => :app do
|
99
|
+
run "sudo start #{vhost_server_name}"
|
100
|
+
end
|
101
|
+
|
102
|
+
desc "Stop the application services"
|
103
|
+
task :stop, :roles => :app do
|
104
|
+
run "sudo stop #{vhost_server_name}"
|
105
|
+
end
|
106
|
+
|
107
|
+
desc "Restart the application services"
|
108
|
+
task :restart, :roles => :app do
|
109
|
+
run "sudo start #{vhost_server_name} || sudo restart #{vhost_server_name}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
namespace :kyan do
|
114
|
+
#
|
115
|
+
# vhost cap tasks
|
116
|
+
#
|
117
|
+
namespace :vhost do
|
118
|
+
desc <<-DESC
|
119
|
+
Creates and symlinks an Nginx virtualhost entry.
|
120
|
+
|
121
|
+
By default, this task uses a builtin template which you
|
122
|
+
see the output with rake kyan:vhost:show. If you need to
|
123
|
+
customise this, you can create your own erb template and
|
124
|
+
update the :vhost_tmpl_path and :vhost_tmpl_name variables.
|
125
|
+
DESC
|
126
|
+
task :setup, :except => { :no_release => true } do
|
127
|
+
if tmpl = build_vhost(vhost_tmpl_path, vhost_tmpl_name)
|
128
|
+
put tmpl, tmpl_server_location
|
129
|
+
symlink(tmpl_server_location, vhost_server_path)
|
130
|
+
else
|
131
|
+
puts "Could not find a suitable template."
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
desc "Displays the vhost that will be uploaded to server"
|
136
|
+
task :show, :except => { :no_release => true } do
|
137
|
+
puts build_vhost(vhost_tmpl_path, vhost_tmpl_name)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
#
|
142
|
+
# database.yml cap tasks
|
143
|
+
#
|
144
|
+
namespace :db do
|
145
|
+
desc <<-DESC
|
146
|
+
Creates a database.yml file in the apps shared path.
|
147
|
+
DESC
|
148
|
+
task :setup, :except => { :no_release => true } do
|
149
|
+
|
150
|
+
require 'digest/sha1'
|
151
|
+
app = appize(application, fetch(:stage))
|
152
|
+
database = fetch(:db_database, app)
|
153
|
+
username = fetch(:db_username, app)
|
154
|
+
password = Capistrano::CLI.ui.ask("DB password for #{database} (empty for default): ")
|
155
|
+
password = password.empty? ? Digest::SHA1.hexdigest(database) : password
|
156
|
+
|
157
|
+
default_template = <<-EOF
|
158
|
+
base: &base
|
159
|
+
encoding: utf8
|
160
|
+
adapter: postgresql
|
161
|
+
pool: <%= fetch(:db_pool, 5) %>
|
162
|
+
host: <%= fetch(:db_host, 'localhost') %>
|
163
|
+
<%= fetch(:stage) %>:
|
164
|
+
database: <%= database %>
|
165
|
+
username: <%= username %>
|
166
|
+
password: <%= password %>
|
167
|
+
<<: *base
|
168
|
+
EOF
|
169
|
+
|
170
|
+
location = fetch(:template_dir, "config/deploy") + '/database.yml.erb'
|
171
|
+
template = File.file?(location) ? File.read(location) : default_template
|
172
|
+
config = ERB.new(template, nil , '-')
|
173
|
+
|
174
|
+
run "mkdir -p #{shared_path}/config"
|
175
|
+
put config.result(binding), "#{shared_path}/config/database.yml"
|
176
|
+
end
|
177
|
+
|
178
|
+
#
|
179
|
+
# Updates the symlink for database.yml file to the just deployed release.
|
180
|
+
#
|
181
|
+
task :symlink, :except => { :no_release => true } do
|
182
|
+
path_to_appl_database_yml = "#{release_path}/config/database.yml"
|
183
|
+
path_to_conf_database_yml = "#{shared_path}/config/database.yml"
|
184
|
+
|
185
|
+
run "ln -nfs #{path_to_conf_database_yml} #{path_to_appl_database_yml}"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
after "deploy:finalize_update", "kyan:db:symlink"
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
if Capistrano::Configuration.instance
|
197
|
+
CapistranoKyan::CapistranoIntegration.load_into(Capistrano::Configuration.instance)
|
198
|
+
else
|
199
|
+
abort "Capinstrano-kyan requires Capistrano 2"
|
200
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
server {
|
2
|
+
listen 80;
|
3
|
+
server_name <%= vhost_server_name %>;
|
4
|
+
root <%= current_path %>/public;
|
5
|
+
passenger_enabled on;
|
6
|
+
rails_env <%= vhost_env %>;
|
7
|
+
|
8
|
+
# serve static content directly
|
9
|
+
location ~* \.(ico|jpg|gif|png|swf|html)$ {
|
10
|
+
if (-f $request_filename) {
|
11
|
+
expires max;
|
12
|
+
break;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-kyan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.10
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Duncan Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: capistrano
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Capistrano tasks for database.yml and vhost creation
|
42
|
+
email:
|
43
|
+
- duncan@kyan.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- capistrano-kyan.gemspec
|
54
|
+
- lib/capistrano-kyan.rb
|
55
|
+
- lib/capistrano-kyan/capistrano_integration.rb
|
56
|
+
- lib/capistrano-kyan/version.rb
|
57
|
+
- templates/vhost.conf.erb
|
58
|
+
homepage: http://github.com/kyan/capistrano-kyan
|
59
|
+
licenses: []
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.0.14
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: A bunch of useful Capistrano tasks
|
81
|
+
test_files: []
|