capistrano-exts 1.0.1 → 1.1.0
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/README.md +2 -2
- data/examples/php_fpm/deploy/development.rb +35 -3
- data/examples/php_fpm/deploy/production.rb +35 -3
- data/examples/php_fpm/deploy/staging.rb +35 -3
- data/examples/rails_passenger/deploy/development.rb +35 -3
- data/examples/rails_passenger/deploy/production.rb +35 -3
- data/examples/rails_passenger/deploy/staging.rb +35 -3
- data/examples/rails_reverse_proxy/deploy/development.rb +36 -4
- data/examples/rails_reverse_proxy/deploy/production.rb +36 -4
- data/examples/rails_reverse_proxy/deploy/staging.rb +36 -4
- data/lib/capistrano-exts/receipts/contao.rb +3 -1
- data/lib/capistrano-exts/receipts/deploy.rb +1 -1
- data/lib/capistrano-exts/receipts/functions.rb +22 -3
- data/lib/capistrano-exts/receipts/mysql.rb +98 -12
- data/lib/capistrano-exts/receipts/servers/db_server.rb +12 -2
- data/lib/capistrano-exts/receipts/servers/web_server.rb +10 -9
- data/lib/capistrano-exts/receipts/servers.rb +5 -5
- data/lib/capistrano-exts/servers/web_server/nginx.rb +1 -1
- data/lib/capistrano-exts/servers/web_server.rb +1 -1
- data/lib/capistrano-exts/templates/multistage.rb +36 -7
- data/lib/capistrano-exts/version.rb +2 -2
- data/spec/requests/nginx_spec.rb +1 -1
- data/spec/servers/web_server/nginx_spec.rb +4 -4
- metadata +21 -21
data/README.md
CHANGED
@@ -11,13 +11,13 @@ Installation
|
|
11
11
|
Install the gem
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
gem install capistrano-
|
14
|
+
gem install capistrano-exts
|
15
15
|
```
|
16
16
|
|
17
17
|
or add it to your Gemfile
|
18
18
|
|
19
19
|
```ruby
|
20
|
-
gem 'capistrano-
|
20
|
+
gem 'capistrano-exts', '>=1.0.0'
|
21
21
|
```
|
22
22
|
|
23
23
|
Setup
|
@@ -8,6 +8,12 @@ role :web, 'root@example_dev_web.com:22'
|
|
8
8
|
role :app, 'root@example_dev_app.com:22'
|
9
9
|
role :db, 'root@example_dev_db.com:22', primary: true
|
10
10
|
|
11
|
+
# Permissions and ownership
|
12
|
+
# Uncomment if necessary...
|
13
|
+
# set :app_owner, 'www-data'
|
14
|
+
# set :app_group, 'www-data'
|
15
|
+
# set :group_writable, true
|
16
|
+
|
11
17
|
# The project's branch to use
|
12
18
|
# Uncomment and edit this if you're using git, for other SCM's please refer
|
13
19
|
# to capistrano's documentation
|
@@ -28,19 +34,45 @@ set :keep_releases, 5
|
|
28
34
|
# Using RVM? Set this to the ruby version/gemset to use
|
29
35
|
set :rvm_ruby_string, "1.9.2"
|
30
36
|
|
31
|
-
|
37
|
+
#############
|
38
|
+
# Mysql
|
39
|
+
#
|
40
|
+
|
41
|
+
# What is the database name for this project/stage ?
|
42
|
+
set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
|
43
|
+
|
44
|
+
# What is the database user ?
|
45
|
+
# NOTE: This is only used if you run deploy:server:prepare which calls mysql:create_db_user
|
46
|
+
set :mysql_db_user, -> { "#{fetch :application}" }
|
47
|
+
|
48
|
+
# Where the database credentials are stored on the server ?
|
32
49
|
set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
|
50
|
+
|
51
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
33
52
|
set :mysql_credentials_host_regex, /hostname: (.*)$/o
|
34
53
|
set :mysql_credentials_host_regex_match, 1
|
54
|
+
|
55
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
35
56
|
set :mysql_credentials_user_regex, /username: (.*)$/o
|
36
57
|
set :mysql_credentials_user_regex_match, 1
|
58
|
+
|
59
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
37
60
|
set :mysql_credentials_pass_regex, /password: (.*)$/o
|
38
61
|
set :mysql_credentials_pass_regex_match, 1
|
62
|
+
|
63
|
+
# Where can we find root credentials ?
|
64
|
+
# NOTE: These options are only used if you run deploy:server:prepare which calls mysql:create_db_user
|
39
65
|
set :mysql_root_credentials_file, "/root/.mysql_password"
|
66
|
+
|
67
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
40
68
|
set :mysql_root_credentials_host_regex, /hostname: (.*)$/o
|
41
69
|
set :mysql_root_credentials_host_regex_match, 1
|
70
|
+
|
71
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
42
72
|
set :mysql_root_credentials_user_regex, /username: (.*)$/o
|
43
73
|
set :mysql_root_credentials_user_regex_match, 1
|
74
|
+
|
75
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
44
76
|
set :mysql_root_credentials_pass_regex, /password: (.*)$/o
|
45
77
|
set :mysql_root_credentials_pass_regex_match, 1
|
46
78
|
|
@@ -92,8 +124,8 @@ set :web_server_mod_rewrite, true
|
|
92
124
|
# Valid options:
|
93
125
|
#
|
94
126
|
# For Nginx:
|
95
|
-
# => :
|
96
|
-
# => :
|
127
|
+
# => :reverse_proxy, :passenger, :php_fpm
|
128
|
+
# => :reverse_proxy is used for unicorn (Rack apps)
|
97
129
|
# => :passenger runs rails apps
|
98
130
|
# => :php_fpm is used to deliver websites written using PHP
|
99
131
|
#
|
@@ -8,6 +8,12 @@ role :web, 'root@example_prod_web.com:22'
|
|
8
8
|
role :app, 'root@example_prod_app.com:22'
|
9
9
|
role :db, 'root@example_prod_db.com:22', primary: true
|
10
10
|
|
11
|
+
# Permissions and ownership
|
12
|
+
# Uncomment if necessary...
|
13
|
+
# set :app_owner, 'www-data'
|
14
|
+
# set :app_group, 'www-data'
|
15
|
+
# set :group_writable, true
|
16
|
+
|
11
17
|
# The project's branch to use
|
12
18
|
# Uncomment and edit this if you're using git, for other SCM's please refer
|
13
19
|
# to capistrano's documentation
|
@@ -28,19 +34,45 @@ set :keep_releases, 5
|
|
28
34
|
# Using RVM? Set this to the ruby version/gemset to use
|
29
35
|
set :rvm_ruby_string, "1.9.2"
|
30
36
|
|
31
|
-
|
37
|
+
#############
|
38
|
+
# Mysql
|
39
|
+
#
|
40
|
+
|
41
|
+
# What is the database name for this project/stage ?
|
42
|
+
set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
|
43
|
+
|
44
|
+
# What is the database user ?
|
45
|
+
# NOTE: This is only used if you run deploy:server:prepare which calls mysql:create_db_user
|
46
|
+
set :mysql_db_user, -> { "#{fetch :application}" }
|
47
|
+
|
48
|
+
# Where the database credentials are stored on the server ?
|
32
49
|
set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
|
50
|
+
|
51
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
33
52
|
set :mysql_credentials_host_regex, /hostname: (.*)$/o
|
34
53
|
set :mysql_credentials_host_regex_match, 1
|
54
|
+
|
55
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
35
56
|
set :mysql_credentials_user_regex, /username: (.*)$/o
|
36
57
|
set :mysql_credentials_user_regex_match, 1
|
58
|
+
|
59
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
37
60
|
set :mysql_credentials_pass_regex, /password: (.*)$/o
|
38
61
|
set :mysql_credentials_pass_regex_match, 1
|
62
|
+
|
63
|
+
# Where can we find root credentials ?
|
64
|
+
# NOTE: These options are only used if you run deploy:server:prepare which calls mysql:create_db_user
|
39
65
|
set :mysql_root_credentials_file, "/root/.mysql_password"
|
66
|
+
|
67
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
40
68
|
set :mysql_root_credentials_host_regex, /hostname: (.*)$/o
|
41
69
|
set :mysql_root_credentials_host_regex_match, 1
|
70
|
+
|
71
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
42
72
|
set :mysql_root_credentials_user_regex, /username: (.*)$/o
|
43
73
|
set :mysql_root_credentials_user_regex_match, 1
|
74
|
+
|
75
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
44
76
|
set :mysql_root_credentials_pass_regex, /password: (.*)$/o
|
45
77
|
set :mysql_root_credentials_pass_regex_match, 1
|
46
78
|
|
@@ -92,8 +124,8 @@ set :web_server_mod_rewrite, true
|
|
92
124
|
# Valid options:
|
93
125
|
#
|
94
126
|
# For Nginx:
|
95
|
-
# => :
|
96
|
-
# => :
|
127
|
+
# => :reverse_proxy, :passenger, :php_fpm
|
128
|
+
# => :reverse_proxy is used for unicorn (Rack apps)
|
97
129
|
# => :passenger runs rails apps
|
98
130
|
# => :php_fpm is used to deliver websites written using PHP
|
99
131
|
#
|
@@ -8,6 +8,12 @@ role :web, 'root@example_staging_web.com:22'
|
|
8
8
|
role :app, 'root@example_staging_app.com:22'
|
9
9
|
role :db, 'root@example_staging_db.com:22', primary: true
|
10
10
|
|
11
|
+
# Permissions and ownership
|
12
|
+
# Uncomment if necessary...
|
13
|
+
# set :app_owner, 'www-data'
|
14
|
+
# set :app_group, 'www-data'
|
15
|
+
# set :group_writable, true
|
16
|
+
|
11
17
|
# The project's branch to use
|
12
18
|
# Uncomment and edit this if you're using git, for other SCM's please refer
|
13
19
|
# to capistrano's documentation
|
@@ -28,19 +34,45 @@ set :keep_releases, 5
|
|
28
34
|
# Using RVM? Set this to the ruby version/gemset to use
|
29
35
|
set :rvm_ruby_string, "1.9.2"
|
30
36
|
|
31
|
-
|
37
|
+
#############
|
38
|
+
# Mysql
|
39
|
+
#
|
40
|
+
|
41
|
+
# What is the database name for this project/stage ?
|
42
|
+
set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
|
43
|
+
|
44
|
+
# What is the database user ?
|
45
|
+
# NOTE: This is only used if you run deploy:server:prepare which calls mysql:create_db_user
|
46
|
+
set :mysql_db_user, -> { "#{fetch :application}" }
|
47
|
+
|
48
|
+
# Where the database credentials are stored on the server ?
|
32
49
|
set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
|
50
|
+
|
51
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
33
52
|
set :mysql_credentials_host_regex, /hostname: (.*)$/o
|
34
53
|
set :mysql_credentials_host_regex_match, 1
|
54
|
+
|
55
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
35
56
|
set :mysql_credentials_user_regex, /username: (.*)$/o
|
36
57
|
set :mysql_credentials_user_regex_match, 1
|
58
|
+
|
59
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
37
60
|
set :mysql_credentials_pass_regex, /password: (.*)$/o
|
38
61
|
set :mysql_credentials_pass_regex_match, 1
|
62
|
+
|
63
|
+
# Where can we find root credentials ?
|
64
|
+
# NOTE: These options are only used if you run deploy:server:prepare which calls mysql:create_db_user
|
39
65
|
set :mysql_root_credentials_file, "/root/.mysql_password"
|
66
|
+
|
67
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
40
68
|
set :mysql_root_credentials_host_regex, /hostname: (.*)$/o
|
41
69
|
set :mysql_root_credentials_host_regex_match, 1
|
70
|
+
|
71
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
42
72
|
set :mysql_root_credentials_user_regex, /username: (.*)$/o
|
43
73
|
set :mysql_root_credentials_user_regex_match, 1
|
74
|
+
|
75
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
44
76
|
set :mysql_root_credentials_pass_regex, /password: (.*)$/o
|
45
77
|
set :mysql_root_credentials_pass_regex_match, 1
|
46
78
|
|
@@ -92,8 +124,8 @@ set :web_server_mod_rewrite, true
|
|
92
124
|
# Valid options:
|
93
125
|
#
|
94
126
|
# For Nginx:
|
95
|
-
# => :
|
96
|
-
# => :
|
127
|
+
# => :reverse_proxy, :passenger, :php_fpm
|
128
|
+
# => :reverse_proxy is used for unicorn (Rack apps)
|
97
129
|
# => :passenger runs rails apps
|
98
130
|
# => :php_fpm is used to deliver websites written using PHP
|
99
131
|
#
|
@@ -8,6 +8,12 @@ role :web, 'root@example_dev_web.com:22'
|
|
8
8
|
role :app, 'root@example_dev_app.com:22'
|
9
9
|
role :db, 'root@example_dev_db.com:22', primary: true
|
10
10
|
|
11
|
+
# Permissions and ownership
|
12
|
+
# Uncomment if necessary...
|
13
|
+
# set :app_owner, 'www-data'
|
14
|
+
# set :app_group, 'www-data'
|
15
|
+
# set :group_writable, true
|
16
|
+
|
11
17
|
# The project's branch to use
|
12
18
|
# Uncomment and edit this if you're using git, for other SCM's please refer
|
13
19
|
# to capistrano's documentation
|
@@ -28,19 +34,45 @@ set :keep_releases, 5
|
|
28
34
|
# Using RVM? Set this to the ruby version/gemset to use
|
29
35
|
set :rvm_ruby_string, "1.9.2"
|
30
36
|
|
31
|
-
|
37
|
+
#############
|
38
|
+
# Mysql
|
39
|
+
#
|
40
|
+
|
41
|
+
# What is the database name for this project/stage ?
|
42
|
+
set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
|
43
|
+
|
44
|
+
# What is the database user ?
|
45
|
+
# NOTE: This is only used if you run deploy:server:prepare which calls mysql:create_db_user
|
46
|
+
set :mysql_db_user, -> { "#{fetch :application}" }
|
47
|
+
|
48
|
+
# Where the database credentials are stored on the server ?
|
32
49
|
set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
|
50
|
+
|
51
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
33
52
|
set :mysql_credentials_host_regex, /hostname: (.*)$/o
|
34
53
|
set :mysql_credentials_host_regex_match, 1
|
54
|
+
|
55
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
35
56
|
set :mysql_credentials_user_regex, /username: (.*)$/o
|
36
57
|
set :mysql_credentials_user_regex_match, 1
|
58
|
+
|
59
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
37
60
|
set :mysql_credentials_pass_regex, /password: (.*)$/o
|
38
61
|
set :mysql_credentials_pass_regex_match, 1
|
62
|
+
|
63
|
+
# Where can we find root credentials ?
|
64
|
+
# NOTE: These options are only used if you run deploy:server:prepare which calls mysql:create_db_user
|
39
65
|
set :mysql_root_credentials_file, "/root/.mysql_password"
|
66
|
+
|
67
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
40
68
|
set :mysql_root_credentials_host_regex, /hostname: (.*)$/o
|
41
69
|
set :mysql_root_credentials_host_regex_match, 1
|
70
|
+
|
71
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
42
72
|
set :mysql_root_credentials_user_regex, /username: (.*)$/o
|
43
73
|
set :mysql_root_credentials_user_regex_match, 1
|
74
|
+
|
75
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
44
76
|
set :mysql_root_credentials_pass_regex, /password: (.*)$/o
|
45
77
|
set :mysql_root_credentials_pass_regex_match, 1
|
46
78
|
|
@@ -92,8 +124,8 @@ set :web_server_mod_rewrite, true
|
|
92
124
|
# Valid options:
|
93
125
|
#
|
94
126
|
# For Nginx:
|
95
|
-
# => :
|
96
|
-
# => :
|
127
|
+
# => :reverse_proxy, :passenger, :php_fpm
|
128
|
+
# => :reverse_proxy is used for unicorn (Rack apps)
|
97
129
|
# => :passenger runs rails apps
|
98
130
|
# => :php_fpm is used to deliver websites written using PHP
|
99
131
|
#
|
@@ -8,6 +8,12 @@ role :web, 'root@example_prod_web.com:22'
|
|
8
8
|
role :app, 'root@example_prod_app.com:22'
|
9
9
|
role :db, 'root@example_prod_db.com:22', primary: true
|
10
10
|
|
11
|
+
# Permissions and ownership
|
12
|
+
# Uncomment if necessary...
|
13
|
+
# set :app_owner, 'www-data'
|
14
|
+
# set :app_group, 'www-data'
|
15
|
+
# set :group_writable, true
|
16
|
+
|
11
17
|
# The project's branch to use
|
12
18
|
# Uncomment and edit this if you're using git, for other SCM's please refer
|
13
19
|
# to capistrano's documentation
|
@@ -28,19 +34,45 @@ set :keep_releases, 5
|
|
28
34
|
# Using RVM? Set this to the ruby version/gemset to use
|
29
35
|
set :rvm_ruby_string, "1.9.2"
|
30
36
|
|
31
|
-
|
37
|
+
#############
|
38
|
+
# Mysql
|
39
|
+
#
|
40
|
+
|
41
|
+
# What is the database name for this project/stage ?
|
42
|
+
set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
|
43
|
+
|
44
|
+
# What is the database user ?
|
45
|
+
# NOTE: This is only used if you run deploy:server:prepare which calls mysql:create_db_user
|
46
|
+
set :mysql_db_user, -> { "#{fetch :application}" }
|
47
|
+
|
48
|
+
# Where the database credentials are stored on the server ?
|
32
49
|
set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
|
50
|
+
|
51
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
33
52
|
set :mysql_credentials_host_regex, /hostname: (.*)$/o
|
34
53
|
set :mysql_credentials_host_regex_match, 1
|
54
|
+
|
55
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
35
56
|
set :mysql_credentials_user_regex, /username: (.*)$/o
|
36
57
|
set :mysql_credentials_user_regex_match, 1
|
58
|
+
|
59
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
37
60
|
set :mysql_credentials_pass_regex, /password: (.*)$/o
|
38
61
|
set :mysql_credentials_pass_regex_match, 1
|
62
|
+
|
63
|
+
# Where can we find root credentials ?
|
64
|
+
# NOTE: These options are only used if you run deploy:server:prepare which calls mysql:create_db_user
|
39
65
|
set :mysql_root_credentials_file, "/root/.mysql_password"
|
66
|
+
|
67
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
40
68
|
set :mysql_root_credentials_host_regex, /hostname: (.*)$/o
|
41
69
|
set :mysql_root_credentials_host_regex_match, 1
|
70
|
+
|
71
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
42
72
|
set :mysql_root_credentials_user_regex, /username: (.*)$/o
|
43
73
|
set :mysql_root_credentials_user_regex_match, 1
|
74
|
+
|
75
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
44
76
|
set :mysql_root_credentials_pass_regex, /password: (.*)$/o
|
45
77
|
set :mysql_root_credentials_pass_regex_match, 1
|
46
78
|
|
@@ -92,8 +124,8 @@ set :web_server_mod_rewrite, true
|
|
92
124
|
# Valid options:
|
93
125
|
#
|
94
126
|
# For Nginx:
|
95
|
-
# => :
|
96
|
-
# => :
|
127
|
+
# => :reverse_proxy, :passenger, :php_fpm
|
128
|
+
# => :reverse_proxy is used for unicorn (Rack apps)
|
97
129
|
# => :passenger runs rails apps
|
98
130
|
# => :php_fpm is used to deliver websites written using PHP
|
99
131
|
#
|
@@ -8,6 +8,12 @@ role :web, 'root@example_staging_web.com:22'
|
|
8
8
|
role :app, 'root@example_staging_app.com:22'
|
9
9
|
role :db, 'root@example_staging_db.com:22', primary: true
|
10
10
|
|
11
|
+
# Permissions and ownership
|
12
|
+
# Uncomment if necessary...
|
13
|
+
# set :app_owner, 'www-data'
|
14
|
+
# set :app_group, 'www-data'
|
15
|
+
# set :group_writable, true
|
16
|
+
|
11
17
|
# The project's branch to use
|
12
18
|
# Uncomment and edit this if you're using git, for other SCM's please refer
|
13
19
|
# to capistrano's documentation
|
@@ -28,19 +34,45 @@ set :keep_releases, 5
|
|
28
34
|
# Using RVM? Set this to the ruby version/gemset to use
|
29
35
|
set :rvm_ruby_string, "1.9.2"
|
30
36
|
|
31
|
-
|
37
|
+
#############
|
38
|
+
# Mysql
|
39
|
+
#
|
40
|
+
|
41
|
+
# What is the database name for this project/stage ?
|
42
|
+
set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
|
43
|
+
|
44
|
+
# What is the database user ?
|
45
|
+
# NOTE: This is only used if you run deploy:server:prepare which calls mysql:create_db_user
|
46
|
+
set :mysql_db_user, -> { "#{fetch :application}" }
|
47
|
+
|
48
|
+
# Where the database credentials are stored on the server ?
|
32
49
|
set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
|
50
|
+
|
51
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
33
52
|
set :mysql_credentials_host_regex, /hostname: (.*)$/o
|
34
53
|
set :mysql_credentials_host_regex_match, 1
|
54
|
+
|
55
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
35
56
|
set :mysql_credentials_user_regex, /username: (.*)$/o
|
36
57
|
set :mysql_credentials_user_regex_match, 1
|
58
|
+
|
59
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
37
60
|
set :mysql_credentials_pass_regex, /password: (.*)$/o
|
38
61
|
set :mysql_credentials_pass_regex_match, 1
|
62
|
+
|
63
|
+
# Where can we find root credentials ?
|
64
|
+
# NOTE: These options are only used if you run deploy:server:prepare which calls mysql:create_db_user
|
39
65
|
set :mysql_root_credentials_file, "/root/.mysql_password"
|
66
|
+
|
67
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
40
68
|
set :mysql_root_credentials_host_regex, /hostname: (.*)$/o
|
41
69
|
set :mysql_root_credentials_host_regex_match, 1
|
70
|
+
|
71
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
42
72
|
set :mysql_root_credentials_user_regex, /username: (.*)$/o
|
43
73
|
set :mysql_root_credentials_user_regex_match, 1
|
74
|
+
|
75
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
44
76
|
set :mysql_root_credentials_pass_regex, /password: (.*)$/o
|
45
77
|
set :mysql_root_credentials_pass_regex_match, 1
|
46
78
|
|
@@ -92,8 +124,8 @@ set :web_server_mod_rewrite, true
|
|
92
124
|
# Valid options:
|
93
125
|
#
|
94
126
|
# For Nginx:
|
95
|
-
# => :
|
96
|
-
# => :
|
127
|
+
# => :reverse_proxy, :passenger, :php_fpm
|
128
|
+
# => :reverse_proxy is used for unicorn (Rack apps)
|
97
129
|
# => :passenger runs rails apps
|
98
130
|
# => :php_fpm is used to deliver websites written using PHP
|
99
131
|
#
|
@@ -8,6 +8,12 @@ role :web, 'root@example_dev_web.com:22'
|
|
8
8
|
role :app, 'root@example_dev_app.com:22'
|
9
9
|
role :db, 'root@example_dev_db.com:22', primary: true
|
10
10
|
|
11
|
+
# Permissions and ownership
|
12
|
+
# Uncomment if necessary...
|
13
|
+
# set :app_owner, 'www-data'
|
14
|
+
# set :app_group, 'www-data'
|
15
|
+
# set :group_writable, true
|
16
|
+
|
11
17
|
# The project's branch to use
|
12
18
|
# Uncomment and edit this if you're using git, for other SCM's please refer
|
13
19
|
# to capistrano's documentation
|
@@ -28,19 +34,45 @@ set :keep_releases, 5
|
|
28
34
|
# Using RVM? Set this to the ruby version/gemset to use
|
29
35
|
set :rvm_ruby_string, "1.9.2"
|
30
36
|
|
31
|
-
|
37
|
+
#############
|
38
|
+
# Mysql
|
39
|
+
#
|
40
|
+
|
41
|
+
# What is the database name for this project/stage ?
|
42
|
+
set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
|
43
|
+
|
44
|
+
# What is the database user ?
|
45
|
+
# NOTE: This is only used if you run deploy:server:prepare which calls mysql:create_db_user
|
46
|
+
set :mysql_db_user, -> { "#{fetch :application}" }
|
47
|
+
|
48
|
+
# Where the database credentials are stored on the server ?
|
32
49
|
set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
|
50
|
+
|
51
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
33
52
|
set :mysql_credentials_host_regex, /hostname: (.*)$/o
|
34
53
|
set :mysql_credentials_host_regex_match, 1
|
54
|
+
|
55
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
35
56
|
set :mysql_credentials_user_regex, /username: (.*)$/o
|
36
57
|
set :mysql_credentials_user_regex_match, 1
|
58
|
+
|
59
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
37
60
|
set :mysql_credentials_pass_regex, /password: (.*)$/o
|
38
61
|
set :mysql_credentials_pass_regex_match, 1
|
62
|
+
|
63
|
+
# Where can we find root credentials ?
|
64
|
+
# NOTE: These options are only used if you run deploy:server:prepare which calls mysql:create_db_user
|
39
65
|
set :mysql_root_credentials_file, "/root/.mysql_password"
|
66
|
+
|
67
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
40
68
|
set :mysql_root_credentials_host_regex, /hostname: (.*)$/o
|
41
69
|
set :mysql_root_credentials_host_regex_match, 1
|
70
|
+
|
71
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
42
72
|
set :mysql_root_credentials_user_regex, /username: (.*)$/o
|
43
73
|
set :mysql_root_credentials_user_regex_match, 1
|
74
|
+
|
75
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
44
76
|
set :mysql_root_credentials_pass_regex, /password: (.*)$/o
|
45
77
|
set :mysql_root_credentials_pass_regex_match, 1
|
46
78
|
|
@@ -92,14 +124,14 @@ set :web_server_mod_rewrite, true
|
|
92
124
|
# Valid options:
|
93
125
|
#
|
94
126
|
# For Nginx:
|
95
|
-
# => :
|
96
|
-
# => :
|
127
|
+
# => :reverse_proxy, :passenger, :php_fpm
|
128
|
+
# => :reverse_proxy is used for unicorn (Rack apps)
|
97
129
|
# => :passenger runs rails apps
|
98
130
|
# => :php_fpm is used to deliver websites written using PHP
|
99
131
|
#
|
100
132
|
# For Apache
|
101
133
|
# =>
|
102
|
-
set :web_server_mode, :
|
134
|
+
set :web_server_mode, :reverse_proxy
|
103
135
|
|
104
136
|
# Server mode specific configurations
|
105
137
|
# Uncomment and edit the one depending on the enabled mode
|
@@ -8,6 +8,12 @@ role :web, 'root@example_prod_web.com:22'
|
|
8
8
|
role :app, 'root@example_prod_app.com:22'
|
9
9
|
role :db, 'root@example_prod_db.com:22', primary: true
|
10
10
|
|
11
|
+
# Permissions and ownership
|
12
|
+
# Uncomment if necessary...
|
13
|
+
# set :app_owner, 'www-data'
|
14
|
+
# set :app_group, 'www-data'
|
15
|
+
# set :group_writable, true
|
16
|
+
|
11
17
|
# The project's branch to use
|
12
18
|
# Uncomment and edit this if you're using git, for other SCM's please refer
|
13
19
|
# to capistrano's documentation
|
@@ -28,19 +34,45 @@ set :keep_releases, 5
|
|
28
34
|
# Using RVM? Set this to the ruby version/gemset to use
|
29
35
|
set :rvm_ruby_string, "1.9.2"
|
30
36
|
|
31
|
-
|
37
|
+
#############
|
38
|
+
# Mysql
|
39
|
+
#
|
40
|
+
|
41
|
+
# What is the database name for this project/stage ?
|
42
|
+
set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
|
43
|
+
|
44
|
+
# What is the database user ?
|
45
|
+
# NOTE: This is only used if you run deploy:server:prepare which calls mysql:create_db_user
|
46
|
+
set :mysql_db_user, -> { "#{fetch :application}" }
|
47
|
+
|
48
|
+
# Where the database credentials are stored on the server ?
|
32
49
|
set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
|
50
|
+
|
51
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
33
52
|
set :mysql_credentials_host_regex, /hostname: (.*)$/o
|
34
53
|
set :mysql_credentials_host_regex_match, 1
|
54
|
+
|
55
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
35
56
|
set :mysql_credentials_user_regex, /username: (.*)$/o
|
36
57
|
set :mysql_credentials_user_regex_match, 1
|
58
|
+
|
59
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
37
60
|
set :mysql_credentials_pass_regex, /password: (.*)$/o
|
38
61
|
set :mysql_credentials_pass_regex_match, 1
|
62
|
+
|
63
|
+
# Where can we find root credentials ?
|
64
|
+
# NOTE: These options are only used if you run deploy:server:prepare which calls mysql:create_db_user
|
39
65
|
set :mysql_root_credentials_file, "/root/.mysql_password"
|
66
|
+
|
67
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
40
68
|
set :mysql_root_credentials_host_regex, /hostname: (.*)$/o
|
41
69
|
set :mysql_root_credentials_host_regex_match, 1
|
70
|
+
|
71
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
42
72
|
set :mysql_root_credentials_user_regex, /username: (.*)$/o
|
43
73
|
set :mysql_root_credentials_user_regex_match, 1
|
74
|
+
|
75
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
44
76
|
set :mysql_root_credentials_pass_regex, /password: (.*)$/o
|
45
77
|
set :mysql_root_credentials_pass_regex_match, 1
|
46
78
|
|
@@ -92,14 +124,14 @@ set :web_server_mod_rewrite, true
|
|
92
124
|
# Valid options:
|
93
125
|
#
|
94
126
|
# For Nginx:
|
95
|
-
# => :
|
96
|
-
# => :
|
127
|
+
# => :reverse_proxy, :passenger, :php_fpm
|
128
|
+
# => :reverse_proxy is used for unicorn (Rack apps)
|
97
129
|
# => :passenger runs rails apps
|
98
130
|
# => :php_fpm is used to deliver websites written using PHP
|
99
131
|
#
|
100
132
|
# For Apache
|
101
133
|
# =>
|
102
|
-
set :web_server_mode, :
|
134
|
+
set :web_server_mode, :reverse_proxy
|
103
135
|
|
104
136
|
# Server mode specific configurations
|
105
137
|
# Uncomment and edit the one depending on the enabled mode
|
@@ -8,6 +8,12 @@ role :web, 'root@example_staging_web.com:22'
|
|
8
8
|
role :app, 'root@example_staging_app.com:22'
|
9
9
|
role :db, 'root@example_staging_db.com:22', primary: true
|
10
10
|
|
11
|
+
# Permissions and ownership
|
12
|
+
# Uncomment if necessary...
|
13
|
+
# set :app_owner, 'www-data'
|
14
|
+
# set :app_group, 'www-data'
|
15
|
+
# set :group_writable, true
|
16
|
+
|
11
17
|
# The project's branch to use
|
12
18
|
# Uncomment and edit this if you're using git, for other SCM's please refer
|
13
19
|
# to capistrano's documentation
|
@@ -28,19 +34,45 @@ set :keep_releases, 5
|
|
28
34
|
# Using RVM? Set this to the ruby version/gemset to use
|
29
35
|
set :rvm_ruby_string, "1.9.2"
|
30
36
|
|
31
|
-
|
37
|
+
#############
|
38
|
+
# Mysql
|
39
|
+
#
|
40
|
+
|
41
|
+
# What is the database name for this project/stage ?
|
42
|
+
set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
|
43
|
+
|
44
|
+
# What is the database user ?
|
45
|
+
# NOTE: This is only used if you run deploy:server:prepare which calls mysql:create_db_user
|
46
|
+
set :mysql_db_user, -> { "#{fetch :application}" }
|
47
|
+
|
48
|
+
# Where the database credentials are stored on the server ?
|
32
49
|
set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
|
50
|
+
|
51
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
33
52
|
set :mysql_credentials_host_regex, /hostname: (.*)$/o
|
34
53
|
set :mysql_credentials_host_regex_match, 1
|
54
|
+
|
55
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
35
56
|
set :mysql_credentials_user_regex, /username: (.*)$/o
|
36
57
|
set :mysql_credentials_user_regex_match, 1
|
58
|
+
|
59
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
37
60
|
set :mysql_credentials_pass_regex, /password: (.*)$/o
|
38
61
|
set :mysql_credentials_pass_regex_match, 1
|
62
|
+
|
63
|
+
# Where can we find root credentials ?
|
64
|
+
# NOTE: These options are only used if you run deploy:server:prepare which calls mysql:create_db_user
|
39
65
|
set :mysql_root_credentials_file, "/root/.mysql_password"
|
66
|
+
|
67
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
40
68
|
set :mysql_root_credentials_host_regex, /hostname: (.*)$/o
|
41
69
|
set :mysql_root_credentials_host_regex_match, 1
|
70
|
+
|
71
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
42
72
|
set :mysql_root_credentials_user_regex, /username: (.*)$/o
|
43
73
|
set :mysql_root_credentials_user_regex_match, 1
|
74
|
+
|
75
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
44
76
|
set :mysql_root_credentials_pass_regex, /password: (.*)$/o
|
45
77
|
set :mysql_root_credentials_pass_regex_match, 1
|
46
78
|
|
@@ -92,14 +124,14 @@ set :web_server_mod_rewrite, true
|
|
92
124
|
# Valid options:
|
93
125
|
#
|
94
126
|
# For Nginx:
|
95
|
-
# => :
|
96
|
-
# => :
|
127
|
+
# => :reverse_proxy, :passenger, :php_fpm
|
128
|
+
# => :reverse_proxy is used for unicorn (Rack apps)
|
97
129
|
# => :passenger runs rails apps
|
98
130
|
# => :php_fpm is used to deliver websites written using PHP
|
99
131
|
#
|
100
132
|
# For Apache
|
101
133
|
# =>
|
102
|
-
set :web_server_mode, :
|
134
|
+
set :web_server_mode, :reverse_proxy
|
103
135
|
|
104
136
|
# Server mode specific configurations
|
105
137
|
# Uncomment and edit the one depending on the enabled mode
|
@@ -30,8 +30,11 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
30
30
|
|
31
31
|
desc "[internal] Setup contao's localconfig"
|
32
32
|
task :setup_localconfig, :roles => :app, :except => { :no_release => true } do
|
33
|
+
on_rollback { run "rm -f #{shared_path}/localconfig.php" }
|
34
|
+
|
33
35
|
localconfig = File.read("public/system/config/localconfig.php.sample")
|
34
36
|
mysql_credentials = fetch :mysql_credentials
|
37
|
+
mysql_db_name = fetch :mysql_db_name
|
35
38
|
|
36
39
|
# localconfig
|
37
40
|
if mysql_credentials.blank?
|
@@ -63,7 +66,6 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
63
66
|
# Dependencies
|
64
67
|
after "deploy:setup", "contao:setup"
|
65
68
|
after "contao:setup", "contao:setup_localconfig"
|
66
|
-
after "contao:setup_localconfig", "mysql:create_db"
|
67
69
|
after "deploy:finalize_update", "contao:fix_links"
|
68
70
|
after "contao:fix_links", "deploy:cleanup"
|
69
71
|
after "deploy:restart", "deploy:fix_permissions"
|
@@ -21,7 +21,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
21
21
|
unless exists?(:app_owner) or exists?(:app_group)
|
22
22
|
run <<-CMD
|
23
23
|
#{try_sudo} chown -R \
|
24
|
-
#{fetch :app_owner}:#{fetch :app_group} \
|
24
|
+
#{fetch :app_owner, 'www-data'}:#{fetch :app_group, 'www-data'} \
|
25
25
|
#{fetch :deploy_to}/releases \
|
26
26
|
#{fetch :deploy_to}/shared
|
27
27
|
CMD
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'capistrano'
|
2
|
+
require 'digest/sha1'
|
2
3
|
require 'highline'
|
3
4
|
|
4
5
|
# Verify that Capistrano is version 2
|
@@ -48,8 +49,26 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
52
|
+
def mysql_db_hosts
|
53
|
+
# TODO: Do some real work here, we shouldn't be allowing all hosts but only all db/web/app hosts.
|
54
|
+
['%']
|
55
|
+
end
|
56
|
+
|
57
|
+
def random_tmp_file(data = nil)
|
58
|
+
if data.present?
|
59
|
+
data_hash = Digest::SHA1.hexdigest data
|
60
|
+
"/tmp/#{fetch :application}_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S')}_#{data_hash}"
|
61
|
+
else
|
62
|
+
"/tmp/#{fetch :application}_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S')}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Helper for some mysql tasks
|
67
|
+
def mysql_credentials
|
68
|
+
return <<-EOS
|
69
|
+
hostname: localhost
|
70
|
+
username: #{mysql_db_user}
|
71
|
+
password: #{fetch :mysql_db_pass}
|
72
|
+
EOS
|
54
73
|
end
|
55
74
|
end
|
@@ -11,8 +11,11 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
11
11
|
desc "Backup database"
|
12
12
|
task :backup_db, :roles => :db, :except => { :no_release => true } do
|
13
13
|
mysql_credentials = fetch :mysql_credentials
|
14
|
+
mysql_db_name = fetch :mysql_db_name
|
14
15
|
MYSQL_DB_BACKUP_PATH = "#{deploy_to}/backups/#{mysql_db_name}_#{Time.now.strftime('%d-%m-%Y_%H-%M-%S')}.sql"
|
15
16
|
|
17
|
+
on_rollback { run "rm -f #{MYSQL_DB_BACKUP_PATH}" }
|
18
|
+
|
16
19
|
if exists?(:mysql_credentials)
|
17
20
|
begin
|
18
21
|
run <<-CMD
|
@@ -39,6 +42,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
39
42
|
desc "drop database"
|
40
43
|
task :drop_db, :roles => :db, :except => { :no_release => true } do
|
41
44
|
mysql_credentials = fetch :mysql_credentials
|
45
|
+
mysql_db_name = fetch :mysql_db_name
|
42
46
|
|
43
47
|
unless mysql_credentials.blank?
|
44
48
|
begin
|
@@ -56,9 +60,69 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
56
60
|
end
|
57
61
|
end
|
58
62
|
|
63
|
+
desc "create database user"
|
64
|
+
task :create_db_user, :roles => :db, :except => { :no_release => true } do
|
65
|
+
mysql_root_credentials = fetch :mysql_root_credentials
|
66
|
+
mysql_db_user = fetch :mysql_db_user
|
67
|
+
random_file = random_tmp_file mysql_root_credentials[:pass]
|
68
|
+
|
69
|
+
unless mysql_root_credentials.blank?
|
70
|
+
set :mysql_db_pass, -> { gen_pass(8) }
|
71
|
+
mysql_create = ""
|
72
|
+
|
73
|
+
mysql_db_hosts.each do |host|
|
74
|
+
mysql_create << <<-EOS
|
75
|
+
CREATE USER '#{mysql_db_user}'@'#{host}' IDENTIFIED BY '#{fetch :mysql_db_pass}';
|
76
|
+
GRANT ALL ON `#{fetch :application}\_%`.* TO '#{mysql_db_user}'@'#{host}';
|
77
|
+
FLUSH PRIVILEGES;
|
78
|
+
EOS
|
79
|
+
end
|
80
|
+
|
81
|
+
put mysql_create, random_file
|
82
|
+
|
83
|
+
begin
|
84
|
+
run <<-CMD
|
85
|
+
mysql \
|
86
|
+
--host='#{mysql_root_credentials[:host]}' \
|
87
|
+
--user='#{mysql_root_credentials[:user]}' \
|
88
|
+
--password='#{mysql_root_credentials[:pass]}' \
|
89
|
+
--default-character-set=utf8 < \
|
90
|
+
#{random_file}
|
91
|
+
CMD
|
92
|
+
|
93
|
+
run <<-CMD
|
94
|
+
rm -f #{random_file}
|
95
|
+
CMD
|
96
|
+
|
97
|
+
find_and_execute_task("mysql:write_db_credentials")
|
98
|
+
rescue
|
99
|
+
puts "WARNING: The user #{application} already exists."
|
100
|
+
find_and_execute_task("mysql:print_db_credentials")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
desc "write database credentials"
|
106
|
+
task :write_db_credentials do
|
107
|
+
mysql_credentials_file = fetch :mysql_credentials_file
|
108
|
+
unless exists?(:mysql_credentials_file) and remote_file_exists?(mysql_credentials_file)
|
109
|
+
put mysql_credentials, mysql_credentials_file
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
desc "print database credentials"
|
114
|
+
task :print_db_credentials do
|
115
|
+
mysql_credentials_file = fetch :mysql_credentials_file
|
116
|
+
unless exists?(:mysql_credentials_file) and remote_file_exists?(mysql_credentials_file)
|
117
|
+
puts "WARNING: mysql_credentials_file is not defined in config.rb you have to manually copy the following info into a credential file and define it"
|
118
|
+
puts mysql_credentials
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
59
122
|
desc "create database"
|
60
123
|
task :create_db, :roles => :db, :except => { :no_release => true } do
|
61
124
|
mysql_credentials = fetch :mysql_credentials
|
125
|
+
mysql_db_name = fetch :mysql_db_name
|
62
126
|
|
63
127
|
unless mysql_credentials.blank?
|
64
128
|
begin
|
@@ -77,7 +141,10 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
77
141
|
|
78
142
|
desc "Import a database dump"
|
79
143
|
task :import_db_dump, :roles => :db, :except => { :no_release => true } do
|
144
|
+
on_rollback { run "rm -f /tmp/#{mysql_db_name}_dump.sql" }
|
145
|
+
|
80
146
|
mysql_credentials = fetch :mysql_credentials
|
147
|
+
mysql_db_name = fetch :mysql_db_name
|
81
148
|
|
82
149
|
unless ARGV.size >=2 and File.exists?(ARGV[1])
|
83
150
|
puts "ERROR: please run 'cap mysql:import_db_dump <sql dump>'"
|
@@ -112,6 +179,8 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
112
179
|
|
113
180
|
desc "Export a database dump"
|
114
181
|
task :export_db_dump, :roles => :db, :except => { :no_release => true } do
|
182
|
+
on_rollback { run "rm -f /tmp/#{File.basename MYSQL_DB_BACKUP_PATH}{,.bz2" }
|
183
|
+
|
115
184
|
mysql_credentials = fetch :mysql_credentials
|
116
185
|
|
117
186
|
unless ARGV.size >=2 or File.exists?(ARGV[1])
|
@@ -152,12 +221,20 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
152
221
|
set :mysql_credentials, false
|
153
222
|
end
|
154
223
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
224
|
+
if exists?(:mysql_credentials_file_contents)
|
225
|
+
mysql_credentials_file_contents = fetch :mysql_credentials_file_contents
|
226
|
+
|
227
|
+
unless mysql_credentials_file_contents.blank?
|
228
|
+
mysql_credentials = {
|
229
|
+
host: mysql_credentials_file_contents.match(mysql_credentials_host_regex).try(:[], mysql_credentials_host_regex_match).try(:chomp),
|
230
|
+
user: mysql_credentials_file_contents.match(mysql_credentials_user_regex).try(:[], mysql_credentials_user_regex_match).try(:chomp),
|
231
|
+
pass: mysql_credentials_file_contents.match(mysql_credentials_pass_regex).try(:[], mysql_credentials_pass_regex_match).try(:chomp),
|
232
|
+
}
|
233
|
+
|
234
|
+
if mysql_credentials[:user].present? and mysql_credentials[:pass].present?
|
235
|
+
set :mysql_credentials, mysql_credentials
|
236
|
+
end
|
237
|
+
end
|
161
238
|
end
|
162
239
|
end
|
163
240
|
|
@@ -185,12 +262,19 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
185
262
|
set :mysql_root_credentials, false
|
186
263
|
end
|
187
264
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
265
|
+
if exists?(:mysql_root_credentials_file_contents)
|
266
|
+
mysql_root_credentials_file_contents = fetch :mysql_root_credentials_file_contents
|
267
|
+
unless mysql_root_credentials_file_contents.blank?
|
268
|
+
mysql_root_credentials = {
|
269
|
+
host: mysql_root_credentials_file_contents.match(mysql_root_credentials_host_regex).try(:[], mysql_root_credentials_host_regex_match).try(:chomp),
|
270
|
+
user: mysql_root_credentials_file_contents.match(mysql_root_credentials_user_regex).try(:[], mysql_root_credentials_user_regex_match).try(:chomp),
|
271
|
+
pass: mysql_root_credentials_file_contents.match(mysql_root_credentials_pass_regex).try(:[], mysql_root_credentials_pass_regex_match).try(:chomp),
|
272
|
+
}
|
273
|
+
|
274
|
+
if mysql_root_credentials[:user].present? and mysql_root_credentials[:pass].present?
|
275
|
+
set :mysql_root_credentials, mysql_root_credentials
|
276
|
+
end
|
277
|
+
end
|
194
278
|
end
|
195
279
|
end
|
196
280
|
|
@@ -211,4 +295,6 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
211
295
|
before "mysql:create_db", "mysql:credentials"
|
212
296
|
before "mysql:import_db_dump", "mysql:backup_db"
|
213
297
|
before "mysql:export_db_dump", "mysql:backup_db"
|
298
|
+
before "mysql:create_db_user", "mysql:root_credentials"
|
299
|
+
after "mysql:create_db_user", "mysql:create_db"
|
214
300
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require 'capistrano-exts/receipts/mysql'
|
4
|
+
|
3
5
|
# Verify that Capistrano is version 2
|
4
6
|
unless Capistrano::Configuration.respond_to?(:instance)
|
5
7
|
abort "This extension requires Capistrano 2"
|
@@ -9,11 +11,19 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
9
11
|
namespace :deploy do
|
10
12
|
namespace :server do
|
11
13
|
namespace :db_server do
|
12
|
-
desc "
|
13
|
-
task :
|
14
|
+
desc "[internal] Prepare the database server"
|
15
|
+
task :prepare, :roles => :db do
|
16
|
+
# Empty task, server preparation goes into callbacks
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "[internal] Finished preparing the database server"
|
20
|
+
task :finish, :roles => :db do
|
14
21
|
# Empty task, server preparation goes into callbacks
|
15
22
|
end
|
16
23
|
end
|
17
24
|
end
|
18
25
|
end
|
26
|
+
|
27
|
+
before "deploy:server:db_server:prepare", "mysql:create_db_user"
|
28
|
+
after "deploy:server:db_server:prepare", "deploy:server:db_server:finish"
|
19
29
|
end
|
@@ -15,8 +15,13 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
15
15
|
namespace :deploy do
|
16
16
|
namespace :server do
|
17
17
|
namespace :web_server do
|
18
|
-
desc "
|
19
|
-
task :
|
18
|
+
desc "Prepare the web server"
|
19
|
+
task :prepare, :roles => :web do
|
20
|
+
# Empty task, server preparation goes into callbacks
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Finished preparing the web server"
|
24
|
+
task :finish do
|
20
25
|
# Empty task, server preparation goes into callbacks
|
21
26
|
end
|
22
27
|
|
@@ -65,7 +70,7 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
65
70
|
if exists?(:web_server_auth_file)
|
66
71
|
web_server_auth_file = fetch :web_server_auth_file
|
67
72
|
web_server_auth_file_contents = fetch :web_server_auth_file_contents
|
68
|
-
random_file =
|
73
|
+
random_file = random_tmp_file web_server_auth_file_contents
|
69
74
|
|
70
75
|
run <<-CMD
|
71
76
|
#{try_sudo} mkdir -p #{File.dirname web_server_auth_file}
|
@@ -96,16 +101,12 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
96
101
|
CMD
|
97
102
|
end
|
98
103
|
end
|
99
|
-
|
100
|
-
task :finish do
|
101
|
-
# Empty task for callbacks
|
102
|
-
end
|
103
104
|
end
|
104
105
|
end
|
105
106
|
end
|
106
107
|
|
107
|
-
before "deploy:server:web_server:
|
108
|
-
after "deploy:server:web_server:
|
108
|
+
before "deploy:server:web_server:prepare", "deploy:server:web_server:generate_web_configuration"
|
109
|
+
after "deploy:server:web_server:prepare", "deploy:server:web_server:finish"
|
109
110
|
after "deploy:server:web_server:generate_web_configuration", "deploy:server:web_server:generate_authentification"
|
110
111
|
after "deploy:server:web_server:generate_web_configuration", "deploy:server:web_server:write_web_conf_file"
|
111
112
|
after "deploy:server:web_server:generate_authentification", "deploy:server:web_server:write_web_server_auth_file"
|
@@ -15,7 +15,7 @@ end
|
|
15
15
|
Capistrano::Configuration.instance(:must_exist).load do
|
16
16
|
namespace :deploy do
|
17
17
|
namespace :server do
|
18
|
-
namespace :
|
18
|
+
namespace :prepare do
|
19
19
|
desc "Prepare the server (database server, web server and folders)"
|
20
20
|
task :default do
|
21
21
|
# Empty task, server preparation goes into callbacks
|
@@ -43,9 +43,9 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# Callbacks
|
46
|
-
before "deploy:server:
|
47
|
-
after "deploy:server:
|
46
|
+
before "deploy:server:prepare", "deploy:server:prepare:folders"
|
47
|
+
after "deploy:server:prepare", "deploy:server:prepare:finish"
|
48
48
|
|
49
|
-
after "deploy:server:
|
50
|
-
after "deploy:server:
|
49
|
+
after "deploy:server:prepare:folders", "deploy:server:db_server:prepare"
|
50
|
+
after "deploy:server:prepare:folders", "deploy:server:web_server:prepare"
|
51
51
|
end
|
@@ -5,7 +5,7 @@ module Capistrano
|
|
5
5
|
module Server
|
6
6
|
class Nginx < WebServer
|
7
7
|
|
8
|
-
AVAILABLE_MODES = [:passenger, :
|
8
|
+
AVAILABLE_MODES = [:passenger, :reverse_proxy, :php_fpm]
|
9
9
|
NGINX_TEMPLATE_PATH = ROOT_PATH + '/capistrano-exts/templates/web_servers/nginx.conf.erb'
|
10
10
|
|
11
11
|
def initialize(mode, template_path = NGINX_TEMPLATE_PATH)
|
@@ -5,9 +5,11 @@ role :web, 'root@nasreddine.com:22'
|
|
5
5
|
role :app, 'root@nasreddine.com:22'
|
6
6
|
role :db, 'root@nasreddine.com:22', primary: true
|
7
7
|
|
8
|
-
# Permissions
|
9
|
-
|
10
|
-
set :
|
8
|
+
# Permissions and ownership
|
9
|
+
# Uncomment if necessary...
|
10
|
+
# set :app_owner, 'www-data'
|
11
|
+
# set :app_group, 'www-data'
|
12
|
+
# set :group_writable, true
|
11
13
|
|
12
14
|
# The project's branch to use
|
13
15
|
# Uncomment and edit this if you're using git, for other SCM's please refer
|
@@ -29,22 +31,49 @@ set :keep_releases, 5
|
|
29
31
|
# Using RVM? Set this to the ruby version/gemset to use
|
30
32
|
set :rvm_ruby_string, "1.9.2"
|
31
33
|
|
32
|
-
|
34
|
+
#############
|
35
|
+
# Mysql
|
36
|
+
#
|
37
|
+
|
38
|
+
# What is the database name for this project/stage ?
|
39
|
+
set :mysql_db_name, -> { "#{fetch :application}_#{fetch :stage}" }
|
40
|
+
|
41
|
+
# What is the database user ?
|
42
|
+
# NOTE: This is only used if you run deploy:server:prepare which calls mysql:create_db_user
|
43
|
+
set :mysql_db_user, -> { "#{fetch :application}" }
|
44
|
+
|
45
|
+
# Where the database credentials are stored on the server ?
|
33
46
|
set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
|
47
|
+
|
48
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
34
49
|
set :mysql_credentials_host_regex, /hostname: (.*)$/o
|
35
50
|
set :mysql_credentials_host_regex_match, 1
|
51
|
+
|
52
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
36
53
|
set :mysql_credentials_user_regex, /username: (.*)$/o
|
37
54
|
set :mysql_credentials_user_regex_match, 1
|
55
|
+
|
56
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
38
57
|
set :mysql_credentials_pass_regex, /password: (.*)$/o
|
39
58
|
set :mysql_credentials_pass_regex_match, 1
|
59
|
+
|
60
|
+
# Where can we find root credentials ?
|
61
|
+
# NOTE: These options are only used if you run deploy:server:prepare which calls mysql:create_db_user
|
40
62
|
set :mysql_root_credentials_file, "/root/.mysql_password"
|
63
|
+
|
64
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the hostname
|
41
65
|
set :mysql_root_credentials_host_regex, /hostname: (.*)$/o
|
42
66
|
set :mysql_root_credentials_host_regex_match, 1
|
67
|
+
|
68
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the username
|
43
69
|
set :mysql_root_credentials_user_regex, /username: (.*)$/o
|
44
70
|
set :mysql_root_credentials_user_regex_match, 1
|
71
|
+
|
72
|
+
# Define the regex / match that will be ran against the contents of the file above to fetch the password
|
45
73
|
set :mysql_root_credentials_pass_regex, /password: (.*)$/o
|
46
74
|
set :mysql_root_credentials_pass_regex_match, 1
|
47
75
|
|
76
|
+
|
48
77
|
#############
|
49
78
|
# Web server
|
50
79
|
#
|
@@ -93,14 +122,14 @@ set :web_server_mod_rewrite, true
|
|
93
122
|
# Valid options:
|
94
123
|
#
|
95
124
|
# For Nginx:
|
96
|
-
# => :
|
97
|
-
# => :
|
125
|
+
# => :reverse_proxy, :passenger, :php_fpm
|
126
|
+
# => :reverse_proxy is used for unicorn (Rack apps)
|
98
127
|
# => :passenger runs rails apps
|
99
128
|
# => :php_fpm is used to deliver websites written using PHP
|
100
129
|
#
|
101
130
|
# For Apache
|
102
131
|
# =>
|
103
|
-
set :web_server_mode, :
|
132
|
+
set :web_server_mode, :reverse_proxy
|
104
133
|
|
105
134
|
# Server mode specific configurations
|
106
135
|
# Uncomment and edit the one depending on the enabled mode
|
data/spec/requests/nginx_spec.rb
CHANGED
@@ -83,8 +83,8 @@ describe Nginx do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
describe ":
|
87
|
-
subject { Nginx.new :
|
86
|
+
describe ":reverse_proxy" do
|
87
|
+
subject { Nginx.new :reverse_proxy }
|
88
88
|
|
89
89
|
before(:each) do
|
90
90
|
subject.application_url = %w{example.com www.example.com}
|
@@ -225,8 +225,8 @@ describe Nginx do
|
|
225
225
|
end
|
226
226
|
end
|
227
227
|
|
228
|
-
describe ":
|
229
|
-
subject { Nginx.new :
|
228
|
+
describe ":reverse_proxy" do
|
229
|
+
subject { Nginx.new :reverse_proxy }
|
230
230
|
|
231
231
|
before(:each) do
|
232
232
|
subject.application_url = %w{example.com www.example.com}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-exts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
16
|
-
requirement: &
|
16
|
+
requirement: &2161009320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.8.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2161009320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: i18n
|
27
|
-
requirement: &
|
27
|
+
requirement: &2161008820 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.6.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2161008820
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activesupport
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152515960 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 3.1.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152515960
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: guard
|
49
|
-
requirement: &
|
49
|
+
requirement: &2152514760 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.6.2
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2152514760
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: guard-bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &2152512100 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.1.3
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2152512100
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: guard-rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &2152509640 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 0.4.3
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2152509640
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rspec
|
82
|
-
requirement: &
|
82
|
+
requirement: &2152509160 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 2.6.0
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2152509160
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: mocha
|
93
|
-
requirement: &
|
93
|
+
requirement: &2152508660 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 0.2.12
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *2152508660
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: factory_girl
|
104
|
-
requirement: &
|
104
|
+
requirement: &2161039720 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: 2.0.5
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *2161039720
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: faker19
|
115
|
-
requirement: &
|
115
|
+
requirement: &2161039260 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
version: 1.0.5
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *2161039260
|
124
124
|
description: Handy extensions for Capistrano
|
125
125
|
email:
|
126
126
|
- wael.nasreddine@gmail.com
|