deploy_mate 0.1 → 0.2
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 +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +19 -0
- data/Gemfile.lock +9 -7
- data/README.md +57 -29
- data/deploy-mate.gemspec +5 -8
- data/lib/capistrano/configs/application.pill.erb +59 -0
- data/lib/capistrano/configs/fail2ban-nginx-request-limit-filter.conf.erb +13 -0
- data/lib/capistrano/configs/fail2ban-nginx-request-limit-jail.conf.erb +494 -0
- data/lib/capistrano/configs/logrotate.erb +2 -2
- data/lib/capistrano/configs/nginx_app.conf.erb +9 -4
- data/lib/capistrano/configs/nginx_base.conf.erb +1 -1
- data/lib/capistrano/configs/puma.rb.erb +64 -0
- data/lib/capistrano/configs/upstart.conf.erb +1 -1
- data/lib/capistrano/deploy_mate_capfile.rb +2 -2
- data/lib/capistrano/deploy_mate_defaults.rb +5 -4
- data/lib/capistrano/helpers.rb +4 -2
- data/lib/capistrano/modules/shell.rb +7 -0
- data/lib/capistrano/modules/user_management.rb +11 -0
- data/lib/capistrano/scripts/create_ubuntu_user.sh +9 -0
- data/lib/capistrano/scripts/set_defaults.sh +2 -1
- data/lib/capistrano/tasks/bluepill.rake +29 -5
- data/lib/capistrano/tasks/elasticsearch.rake +18 -0
- data/lib/capistrano/tasks/fail2ban.rake +22 -0
- data/lib/capistrano/tasks/logrotate.rake +1 -0
- data/lib/capistrano/tasks/machine.rake +99 -17
- data/lib/capistrano/tasks/nginx.rake +7 -4
- data/lib/capistrano/tasks/puma.rake +18 -0
- data/lib/capistrano/tasks/unicorn.rake +1 -17
- data/lib/capistrano/tasks/upstart.rake +2 -0
- data/lib/deploy_mate/tasks.rake +52 -45
- data/lib/deploy_mate/templates/Capfile.erb +9 -2
- data/lib/deploy_mate/templates/deploy/stage.rb.erb +4 -4
- data/lib/deploy_mate/templates/deploy.rb.erb +22 -4
- data/lib/deploy_mate/templates/deploy_mate.yml.erb +79 -0
- data/lib/deploy_mate.rb +9 -0
- metadata +19 -5
- data/lib/capistrano/configs/unicorn.pill.erb +0 -28
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
sudo mkdir -p /home/ubuntu/.ssh/
|
3
|
+
sudo groupadd ubuntu
|
4
|
+
sudo useradd ubuntu -g ubuntu -d /home/ubuntu -s /bin/bash
|
5
|
+
sudo adduser ubuntu sudo
|
6
|
+
sudo cp ~/.ssh/authorized_keys /home/ubuntu/.ssh/
|
7
|
+
sudo chown -R ubuntu:ubuntu /home/ubuntu
|
8
|
+
sudo echo "ubuntu ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/ubuntu_no_sudo_password
|
9
|
+
sudo chmod 0440 /etc/sudoers.d/ubuntu_no_sudo_password
|
@@ -1,27 +1,51 @@
|
|
1
1
|
namespace :bluepill do
|
2
|
+
include Shell
|
2
3
|
|
3
4
|
desc "Installs the application pill"
|
4
5
|
task :setup do
|
5
6
|
on roles(:app) do
|
6
7
|
execute "mkdir -p #{shared_path}/config"
|
7
|
-
template "
|
8
|
+
template "application.pill.erb", "#{shared_path}/config/#{fetch(:application)}.pill"
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
11
12
|
desc "Starts bluepill"
|
12
13
|
task :start do
|
13
14
|
on roles(:app) do
|
14
|
-
|
15
|
+
if !bluepill_running?
|
16
|
+
sudo "start bluepill"
|
17
|
+
else
|
18
|
+
info "No need to start bluepill, it is running!"
|
19
|
+
end
|
15
20
|
end
|
16
21
|
end
|
17
22
|
|
18
|
-
desc "Stops
|
23
|
+
desc "Stops app server"
|
19
24
|
task :stop do
|
20
25
|
on roles(:app) do
|
21
|
-
|
26
|
+
if bluepill_running?
|
27
|
+
sudo "stop bluepill"
|
28
|
+
else
|
29
|
+
"Can't stop bluepill because it's not running!"
|
30
|
+
end
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
34
|
+
desc "Restarts/Reloads app gracefully"
|
35
|
+
task :restart do
|
36
|
+
invoke "bluepill:start"
|
25
37
|
|
26
|
-
|
38
|
+
on roles(:app) do
|
39
|
+
if bluepill_running?
|
40
|
+
if pill_running?(fetch(:app_server))
|
41
|
+
execute :rvmsudo, :bluepill, fetch(:application), :restart
|
42
|
+
else
|
43
|
+
execute :rvmsudo, :bluepill, fetch(:application), :start
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
27
47
|
|
48
|
+
invoke "nginx:reload"
|
49
|
+
end
|
50
|
+
before :restart, 'rvm:hook'
|
51
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
set_default(:elasticsearch_version, "1.7")
|
2
|
+
|
3
|
+
namespace :elasticsearch do
|
4
|
+
include Aptitude
|
5
|
+
task :install do
|
6
|
+
on roles(:search) do
|
7
|
+
unless is_package_installed?("elasticsearch")
|
8
|
+
apt_get_install("openjdk-7-jre-headless") unless is_package_installed?("openjdk-7-jre-headless")
|
9
|
+
execute "wget -qO - https://packages.elasticsearch.org/GPG-KEY-elasticsearch | sudo apt-key add -"
|
10
|
+
sudo "add-apt-repository 'deb http://packages.elasticsearch.org/elasticsearch/#{fetch(:elasticsearch_version)}/debian stable main'"
|
11
|
+
apt_get_update
|
12
|
+
apt_get_install("elasticsearch")
|
13
|
+
sudo "update-rc.d elasticsearch defaults 95 10"
|
14
|
+
sudo :service, :elasticsearch, :start
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
namespace :fail2ban do
|
2
|
+
include Shell
|
3
|
+
|
4
|
+
desc "Installs the fail2ban configs"
|
5
|
+
task :setup do
|
6
|
+
on roles(:web) do
|
7
|
+
template "fail2ban-nginx-request-limit-jail.conf.erb", "/tmp/fail2ban_jail"
|
8
|
+
sudo "mv /tmp/fail2ban_jail /etc/fail2ban/jail.conf"
|
9
|
+
template "fail2ban-nginx-request-limit-jail.conf.erb", "/tmp/fail2ban_req_filter"
|
10
|
+
sudo "mv /tmp/fail2ban_req_filter /etc/fail2ban/filter.d/nginx-req-limit.conf"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Restart fail2ban"
|
15
|
+
task :restart do
|
16
|
+
on roles(:web) do
|
17
|
+
sudo "service fail2ban restart"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
after "fail2ban:setup", "fail2ban:restart"
|
22
|
+
end
|
@@ -1,37 +1,59 @@
|
|
1
1
|
namespace :machine do
|
2
2
|
include Aptitude
|
3
|
+
include UserManagement
|
3
4
|
|
4
5
|
desc "Sets up a blank Ubuntu to run our Rails-setup"
|
5
6
|
task :init do
|
6
7
|
on roles(:app) do
|
7
8
|
apt_get_update
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
9
|
+
end
|
10
|
+
invoke "machine:install:ssh_keys"
|
11
|
+
invoke "machine:install:htop"
|
12
|
+
invoke "machine:install:language_pack_de"
|
13
|
+
invoke "machine:install:unattended_upgrades"
|
14
|
+
invoke "machine:install:ntp"
|
15
|
+
invoke "machine:install:git"
|
16
|
+
invoke "machine:install:nginx"
|
17
|
+
invoke "machine:install:fail2ban"
|
18
|
+
invoke "machine:install:rvm"
|
19
|
+
invoke "machine:install:ruby"
|
20
|
+
invoke "machine:install:set_defaults"
|
21
|
+
invoke "machine:install:bluepill"
|
22
|
+
invoke "machine:install:bundler"
|
23
|
+
invoke "machine:install:nodejs"
|
24
|
+
invoke "machine:install:elasticsearch"
|
25
|
+
invoke "machine:install:imagemagick" if fetch(:imagemagick)
|
26
|
+
invoke "machine:install:memcached" if fetch(:memcached)
|
27
|
+
invoke "machine:install:mysql_dev" if fetch(:db_engine) == "mysql"
|
28
|
+
invoke "machine:install:postgres_dev" if fetch(:db_engine) == "postgresql"
|
29
|
+
end
|
30
|
+
before "machine:init", "machine:check_ubuntu_user"
|
31
|
+
before "deploy", "machine:check_ubuntu_user"
|
32
|
+
|
33
|
+
desc "Check if we are doing things as the correct user"
|
34
|
+
task :check_ubuntu_user do
|
35
|
+
on roles(:app) do
|
36
|
+
unless am_i?("ubuntu")
|
37
|
+
execute_script("create_ubuntu_user.sh") # Creates an Amazon AWS-style 'ubuntu'-user on machines with only 'root'
|
38
|
+
error "Please use a use a user named 'ubuntu' to login to the machine."
|
39
|
+
fail
|
40
|
+
end
|
41
|
+
end
|
23
42
|
end
|
24
43
|
|
25
44
|
desc "Install configs"
|
26
45
|
task :setup do
|
27
46
|
invoke "nginx:setup"
|
28
|
-
invoke "unicorn:setup"
|
47
|
+
invoke "unicorn:setup" if fetch(:app_server) == "unicorn"
|
48
|
+
invoke "puma:setup" if fetch(:app_server) == "puma"
|
29
49
|
invoke "upstart:setup"
|
30
50
|
invoke "logrotate:setup"
|
51
|
+
invoke "fail2ban:setup"
|
31
52
|
invoke "bluepill:setup"
|
32
53
|
end
|
33
54
|
before :setup, "deploy:ensure_folder"
|
34
55
|
|
56
|
+
desc "Install all dependencies"
|
35
57
|
namespace :install do
|
36
58
|
task :set_defaults do
|
37
59
|
on roles(:app) do
|
@@ -42,6 +64,10 @@ namespace :machine do
|
|
42
64
|
end
|
43
65
|
end
|
44
66
|
|
67
|
+
task :elasticsearch do
|
68
|
+
invoke 'elasticsearch:install'
|
69
|
+
end
|
70
|
+
|
45
71
|
task :language_pack_de do
|
46
72
|
on roles(:app) do
|
47
73
|
apt_get_install("language-pack-de") unless is_package_installed?("language-pack-de")
|
@@ -76,12 +102,31 @@ namespace :machine do
|
|
76
102
|
end
|
77
103
|
end
|
78
104
|
|
105
|
+
task :imagemagick do
|
106
|
+
on roles(:app) do
|
107
|
+
apt_get_install("imagemagick") unless is_package_installed?("imagemagick")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
task :memcached do
|
112
|
+
on roles(:app) do
|
113
|
+
apt_get_install("memcached") unless is_package_installed?("memcached")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
79
117
|
task :mysql_dev do
|
80
118
|
on roles(:app) do
|
81
119
|
apt_get_install("libmysqlclient-dev") unless is_package_installed?("libmysqlclient-dev")
|
82
120
|
end
|
83
121
|
end
|
84
122
|
|
123
|
+
task :postgres_dev do
|
124
|
+
on roles(:app) do
|
125
|
+
apt_get_install("libpq-dev") unless is_package_installed?("libpq-dev")
|
126
|
+
apt_get_install("postgresql-client") unless is_package_installed?("postgresql-client")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
85
130
|
task :htop do
|
86
131
|
on roles(:app) do
|
87
132
|
apt_get_install("htop") unless is_package_installed?("htop")
|
@@ -97,6 +142,10 @@ namespace :machine do
|
|
97
142
|
task :ntp do
|
98
143
|
on roles(:app) do
|
99
144
|
apt_get_install("ntp") unless is_package_installed?("ntp")
|
145
|
+
sudo "chmod 666 /etc/timezone"
|
146
|
+
execute 'echo "Europe/Berlin" > /etc/timezone'
|
147
|
+
sudo "chmod 644 /etc/timezone"
|
148
|
+
sudo "dpkg-reconfigure -f noninteractive tzdata"
|
100
149
|
end
|
101
150
|
end
|
102
151
|
|
@@ -123,6 +172,7 @@ namespace :machine do
|
|
123
172
|
unless is_package_installed?("imagemagick")
|
124
173
|
apt_get_install("imagemagick")
|
125
174
|
apt_get_install("libmagickcore-dev")
|
175
|
+
apt_get_install("libmagickwand-dev")
|
126
176
|
end
|
127
177
|
end
|
128
178
|
end
|
@@ -135,9 +185,41 @@ namespace :machine do
|
|
135
185
|
end
|
136
186
|
end
|
137
187
|
|
188
|
+
desc "Installs new SSH Keys"
|
189
|
+
task :ssh_keys do
|
190
|
+
on roles(:app) do
|
191
|
+
file_patterns = fetch(:ssh_file_names)
|
192
|
+
|
193
|
+
next puts("Skip SSH key installation") if file_patterns == []
|
194
|
+
|
195
|
+
puts "Installing SSH Keys from #{file_patterns.join(',')}..."
|
196
|
+
|
197
|
+
keys = []
|
198
|
+
file_patterns.each do |file_pattern|
|
199
|
+
Dir.glob(File.expand_path(file_pattern)).each do |file_name|
|
200
|
+
next if File.directory?(file_name)
|
201
|
+
key_as_string = File.read(file_name)
|
202
|
+
|
203
|
+
if key_as_string.start_with?("ssh-rsa")
|
204
|
+
keys << key_as_string
|
205
|
+
puts file_name
|
206
|
+
else
|
207
|
+
warn "#{file_name} is NO publickey"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
fail "No ssh-keys found in #{file_patterns.join(',')}." unless keys.any?
|
213
|
+
|
214
|
+
upload!(StringIO.new(keys.join("")), 'new_keys')
|
215
|
+
sudo "rm ~/.ssh/authorized_keys"
|
216
|
+
sudo "mv new_keys ~/.ssh/authorized_keys"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
138
220
|
task :update_rvm_key do
|
139
221
|
on roles(:app) do
|
140
|
-
execute :gpg, "--keyserver hkp://keys.gnupg.net --recv-keys
|
222
|
+
execute :gpg, "--keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3"
|
141
223
|
end
|
142
224
|
end
|
143
225
|
before "machine:install:rvm", "machine:install:update_rvm_key"
|
@@ -1,28 +1,31 @@
|
|
1
1
|
set_default(:nginx_server_name, "*.*")
|
2
2
|
|
3
3
|
namespace :nginx do
|
4
|
+
include Shell
|
4
5
|
|
5
6
|
desc "Installs the nginx configs"
|
6
7
|
task :setup do
|
7
8
|
on roles(:web) do
|
8
9
|
template "nginx_base.conf.erb", "/tmp/nginx_conf"
|
9
10
|
sudo "mv /tmp/nginx_conf /etc/nginx/nginx.conf"
|
11
|
+
|
10
12
|
template "nginx_app.conf.erb", "/tmp/#{fetch(:application)}_conf"
|
11
13
|
sudo "mv /tmp/#{fetch(:application)}_conf /etc/nginx/sites-available/#{fetch(:application)}.conf"
|
12
14
|
|
13
|
-
if
|
15
|
+
if file_exists? "/etc/nginx/sites-enabled/default"
|
14
16
|
sudo "rm /etc/nginx/sites-enabled/default"
|
15
17
|
end
|
16
18
|
|
17
|
-
|
18
|
-
invoke "nginx:reload"
|
19
|
+
execute "mkdir -p #{shared_path}/log"
|
19
20
|
end
|
21
|
+
invoke "nginx:enable_site"
|
22
|
+
invoke "nginx:reload"
|
20
23
|
end
|
21
24
|
|
22
25
|
desc "Enable the app page for nginx"
|
23
26
|
task :enable_site do
|
24
27
|
on roles(:web) do
|
25
|
-
unless
|
28
|
+
unless file_exists? "/etc/nginx/sites-enabled/#{fetch(:application)}.conf"
|
26
29
|
sudo "ln -sf /etc/nginx/sites-available/#{fetch(:application)}.conf /etc/nginx/sites-enabled/#{fetch(:application)}.conf"
|
27
30
|
end
|
28
31
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
set_default(:puma_workers, "5")
|
2
|
+
set_default(:puma_threads, "10")
|
3
|
+
set_default(:puma_timeout, "30")
|
4
|
+
set_default(:puma_worker_grace_time, "60")
|
5
|
+
|
6
|
+
namespace :puma do
|
7
|
+
include Bluepill
|
8
|
+
include Shell
|
9
|
+
|
10
|
+
desc "Installs the puma config"
|
11
|
+
task :setup do
|
12
|
+
on roles(:app) do
|
13
|
+
execute "mkdir -p #{shared_path}/config"
|
14
|
+
template "puma.rb.erb", "#{shared_path}/config/puma.rb"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -4,6 +4,7 @@ set_default(:unicorn_worker_grace_time, "60")
|
|
4
4
|
|
5
5
|
namespace :unicorn do
|
6
6
|
include Bluepill
|
7
|
+
include Shell
|
7
8
|
|
8
9
|
desc "Installs the unicorn config"
|
9
10
|
task :setup do
|
@@ -13,21 +14,4 @@ namespace :unicorn do
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
desc "Gracefully restarts unicorn"
|
17
|
-
task :phased_restart do
|
18
|
-
on roles(:app) do
|
19
|
-
if bluepill_running?
|
20
|
-
if pill_running?(:unicorn)
|
21
|
-
execute :rvmsudo, :bluepill, :restart, :unicorn
|
22
|
-
else
|
23
|
-
execute :rvmsudo, :bluepill, :start, :unicorn
|
24
|
-
end
|
25
|
-
else
|
26
|
-
invoke "bluepill:start"
|
27
|
-
invoke "nginx:reload"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
before :phased_restart, 'rvm:hook'
|
32
|
-
|
33
17
|
end
|
data/lib/deploy_mate/tasks.rake
CHANGED
@@ -1,46 +1,48 @@
|
|
1
|
-
require 'readline'
|
2
|
-
|
3
1
|
namespace :deploy_mate do
|
2
|
+
desc 'copy the default configuration file to config/deploy_mate.yml'
|
3
|
+
task :default_config do
|
4
|
+
@app_name = guess_app_name
|
5
|
+
@ruby_version = guess_ruby_version
|
6
|
+
@rails = to_h(rails?)
|
7
|
+
@imagemagick = to_h(imagemagick?)
|
8
|
+
@sidekiq = to_h(sidekiq?)
|
9
|
+
@memcached = to_h(memcached?)
|
4
10
|
|
5
|
-
|
6
|
-
|
7
|
-
puts "
|
8
|
-
|
9
|
-
|
10
|
-
@app_name = ask("App-Name (for nginx, servers, etc.):", guess_app_name)
|
11
|
-
@repo_url = ask("Url-Location of git-repo:", "git@github.com:hanseventures/#{@app_name}.git")
|
12
|
-
@is_rails = yes_or_no?("Is this a RAILS project ?", (rails_present? ? "yes" : "no"))
|
13
|
-
|
14
|
-
@stage_name = ask("Give the first stage a name:", "prestage")
|
15
|
-
@ssh_name = ask("SSH-Hostname for the server:", "#{@app_name}-#{@stage_name}")
|
16
|
-
@branch_name = ask("Branch to deploy '#{@stage_name}' from:", "dev")
|
17
|
-
@host_name = ask("Web-URL for '#{@stage_name}':", "#{@stage_name}.#{@app_name}.com")
|
18
|
-
@environment = ask("#{@stage_name}'s environment (RACK_ENV/RAILS_ENV):", "#{@stage_name}")
|
19
|
-
|
20
|
-
puts "Aye!"
|
21
|
-
puts "Worrrrking..."
|
11
|
+
puts "Creating default template:\n\n"
|
12
|
+
puts "\t" + config_template('deploy_mate.yml.erb', 'config/deploy_mate.yml')
|
13
|
+
puts "\nConfigure it and then run:\n\n\tbundle exec rake deploy_mate:install\n\n"
|
14
|
+
end
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
sleep 1
|
16
|
+
task :install do
|
17
|
+
@config = YAML.load_file(File.expand_path('config/deploy_mate.yml', ENV['PWD']))
|
18
|
+
puts "Creating capistrano deployment files:\n"
|
27
19
|
FileUtils.mkdir_p("config/deploy") unless File.exists?("config/deploy")
|
28
|
-
config_template("
|
29
|
-
|
30
|
-
|
31
|
-
puts "Arr, be dun working!"
|
20
|
+
puts config_template("Capfile.erb", "Capfile")
|
21
|
+
puts config_template("deploy.rb.erb", "config/deploy.rb")
|
22
|
+
puts config_template("deploy/stage.rb.erb", "config/deploy/#{@config['stage_name']}.rb")
|
32
23
|
end
|
33
|
-
|
34
24
|
end
|
35
25
|
|
36
26
|
def config_template(from, to)
|
37
27
|
erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
|
38
28
|
compiled = ERB.new(erb).result(binding)
|
39
29
|
File.open(to, "wb") { |f| f.write(compiled) }
|
40
|
-
|
30
|
+
to
|
31
|
+
end
|
32
|
+
|
33
|
+
def sidekiq?
|
34
|
+
defined? Sidekiq
|
41
35
|
end
|
42
36
|
|
43
|
-
def
|
37
|
+
def imagemagick?
|
38
|
+
defined? RMagick || defined? MiniMagick
|
39
|
+
end
|
40
|
+
|
41
|
+
def memcached?
|
42
|
+
defined? Dalli
|
43
|
+
end
|
44
|
+
|
45
|
+
def rails?
|
44
46
|
defined? Rails
|
45
47
|
end
|
46
48
|
|
@@ -48,21 +50,26 @@ def guess_app_name
|
|
48
50
|
Dir.pwd.split(File::SEPARATOR).last
|
49
51
|
end
|
50
52
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
def guess_ruby_version
|
54
|
+
ruby_version = nil
|
55
|
+
ruby_version = cat_file(".ruby-version")
|
56
|
+
ruby_version.strip! if ruby_version
|
57
|
+
unless ruby_version
|
58
|
+
gem_file_content = cat_file("Gemfile")
|
59
|
+
if gem_file_content
|
60
|
+
match = gem_file_content.match("^ruby '(?<version>[0-9.]*)'")
|
61
|
+
if match
|
62
|
+
ruby_version = "ruby-" + match["version"]
|
63
|
+
end
|
64
|
+
end
|
55
65
|
end
|
56
|
-
|
66
|
+
ruby_version
|
57
67
|
end
|
58
68
|
|
59
|
-
def
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
data = Readline.readline("#{prompt}: ")
|
67
|
-
return data.chomp
|
68
|
-
end
|
69
|
+
def to_h(value)
|
70
|
+
value ? "yes" : "no"
|
71
|
+
end
|
72
|
+
|
73
|
+
def cat_file(filename)
|
74
|
+
File.open(filename, "rb") { |f| f.read } if File.exist?(filename)
|
75
|
+
end
|
@@ -1,5 +1,12 @@
|
|
1
1
|
require 'capistrano/deploy_mate_capfile'
|
2
|
-
<% if @
|
2
|
+
<% if @config['rails'] %>
|
3
3
|
require 'capistrano/rails/assets'
|
4
4
|
require 'capistrano/rails/migrations'
|
5
|
-
<% end %>
|
5
|
+
<% end %>
|
6
|
+
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
|
7
|
+
|
8
|
+
# Optionals
|
9
|
+
# Uncomment, if needed
|
10
|
+
|
11
|
+
# require "whenever/capistrano"
|
12
|
+
# before 'deploy:restart', 'deploy:migrate', 'whenever:update_crontab'
|
@@ -1,7 +1,7 @@
|
|
1
|
-
server "<%= @ssh_name %>", roles: [:app, :
|
1
|
+
server "<%= @config['ssh_name'] %>", roles: [:app, :db, :web<% if @config['elasticsearch'] %>, :search<% end %>], :primary => true
|
2
2
|
|
3
3
|
set :unicorn_workers, "2"
|
4
|
-
set :nginx_server_name, "<%= @host_name %>"
|
4
|
+
set :nginx_server_name, "<%= @config['host_name'] %>"
|
5
5
|
|
6
|
-
set :environment, "<%= @environment %>"
|
7
|
-
set :branch, "<%= @branch_name %>"
|
6
|
+
set :environment, "<%= @config['environment'] %>"
|
7
|
+
set :branch, ENV.fetch("branch", "<%= @config['branch_name'] %>")
|
@@ -1,9 +1,27 @@
|
|
1
1
|
# NOTE: copy this file to /config/deploy.rb
|
2
|
-
set :application, '<%= @app_name %>'
|
2
|
+
set :application, '<%= @config['app_name'] %>'
|
3
3
|
|
4
4
|
require "capistrano/deploy_mate_defaults"
|
5
5
|
|
6
|
+
set :rvm_ruby_version, '<%= @config['ruby_version'] %>'
|
7
|
+
|
6
8
|
# Set app specific vars
|
7
|
-
set :stages, %w(<%= @stage_name %>)
|
8
|
-
set :default_stage, '<%= @stage_name %>'
|
9
|
-
set :repo_url, '<%= @repo_url %>'
|
9
|
+
set :stages, %w(<%= @config['stage_name'] %>)
|
10
|
+
set :default_stage, '<%= @config['stage_name'] %>'
|
11
|
+
set :repo_url, '<%= @config['repo_url'] %>'
|
12
|
+
set :db_engine, '<%= @config['db_engine'] %>'
|
13
|
+
set :app_server, '<%= @config['app_server'] %>'
|
14
|
+
|
15
|
+
set :imagemagick, <%= @config['imagemagick'] %>
|
16
|
+
set :memcached, <%= @config['memcached'] %>
|
17
|
+
set :sidekiq, <%= @config['sidekiq'] %>
|
18
|
+
|
19
|
+
set :ssh_file_names, [<%= @config['ssh_file_names'].to_a.map { |file| "'#{file}'" }.join(', ') %>]
|
20
|
+
|
21
|
+
# Optionals
|
22
|
+
# Uncomment, if needed
|
23
|
+
|
24
|
+
# set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" }
|
25
|
+
# set :whenever_environment, fetch(:stage)
|
26
|
+
# set :whenever_roles, [:cronjobs]
|
27
|
+
# before "whenever:update_crontab", 'rvm:hook'
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# This file represents your application deployment configuration and
|
2
|
+
# will be used to generate the capistrano deployment and server setup.
|
3
|
+
# Please go through this file and when you are ready execute:
|
4
|
+
#
|
5
|
+
# bundle exec rake deploy_mate:install
|
6
|
+
|
7
|
+
---
|
8
|
+
|
9
|
+
# Name of the application, which is usually the same as the
|
10
|
+
# repository name.
|
11
|
+
app_name: <%= @app_name %>
|
12
|
+
|
13
|
+
# The url of your GIT repository.
|
14
|
+
repo_url: "git@github.com:your-github-name/<%= @app_name %>.git"
|
15
|
+
|
16
|
+
# For which stage should the server-setup/deployment be generated. It is
|
17
|
+
# recommended to start with a prestage system and afterwards configure
|
18
|
+
# the production system when it is ready.
|
19
|
+
stage_name: prestage
|
20
|
+
|
21
|
+
# Under which rails environment will the application run.
|
22
|
+
environment: prestage
|
23
|
+
|
24
|
+
# Which GIT branch should be deployed to the defined server by default?
|
25
|
+
# You can overrule this value by providing a branch on the deployment command:
|
26
|
+
#
|
27
|
+
# bundle exec cap prestage deploy branch=feature/xyz
|
28
|
+
branch_name: dev
|
29
|
+
|
30
|
+
# Which is the ssh shortcut to connect to the server. It should be configured
|
31
|
+
# in your ~/.ssh/config. You should be able to connect to the server using:
|
32
|
+
#
|
33
|
+
# ssh specified_ssh_name
|
34
|
+
#
|
35
|
+
ssh_name: prestage-server
|
36
|
+
|
37
|
+
# Since you are able to connect to the server with the specified ssh shortcurt,
|
38
|
+
# usually more persons should be able to access it. You can specify a list of
|
39
|
+
# public ssh keys which will be copied to the ~/.ssh/authorized_keys file on the
|
40
|
+
# server. If the list is empty, the current key setting will be left untouched on
|
41
|
+
# the server.
|
42
|
+
ssh_file_names:
|
43
|
+
- "~/.ssh/*.pub"
|
44
|
+
|
45
|
+
# Under which URL should your server be available? An IP address does the job
|
46
|
+
# too
|
47
|
+
host_name: example.com
|
48
|
+
|
49
|
+
# The ruby version, that will be installed and used on the server. It is used
|
50
|
+
# by RVM and must have a compatible syntax like '2.3.0' or 'ruby-2.3.0'.
|
51
|
+
ruby_version: <%= @ruby_version %>
|
52
|
+
|
53
|
+
# Currently there are two database engines supported: 'postgresql' and 'mysql'
|
54
|
+
db_engine: postgresql
|
55
|
+
|
56
|
+
# Currently there are two appservers supported: 'unicorn' and 'puma'.
|
57
|
+
# Remember to add the chosen appserver to your Gemfile if you are not
|
58
|
+
# already using it locally.
|
59
|
+
app_server: unicorn
|
60
|
+
|
61
|
+
# Are your running a rails application?
|
62
|
+
# Possible values 'yes' or 'no'.
|
63
|
+
rails: <%= @rails %>
|
64
|
+
|
65
|
+
# Are you depending on imagemagick for image manipulation (E.g. paperclip gem)?
|
66
|
+
# Possible values 'yes' or 'no'.
|
67
|
+
imagemagick: <%= @imagemagick %>
|
68
|
+
|
69
|
+
# Are you depending on sidekiq (E.g. as active job backend)?
|
70
|
+
# Possible values 'yes' or 'no'.
|
71
|
+
sidekiq: <%= @sidekiq %>
|
72
|
+
|
73
|
+
# Are you depending on elastic search?
|
74
|
+
# Possible values 'yes' or 'no'.
|
75
|
+
elasticsearch: no
|
76
|
+
|
77
|
+
# Are you depending on memcached for example as a cache store?
|
78
|
+
# Possible values 'yes' or 'no'.
|
79
|
+
memcached: <%= @memcached %>
|