ms_deploy 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -0
- data/lib/examples/deploy.rb +110 -0
- data/lib/ms_deploy/recipes/bundler.rb +1 -1
- data/lib/ms_deploy/recipes/deploy/setup.rb +48 -16
- data/lib/ms_deploy/recipes/deploy/symlink.rb +0 -1
- data/lib/ms_deploy/recipes/{deploy/nginx.rb → nginx.rb} +3 -3
- data/lib/ms_deploy/{recipes/templates → templates}/ssl_vhost.erb +1 -1
- data/lib/ms_deploy/{recipes/templates → templates}/vhost.erb +1 -1
- data/lib/ms_deploy/version.rb +1 -1
- data/ms_deploy.gemspec +0 -2
- metadata +12 -12
- data/TODO +0 -3
- data/lib/ms_deploy/recipes/mysql.rb +0 -48
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
|
2
|
+
set :application, ''
|
3
|
+
set :domain, ''
|
4
|
+
set :server_domain, ''
|
5
|
+
|
6
|
+
set :user, 'deploy'
|
7
|
+
set :group, 'deploy'
|
8
|
+
|
9
|
+
set :ruby_version, "ruby-1.9.3.rc1"
|
10
|
+
set :rails_root, File.expand_path('../../', __FILE__)
|
11
|
+
|
12
|
+
set :default_environment, {
|
13
|
+
'PATH' => "/home/#{user}/.rbenv/shims:/home/#{user}/.rbenv/bin:$PATH"
|
14
|
+
}
|
15
|
+
|
16
|
+
set :rails_env, :production # use 'stage' to differ between stage environments
|
17
|
+
set :keep_releases, 10 # default
|
18
|
+
set :use_sudo, false
|
19
|
+
|
20
|
+
server domain, :web, :app, :db, :primary => true
|
21
|
+
|
22
|
+
set :branch do
|
23
|
+
ENV['BRANCH'] || 'xxx'
|
24
|
+
end
|
25
|
+
|
26
|
+
# Multistage settings
|
27
|
+
#set :stage_dir, File.dirname(__FILE__) + '/deploy/stages'
|
28
|
+
#set :default_stage, "vagrant"
|
29
|
+
#
|
30
|
+
#require 'capistrano/ext/multistage'
|
31
|
+
|
32
|
+
# database
|
33
|
+
set :db_name, ''
|
34
|
+
set :db_user_name, ''
|
35
|
+
set :db_user_password, ''
|
36
|
+
|
37
|
+
set :scm, :git
|
38
|
+
set :repository, '.git'
|
39
|
+
set :git_enable_submodules, 1
|
40
|
+
|
41
|
+
# set deployment strategy
|
42
|
+
set :deploy_via, :remote_cache
|
43
|
+
set :copy_exclude, %w(.git .svn .DS_Store test doc .gitkeep)
|
44
|
+
|
45
|
+
# :forward_agent allows us to avoid using and distributing a deploy key.
|
46
|
+
# On problems run 'ssh-add' locally
|
47
|
+
# In your /etc/ssh/ssh_config or ~/.ssh/config you need to have ForwardAgent enabled for this to work.
|
48
|
+
set :ssh_options, { :port => fetch(:ssh_port, 22), :forward_agent => true, :paranoid => true }
|
49
|
+
|
50
|
+
default_run_options[:pty] = true
|
51
|
+
|
52
|
+
# set application folder
|
53
|
+
set(:deploy_to) { "/var/projects/#{application}/#{fetch(:stage, 'production')}" }
|
54
|
+
|
55
|
+
require 'ms_deploy/recipes/nginx'
|
56
|
+
require 'ms_deploy/recipes/bundler'
|
57
|
+
require 'ms_deploy/recipes/deploy/symlink'
|
58
|
+
require 'ms_deploy/recipes/deploy/unicorn'
|
59
|
+
require 'ms_deploy/recipes/deploy/setup'
|
60
|
+
require 'ms_deploy/recipes/deploy/assets'
|
61
|
+
|
62
|
+
before 'deploy:setup', 'deploy:prepare:database';
|
63
|
+
after 'deploy:update", "deploy:cleanup'
|
64
|
+
|
65
|
+
set(:shared_directories_to_create) {
|
66
|
+
[
|
67
|
+
"#{shared_path}/vendor/bundle",
|
68
|
+
"#{shared_path}/vendor/cache",
|
69
|
+
"#{shared_path}/uploads"
|
70
|
+
]
|
71
|
+
}
|
72
|
+
|
73
|
+
set(:shared_directories_to_link) {
|
74
|
+
{
|
75
|
+
"#{shared_path}/bundle/" => "#{release_path}/vendor/bundle",
|
76
|
+
"#{shared_path}/solr/" => "#{release_path}/solr"
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
set(:directories_to_create) {
|
81
|
+
[
|
82
|
+
"#{release_path}/tmp",
|
83
|
+
"#{release_path}/vendor"
|
84
|
+
]
|
85
|
+
}
|
86
|
+
|
87
|
+
set(:files_to_link) {
|
88
|
+
{
|
89
|
+
"#{shared_path}/config/config.production.yml" => "#{release_path}/config/config.local.yml",
|
90
|
+
"#{shared_path}/config/unicorn.production.rb" => "#{release_path}/config/unicorn.production.rb"
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
set(:config_file_to_setup) {
|
95
|
+
[
|
96
|
+
"config.production.yml",
|
97
|
+
"unicorn.production.rb"
|
98
|
+
]
|
99
|
+
}
|
100
|
+
|
101
|
+
set(:files_to_delete) {
|
102
|
+
[
|
103
|
+
]
|
104
|
+
}
|
105
|
+
|
106
|
+
set(:chmods_to_set) {
|
107
|
+
{
|
108
|
+
# "#{shared_path}/data/pdf" => 755
|
109
|
+
}
|
110
|
+
}
|
@@ -17,7 +17,7 @@ Capistrano::Configuration.instance.load do
|
|
17
17
|
|
18
18
|
namespace :bundler do
|
19
19
|
task :install_gem do
|
20
|
-
run "cd #{
|
20
|
+
run "cd #{release_path} && gem install bundler --pre --no-ri --no-rdoc"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -2,14 +2,11 @@ Capistrano::Configuration.instance.load do
|
|
2
2
|
|
3
3
|
namespace :deploy do
|
4
4
|
namespace :prepare do
|
5
|
-
task :
|
5
|
+
task :create_config_files do
|
6
6
|
run "mkdir -p #{shared_path}/config/"
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
task :create_database_config do
|
11
|
-
run "mkdir -p #{shared_path}/config/"
|
12
|
-
put(File.read(database_config_file), "#{shared_path}/config/database.yml", :via => :scp)
|
7
|
+
config_file_to_setup.each do |config_file|
|
8
|
+
put(File.read(config_file_path(config_file)), "#{shared_path}/config/#{config_file}", :via => :scp)
|
9
|
+
end
|
13
10
|
end
|
14
11
|
|
15
12
|
desc "Set up shared directory structure"
|
@@ -17,21 +14,56 @@ Capistrano::Configuration.instance.load do
|
|
17
14
|
shared_directories_to_create.each { |directory| run "mkdir -p #{directory}" }
|
18
15
|
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
task :database do
|
18
|
+
set :db_admin_user, 'root' unless fetch(:db_admin_user, nil)
|
19
|
+
set :db_admin_password, Capistrano::CLI.password_prompt("Type your mysql password for user '#{db_admin_user}' (not set if empty): ") unless fetch(:db_admin_password, nil)
|
20
|
+
set :db_name, application.gsub(/\W+/, '')[0..5] + '_' + rails_env.to_s unless fetch(:db_name, nil)
|
21
|
+
set :db_user_name, application unless fetch(:db_user_name, nil)
|
22
|
+
set :db_user_password, '' unless fetch(:db_user_password, nil)
|
23
|
+
|
24
|
+
unless db_admin_password.to_s.empty?
|
25
|
+
unless database_exits?
|
26
|
+
create_database
|
27
|
+
end
|
28
|
+
setup_database_permissions
|
29
|
+
end
|
30
|
+
end
|
24
31
|
end
|
25
32
|
end
|
26
33
|
|
27
|
-
before :"deploy:setup", :"deploy:prepare:
|
28
|
-
before :"deploy:setup", :"deploy:prepare:create_database_config";
|
34
|
+
before :"deploy:setup", :"deploy:prepare:create_config_files";
|
29
35
|
before :"deploy:setup", :"deploy:prepare:create_shared_folders";
|
30
36
|
|
31
37
|
end
|
32
38
|
|
33
|
-
def
|
34
|
-
config_file = "#{rails_root}/config/#{
|
35
|
-
raise "No config file '#{config_file}'
|
39
|
+
def config_file_path(config_file_name)
|
40
|
+
config_file = "#{rails_root}/config/#{config_file_name}"
|
41
|
+
raise "No config file '#{config_file}'" unless File.exists? config_file
|
36
42
|
config_file
|
37
43
|
end
|
44
|
+
|
45
|
+
def database_exits?
|
46
|
+
exists = false
|
47
|
+
|
48
|
+
run "mysql --user=#{db_admin_user} --password=#{db_admin_password} --execute=\"show databases;\"" do |channel, stream, data|
|
49
|
+
exists = exists || data.include?(db_name)
|
50
|
+
end
|
51
|
+
|
52
|
+
exists
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_database
|
56
|
+
create_sql = <<-SQL
|
57
|
+
CREATE DATABASE #{db_name};
|
58
|
+
SQL
|
59
|
+
|
60
|
+
run "mysql --user=#{db_admin_user} --password=#{db_admin_password} --execute=\"#{create_sql}\""
|
61
|
+
end
|
62
|
+
|
63
|
+
def setup_database_permissions
|
64
|
+
grant_sql = <<-SQL
|
65
|
+
GRANT ALL PRIVILEGES ON #{db_name}.* TO #{db_user_name}@localhost IDENTIFIED BY '#{db_user_password}';
|
66
|
+
SQL
|
67
|
+
|
68
|
+
run "mysql --user=#{db_admin_user} --password=#{db_admin_password} --execute=\"#{grant_sql}\""
|
69
|
+
end
|
@@ -2,7 +2,7 @@ require "ms_deploy/render"
|
|
2
2
|
|
3
3
|
Capistrano::Configuration.instance.load do
|
4
4
|
|
5
|
-
namespace :
|
5
|
+
namespace :service do
|
6
6
|
namespace :nginx do
|
7
7
|
desc <<-DESC
|
8
8
|
Starts the nginx web-server.
|
@@ -30,7 +30,7 @@ Capistrano::Configuration.instance.load do
|
|
30
30
|
|
31
31
|
task :install do
|
32
32
|
template_path = File.expand_path('../../templates/vhost.erb', __FILE__)
|
33
|
-
vars = {'application'=> application, 'project_root' => deploy_to + '/current', '
|
33
|
+
vars = {'application'=> application, 'project_root' => deploy_to + '/current', 'domain' => domain}
|
34
34
|
config_path = "#{shared_path}/config/#{application}_vhost.conf"
|
35
35
|
|
36
36
|
put(render_erb_template(template_path, vars), config_path)
|
@@ -44,6 +44,6 @@ Capistrano::Configuration.instance.load do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
after :"deploy:setup", :"
|
47
|
+
after :"deploy:setup", :"service:nginx:install";
|
48
48
|
|
49
49
|
end
|
data/lib/ms_deploy/version.rb
CHANGED
data/ms_deploy.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ms_deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-02 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
16
|
-
requirement: &
|
16
|
+
requirement: &79221250 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *79221250
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: capistrano-ext
|
27
|
-
requirement: &
|
27
|
+
requirement: &79220690 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *79220690
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: erubis
|
38
|
-
requirement: &
|
38
|
+
requirement: &79220470 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *79220470
|
47
47
|
description: capistrano deployment task for my projects
|
48
48
|
email:
|
49
49
|
- michael.schiller@gmx.de
|
@@ -53,22 +53,22 @@ extra_rdoc_files: []
|
|
53
53
|
files:
|
54
54
|
- .gitignore
|
55
55
|
- Gemfile
|
56
|
+
- README.md
|
56
57
|
- Rakefile
|
57
|
-
-
|
58
|
+
- lib/examples/deploy.rb
|
58
59
|
- lib/ms_deploy.rb
|
59
60
|
- lib/ms_deploy/recipes/bundler.rb
|
60
61
|
- lib/ms_deploy/recipes/deploy/assets.rb
|
61
|
-
- lib/ms_deploy/recipes/deploy/nginx.rb
|
62
62
|
- lib/ms_deploy/recipes/deploy/setup.rb
|
63
63
|
- lib/ms_deploy/recipes/deploy/symlink.rb
|
64
64
|
- lib/ms_deploy/recipes/deploy/unicorn.rb
|
65
65
|
- lib/ms_deploy/recipes/info.rb
|
66
|
-
- lib/ms_deploy/recipes/
|
66
|
+
- lib/ms_deploy/recipes/nginx.rb
|
67
67
|
- lib/ms_deploy/recipes/redis.rb
|
68
|
-
- lib/ms_deploy/recipes/templates/ssl_vhost.erb
|
69
|
-
- lib/ms_deploy/recipes/templates/vhost.erb
|
70
68
|
- lib/ms_deploy/recipes/whenever.rb
|
71
69
|
- lib/ms_deploy/render.rb
|
70
|
+
- lib/ms_deploy/templates/ssl_vhost.erb
|
71
|
+
- lib/ms_deploy/templates/vhost.erb
|
72
72
|
- lib/ms_deploy/version.rb
|
73
73
|
- ms_deploy.gemspec
|
74
74
|
homepage: https://github.com/mschiller/ms_deploy
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
Capistrano::Configuration.instance.load do
|
4
|
-
|
5
|
-
namespace :deploy do
|
6
|
-
namespace :prepare do
|
7
|
-
task :database do
|
8
|
-
set :db_admin_user, 'root' unless fetch(:db_admin_user, nil)
|
9
|
-
set :db_admin_password, Capistrano::CLI.password_prompt("Type your mysql password for user '#{db_admin_user}': ") unless fetch(:db_admin_password, nil)
|
10
|
-
set :db_name, application.gsub(/\W+/, '')[0..5] + '_' + rails_env.to_s unless fetch(:db_name, nil)
|
11
|
-
set :db_user_name, 'root' unless fetch(:db_user_name, nil)
|
12
|
-
set :db_user_password, '' unless fetch(:db_user_password, nil)
|
13
|
-
|
14
|
-
unless database_exits?
|
15
|
-
create_database
|
16
|
-
end
|
17
|
-
setup_database_permissions
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def database_exits?
|
23
|
-
exists = false
|
24
|
-
|
25
|
-
run "mysql --user=#{db_admin_user} --password=#{db_admin_password} --execute=\"show databases;\"" do |channel, stream, data|
|
26
|
-
exists = exists || data.include?(db_name)
|
27
|
-
end
|
28
|
-
|
29
|
-
exists
|
30
|
-
end
|
31
|
-
|
32
|
-
def create_database
|
33
|
-
create_sql = <<-SQL
|
34
|
-
CREATE DATABASE #{db_name};
|
35
|
-
SQL
|
36
|
-
|
37
|
-
run "mysql --user=#{db_admin_user} --password=#{db_admin_password} --execute=\"#{create_sql}\""
|
38
|
-
end
|
39
|
-
|
40
|
-
def setup_database_permissions
|
41
|
-
grant_sql = <<-SQL
|
42
|
-
GRANT ALL PRIVILEGES ON #{db_name}.* TO #{db_user_name}@localhost IDENTIFIED BY '#{db_user_password}';
|
43
|
-
SQL
|
44
|
-
|
45
|
-
run "mysql --user=#{db_admin_user} --password=#{db_admin_password} --execute=\"#{grant_sql}\""
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|