cmdeploy 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cmdeploy +61 -0
- data/lib/cmdeploy/recipes/assets.rb +17 -0
- data/lib/cmdeploy/recipes/base.rb +25 -0
- data/lib/cmdeploy/recipes/bundler.rb +20 -0
- data/lib/cmdeploy/recipes/nginx.rb +30 -0
- data/lib/cmdeploy/recipes/password_file.rb +24 -0
- data/lib/cmdeploy/recipes/revision_history.rb +19 -0
- data/lib/cmdeploy/recipes/templates/deploy_rb.erb +18 -0
- data/lib/cmdeploy/recipes/templates/nginx_unicorn.erb +17 -0
- data/lib/cmdeploy/recipes/templates/nginx_unicorn_upstream.erb +4 -0
- data/lib/cmdeploy/recipes/templates/unicorn_conf.erb +2 -0
- data/lib/cmdeploy/recipes/templates/unicorn_rb.erb +36 -0
- data/lib/cmdeploy/recipes/unicorn.rb +29 -0
- data/lib/cmdeploy/recipes/variables.rb +37 -0
- data/lib/cmdeploy/version.rb +3 -0
- data/lib/cmdeploy.rb +11 -0
- metadata +62 -0
data/bin/cmdeploy
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
def template(application,from,to)
|
7
|
+
erb = File.read("#{File.dirname(__FILE__)}/../lib/cmdeploy/recipes/templates/#{from}")
|
8
|
+
File.open(to,"w") do |output|
|
9
|
+
output.write(ERB.new(erb).result(binding))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
if ARGV.size == 0
|
14
|
+
# no arguments provided, show usage
|
15
|
+
puts "Usage of #{File.basename(__FILE__)}: bundle exec cmdeploy [-f] APPNAME"
|
16
|
+
puts " -f => force to overwrite existing files"
|
17
|
+
else
|
18
|
+
force = false
|
19
|
+
application = nil
|
20
|
+
|
21
|
+
ARGV.each do |arg|
|
22
|
+
case arg
|
23
|
+
when /-f/ then
|
24
|
+
force = true
|
25
|
+
else
|
26
|
+
application = application || arg
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# checking where we are...
|
31
|
+
puts "Installing templates #{"[force mode] " if force}for application [#{application}]..."
|
32
|
+
puts "Checking actual folder..."
|
33
|
+
%w(app app/controllers config).each do |folder|
|
34
|
+
unless File.exists?(folder) && File.directory?(folder)
|
35
|
+
puts "=> Could not find folder [#{folder}]. You need to be in a Ruby On Rails root folder"
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
list = []
|
41
|
+
list << ["deploy_rb.erb","config/deploy.rb"]
|
42
|
+
list << ["unicorn_rb.erb","config/unicorn.rb"]
|
43
|
+
|
44
|
+
list.each do |item|
|
45
|
+
from = item[0]
|
46
|
+
to = item[1]
|
47
|
+
|
48
|
+
puts "Processing [#{to}]..."
|
49
|
+
|
50
|
+
if File.exists?(to)
|
51
|
+
if force
|
52
|
+
puts "overwrite existing file"
|
53
|
+
else
|
54
|
+
puts "=> File [#{to}] exists. Please delete or use -f to overwrite."
|
55
|
+
exit 1
|
56
|
+
end
|
57
|
+
end
|
58
|
+
template(application,from,to)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CMDeploy
|
2
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
3
|
+
Capistrano::Configuration.instance(:must_exist) :
|
4
|
+
Capistrano.configuration(:must_exist)
|
5
|
+
|
6
|
+
configuration.load do
|
7
|
+
|
8
|
+
namespace :deploy do
|
9
|
+
namespace :assets do
|
10
|
+
desc "cm-deploy: Assets precompilation"
|
11
|
+
task :precompile do
|
12
|
+
run "cd #{release_path} && #{rake} RAILS_RELATIVE_URL_ROOT=/#{application} RAILS_ENV=#{stage} RAILS_GROUPS=assets assets:precompile"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CMDeploy
|
2
|
+
def set_default(name, *args, &block)
|
3
|
+
set(name, *args, &block) unless exists?(name)
|
4
|
+
end
|
5
|
+
|
6
|
+
def set_default_overwrite(name,pre_value,new_value,overwrite_pattern)
|
7
|
+
if pre_value =~ overwrite_pattern
|
8
|
+
set name, new_value
|
9
|
+
else
|
10
|
+
set_default(name,new_value)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def template(from, to)
|
15
|
+
erb = File.read("#{File.dirname(__FILE__)}/templates/#{from}")
|
16
|
+
put ERB.new(erb).result(binding), to
|
17
|
+
end
|
18
|
+
|
19
|
+
def local_template(from,to)
|
20
|
+
erb = File.read("#{File.dirname(__FILE__)}/templates/#{from}")
|
21
|
+
File.open(to,"w") do |output|
|
22
|
+
output.write(ERB.new(erb).result(binding))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module CMDeploy
|
2
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
3
|
+
Capistrano::Configuration.instance(:must_exist) :
|
4
|
+
Capistrano.configuration(:must_exist)
|
5
|
+
|
6
|
+
configuration.load do
|
7
|
+
|
8
|
+
namespace :deploy do
|
9
|
+
|
10
|
+
desc "cm-deploy: check and install gems via bunlder"
|
11
|
+
task :bundle_setup, roles: :app do
|
12
|
+
run ". ~/.bashrc && cd #{release_path} && (bundle check || bundle install --without development) && bundle install --binstubs"
|
13
|
+
end
|
14
|
+
after "deploy:assets:symlink", "deploy:bundle_setup"
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module CMDeploy
|
2
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
3
|
+
Capistrano::Configuration.instance(:must_exist) :
|
4
|
+
Capistrano.configuration(:must_exist)
|
5
|
+
|
6
|
+
configuration.load do
|
7
|
+
|
8
|
+
namespace :nginx do
|
9
|
+
desc "cm-deploy: setup nginx configuration for this application"
|
10
|
+
task :setup, roles: :web do
|
11
|
+
template("nginx_unicorn.erb","/tmp/nginx_unicorn")
|
12
|
+
run "mv /tmp/nginx_unicorn #{nginx_conf_folder}/#{application}.conf"
|
13
|
+
|
14
|
+
template("nginx_unicorn_upstream.erb","/tmp/nginx_unicorn_upstream")
|
15
|
+
run "mv /tmp/nginx_unicorn_upstream #{nginx_conf_folder}/upstream/#{application}.conf"
|
16
|
+
end
|
17
|
+
after "deploy:setup", "nginx:setup"
|
18
|
+
|
19
|
+
%w[start stop restart status reload configtest].each do |command|
|
20
|
+
desc "cm-deploy: #{command} nginx"
|
21
|
+
task command, roles: :web do
|
22
|
+
run "#{sudo} /sbin/service nginx #{command}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module CMDeploy
|
2
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
3
|
+
Capistrano::Configuration.instance(:must_exist) :
|
4
|
+
Capistrano.configuration(:must_exist)
|
5
|
+
|
6
|
+
configuration.load do
|
7
|
+
|
8
|
+
namespace :deploy do
|
9
|
+
|
10
|
+
desc "cm-deploy: copy password file from server"
|
11
|
+
task :copy_password_file, roles: :app do
|
12
|
+
begin
|
13
|
+
run "mkdir -p ~/.rails/#{application} && cp ~/.rails/#{application}/database.yml #{release_path}/config"
|
14
|
+
rescue
|
15
|
+
puts "\n\nCould not find server side password file. Please check ~/.rails/#{application}/database.yml"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
after "deploy:assets:symlink", "deploy:copy_password_file"
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module CMDeploy
|
2
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
3
|
+
Capistrano::Configuration.instance(:must_exist) :
|
4
|
+
Capistrano.configuration(:must_exist)
|
5
|
+
|
6
|
+
configuration.load do
|
7
|
+
|
8
|
+
namespace :deploy do
|
9
|
+
|
10
|
+
desc "cm_deploy: fetch revision history"
|
11
|
+
task :fetch_revision_history, roles: :app do
|
12
|
+
run "cd #{release_path} && svn log --xml #{release_path} > revision.xml"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
after "deploy:assets:precompile", "deploy:fetch_revision_history"
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
set :application, "<%= application %>"
|
3
|
+
require 'cmdeploy'
|
4
|
+
|
5
|
+
# default server for test
|
6
|
+
server "{full_qualified_test_server_name}", :web, :app, primary: true
|
7
|
+
|
8
|
+
task :production do
|
9
|
+
puts "production..."
|
10
|
+
set :stage, 'production'
|
11
|
+
server "{full_qualified_production_server_name}", :web, :app, primary: true
|
12
|
+
end
|
13
|
+
|
14
|
+
task :integration do
|
15
|
+
puts "integration..."
|
16
|
+
set :stage, 'integration'
|
17
|
+
server "{full_qualified_integration_server_name}", :web, :app, primary: true
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# deliver static assets as gzip files
|
2
|
+
location ~ ^/<%= application %>/assets/ {
|
3
|
+
root /CHBS/apps/apps/<%= application %>/current/public;
|
4
|
+
gzip_static on; # to serve pre-gzipped version
|
5
|
+
expires max;
|
6
|
+
add_header Cache-Control public;
|
7
|
+
}
|
8
|
+
|
9
|
+
# pass request to rails app
|
10
|
+
location ~ /<%= application %> {
|
11
|
+
root /CHBS/apps/apps/<%= application %>/current/public;
|
12
|
+
|
13
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
14
|
+
proxy_set_header Host $http_host;
|
15
|
+
proxy_redirect off;
|
16
|
+
proxy_pass http://unicorn_<%= application %>;
|
17
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
application_name = '<%= application %>'
|
2
|
+
application_path = "/CHBS/apps/apps/#{application_name}/current"
|
3
|
+
|
4
|
+
# path to the app
|
5
|
+
working_directory application_path
|
6
|
+
|
7
|
+
# pid file location
|
8
|
+
pid "#{application_path}/tmp/pids/unicorn.pid"
|
9
|
+
|
10
|
+
# log everthing to one file
|
11
|
+
stderr_path "#{application_path}/log/unicorn.log"
|
12
|
+
stdout_path "#{application_path}/log/unicorn.log"
|
13
|
+
|
14
|
+
# unicorn options
|
15
|
+
listen "/tmp/unicorn.#{application_name}.sock"
|
16
|
+
worker_processes 3
|
17
|
+
timeout 90
|
18
|
+
preload_app true
|
19
|
+
|
20
|
+
before_fork do |server, worker|
|
21
|
+
ActiveRecord::Base.connection.disconnect!
|
22
|
+
|
23
|
+
old_pid = "#{server.config[:pid]}.oldbin"
|
24
|
+
if File.exists?(old_pid) && server.pid != old_pid
|
25
|
+
begin
|
26
|
+
Process.kill("QUIT", File.read(old_pid).to_i)
|
27
|
+
rescue Errno::ENOENT, Errno::ESRCH
|
28
|
+
# someone else did our job for us
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
after_fork do |server, worker|
|
34
|
+
ActiveRecord::Base.establish_connection
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module CMDeploy
|
2
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
3
|
+
Capistrano::Configuration.instance(:must_exist) :
|
4
|
+
Capistrano.configuration(:must_exist)
|
5
|
+
|
6
|
+
configuration.load do
|
7
|
+
|
8
|
+
namespace :unicorn do
|
9
|
+
desc "cm-deploy: create unicorn startup script"
|
10
|
+
task :setup, roles: :app do
|
11
|
+
run "mkdir -p #{unicorn_conf_folder}"
|
12
|
+
template("unicorn_conf.erb","/tmp/unicorn_conf")
|
13
|
+
run "mv /tmp/unicorn_conf #{unicorn_conf_folder}/#{application}.conf"
|
14
|
+
end
|
15
|
+
after "deploy:setup", "unicorn:setup"
|
16
|
+
|
17
|
+
%w[start stop restart reload upgrade status rotate].each do |command|
|
18
|
+
desc "cm-deploy: #{command} unicorn"
|
19
|
+
task command, roles: :app do
|
20
|
+
run ". ~/.bashrc && uc #{command} ~/etc/unicorn/#{application}.conf"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
after "deploy:restart", "unicorn:reload"
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module CMDeploy
|
2
|
+
configuration = Capistrano::Configuration.respond_to?(:instance) ?
|
3
|
+
Capistrano::Configuration.instance(:must_exist) :
|
4
|
+
Capistrano.configuration(:must_exist)
|
5
|
+
|
6
|
+
configuration.load do
|
7
|
+
|
8
|
+
# cm specific settings
|
9
|
+
set :stage, 'test'
|
10
|
+
set :nginx_conf_folder,'~/opt/nginx/conf/sites/apps.cm' # nginx app configuration folder
|
11
|
+
set :unicorn_conf_folder, '~/etc/unicorn' # unicorn configuration folder
|
12
|
+
|
13
|
+
# deployment
|
14
|
+
set :user, 's_cme'
|
15
|
+
set :deploy_via, :remote_cache
|
16
|
+
|
17
|
+
set :deploy_to, "/CHBS/apps/apps/#{application}"
|
18
|
+
|
19
|
+
# scm
|
20
|
+
set :scm, :subversion
|
21
|
+
set :repository, "http://svn.nibr.novartis.intra/svn/SDM/cm/module/#{application}/branches/master/src/rails"
|
22
|
+
|
23
|
+
# sudo
|
24
|
+
set :use_sudo, false
|
25
|
+
|
26
|
+
# rake
|
27
|
+
set :rake, '. ~/.bashrc && bundle exec rake'
|
28
|
+
|
29
|
+
#create a pty for each process
|
30
|
+
default_run_options[:pty] = true
|
31
|
+
ssh_options[:forward_agent] = true
|
32
|
+
|
33
|
+
# per default only 5 release will be kept
|
34
|
+
after "deploy:assets:precompile", "deploy:cleanup"
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/cmdeploy.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "cmdeploy/version"
|
2
|
+
|
3
|
+
# provided recipes
|
4
|
+
require 'cmdeploy/recipes/base'
|
5
|
+
require 'cmdeploy/recipes/variables'
|
6
|
+
require 'cmdeploy/recipes/assets'
|
7
|
+
require 'cmdeploy/recipes/bundler'
|
8
|
+
require 'cmdeploy/recipes/revision_history'
|
9
|
+
require 'cmdeploy/recipes/password_file'
|
10
|
+
require 'cmdeploy/recipes/unicorn'
|
11
|
+
require 'cmdeploy/recipes/nginx'
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cmdeploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thomas Steiner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-15 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: CM specific deployment recipes
|
15
|
+
email:
|
16
|
+
- thomas.steiner@ikey.ch
|
17
|
+
executables:
|
18
|
+
- cmdeploy
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/cmdeploy/recipes/assets.rb
|
23
|
+
- lib/cmdeploy/recipes/base.rb
|
24
|
+
- lib/cmdeploy/recipes/bundler.rb
|
25
|
+
- lib/cmdeploy/recipes/nginx.rb
|
26
|
+
- lib/cmdeploy/recipes/password_file.rb
|
27
|
+
- lib/cmdeploy/recipes/revision_history.rb
|
28
|
+
- lib/cmdeploy/recipes/templates/deploy_rb.erb
|
29
|
+
- lib/cmdeploy/recipes/templates/nginx_unicorn.erb
|
30
|
+
- lib/cmdeploy/recipes/templates/nginx_unicorn_upstream.erb
|
31
|
+
- lib/cmdeploy/recipes/templates/unicorn_conf.erb
|
32
|
+
- lib/cmdeploy/recipes/templates/unicorn_rb.erb
|
33
|
+
- lib/cmdeploy/recipes/unicorn.rb
|
34
|
+
- lib/cmdeploy/recipes/variables.rb
|
35
|
+
- lib/cmdeploy/version.rb
|
36
|
+
- lib/cmdeploy.rb
|
37
|
+
- bin/cmdeploy
|
38
|
+
homepage: ''
|
39
|
+
licenses: []
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.8.24
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: CM specific deployment recipes
|
62
|
+
test_files: []
|