deploy_mate 0.2 → 0.11

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Gemfile.lock +7 -9
  4. data/README.md +37 -46
  5. data/deploy-mate.gemspec +7 -4
  6. data/lib/capistrano/configs/logrotate.erb +2 -2
  7. data/lib/capistrano/configs/nginx_app.conf.erb +4 -9
  8. data/lib/capistrano/configs/nginx_base.conf.erb +1 -1
  9. data/lib/capistrano/configs/unicorn.pill.erb +28 -0
  10. data/lib/capistrano/configs/upstart.conf.erb +1 -1
  11. data/lib/capistrano/deploy_mate_capfile.rb +2 -2
  12. data/lib/capistrano/deploy_mate_defaults.rb +4 -5
  13. data/lib/capistrano/helpers.rb +2 -4
  14. data/lib/capistrano/scripts/set_defaults.sh +1 -2
  15. data/lib/capistrano/tasks/bluepill.rake +5 -29
  16. data/lib/capistrano/tasks/logrotate.rake +0 -1
  17. data/lib/capistrano/tasks/machine.rake +17 -91
  18. data/lib/capistrano/tasks/nginx.rake +4 -7
  19. data/lib/capistrano/tasks/unicorn.rake +17 -1
  20. data/lib/capistrano/tasks/upstart.rake +0 -2
  21. data/lib/deploy_mate/tasks.rake +50 -49
  22. data/lib/deploy_mate/templates/Capfile.erb +1 -7
  23. data/lib/deploy_mate/templates/deploy.rb.erb +5 -22
  24. data/lib/deploy_mate/templates/deploy/stage.rb.erb +4 -4
  25. metadata +5 -19
  26. data/CHANGELOG.md +0 -19
  27. data/lib/capistrano/configs/application.pill.erb +0 -59
  28. data/lib/capistrano/configs/fail2ban-nginx-request-limit-filter.conf.erb +0 -13
  29. data/lib/capistrano/configs/fail2ban-nginx-request-limit-jail.conf.erb +0 -494
  30. data/lib/capistrano/configs/puma.rb.erb +0 -64
  31. data/lib/capistrano/modules/shell.rb +0 -7
  32. data/lib/capistrano/modules/user_management.rb +0 -11
  33. data/lib/capistrano/scripts/create_ubuntu_user.sh +0 -9
  34. data/lib/capistrano/tasks/elasticsearch.rake +0 -18
  35. data/lib/capistrano/tasks/fail2ban.rake +0 -22
  36. data/lib/capistrano/tasks/puma.rake +0 -18
  37. data/lib/deploy_mate.rb +0 -9
  38. data/lib/deploy_mate/templates/deploy_mate.yml.erb +0 -79
@@ -1,31 +1,28 @@
1
1
  set_default(:nginx_server_name, "*.*")
2
2
 
3
3
  namespace :nginx do
4
- include Shell
5
4
 
6
5
  desc "Installs the nginx configs"
7
6
  task :setup do
8
7
  on roles(:web) do
9
8
  template "nginx_base.conf.erb", "/tmp/nginx_conf"
10
9
  sudo "mv /tmp/nginx_conf /etc/nginx/nginx.conf"
11
-
12
10
  template "nginx_app.conf.erb", "/tmp/#{fetch(:application)}_conf"
13
11
  sudo "mv /tmp/#{fetch(:application)}_conf /etc/nginx/sites-available/#{fetch(:application)}.conf"
14
12
 
15
- if file_exists? "/etc/nginx/sites-enabled/default"
13
+ if test("[ -f /etc/nginx/sites-enabled/default ]")
16
14
  sudo "rm /etc/nginx/sites-enabled/default"
17
15
  end
18
16
 
19
- execute "mkdir -p #{shared_path}/log"
17
+ invoke "nginx:enable_site"
18
+ invoke "nginx:reload"
20
19
  end
21
- invoke "nginx:enable_site"
22
- invoke "nginx:reload"
23
20
  end
24
21
 
25
22
  desc "Enable the app page for nginx"
26
23
  task :enable_site do
27
24
  on roles(:web) do
28
- unless file_exists? "/etc/nginx/sites-enabled/#{fetch(:application)}.conf"
25
+ unless test("[ -f /etc/nginx/sites-enabled/#{fetch(:application)}.conf ]")
29
26
  sudo "ln -sf /etc/nginx/sites-available/#{fetch(:application)}.conf /etc/nginx/sites-enabled/#{fetch(:application)}.conf"
30
27
  end
31
28
  end
@@ -4,7 +4,6 @@ set_default(:unicorn_worker_grace_time, "60")
4
4
 
5
5
  namespace :unicorn do
6
6
  include Bluepill
7
- include Shell
8
7
 
9
8
  desc "Installs the unicorn config"
10
9
  task :setup do
@@ -14,4 +13,21 @@ namespace :unicorn do
14
13
  end
15
14
  end
16
15
 
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
+
17
33
  end
@@ -1,8 +1,6 @@
1
1
  namespace :upstart do
2
2
  include Upstart
3
- include Shell
4
3
 
5
- # TODO: remove one of these - they do the same
6
4
  desc "Install the upstart config"
7
5
  task :setup do
8
6
  on roles(:app) do
@@ -1,48 +1,47 @@
1
+ require 'readline'
2
+
1
3
  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?)
10
4
 
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
5
+ desc 'Installs the needed capistrano files to deploy with the mate.'
6
+ task :install do |t,args|
7
+ puts "I'm your DEPLOY_MATE."
8
+ puts "We will setting up your deployment now."
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
+ @db_engine = ask_until("What db are you using?", %w( postgresql mysql ), "mysql")
15
20
 
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"
21
+ puts "Aye!"
22
+ puts "Worrrrking..."
23
+
24
+ config_template("Capfile.erb", "Capfile")
25
+ sleep 1
26
+ config_template("deploy.rb.erb", "config/deploy.rb")
27
+ sleep 1
19
28
  FileUtils.mkdir_p("config/deploy") unless File.exists?("config/deploy")
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")
29
+ config_template("deploy/stage.rb.erb", "config/deploy/#{@stage_name}.rb")
30
+ sleep 1
31
+
32
+ puts "Arr, be dun working!"
23
33
  end
34
+
24
35
  end
25
36
 
26
37
  def config_template(from, to)
27
38
  erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
28
39
  compiled = ERB.new(erb).result(binding)
29
40
  File.open(to, "wb") { |f| f.write(compiled) }
30
- to
41
+ puts "'#{to}'"
31
42
  end
32
43
 
33
- def sidekiq?
34
- defined? Sidekiq
35
- end
36
-
37
- def imagemagick?
38
- defined? RMagick || defined? MiniMagick
39
- end
40
-
41
- def memcached?
42
- defined? Dalli
43
- end
44
-
45
- def rails?
44
+ def rails_present?
46
45
  defined? Rails
47
46
  end
48
47
 
@@ -50,26 +49,28 @@ def guess_app_name
50
49
  Dir.pwd.split(File::SEPARATOR).last
51
50
  end
52
51
 
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
52
+ def yes_or_no?(prompt, default = nil)
53
+ answer = "undefined"
54
+ while(!["yes", "no"].include?(answer))
55
+ answer = ask("#{prompt} [yes/no]:", (default == "yes" ? "yes" : "no"))
65
56
  end
66
- ruby_version
57
+ (answer == "yes")
67
58
  end
68
59
 
69
- def to_h(value)
70
- value ? "yes" : "no"
60
+ def ask_until(prompt, answers, default)
61
+ begin
62
+ answer = ask("#{prompt} (#{answers.join(', ')})", default).downcase
63
+ end until answers.include? answer
64
+ answer
71
65
  end
72
66
 
73
- def cat_file(filename)
74
- File.open(filename, "rb") { |f| f.read } if File.exist?(filename)
67
+ def ask(prompt, default = nil)
68
+ if default
69
+ Readline.pre_input_hook = -> {
70
+ Readline.insert_text(default)
71
+ Readline.redisplay
72
+ }
73
+ end
74
+ data = Readline.readline("#{prompt}: ")
75
+ return data.chomp
75
76
  end
@@ -1,12 +1,6 @@
1
1
  require 'capistrano/deploy_mate_capfile'
2
- <% if @config['rails'] %>
2
+ <% if @is_rails %>
3
3
  require 'capistrano/rails/assets'
4
4
  require 'capistrano/rails/migrations'
5
5
  <% end %>
6
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,27 +1,10 @@
1
1
  # NOTE: copy this file to /config/deploy.rb
2
- set :application, '<%= @config['app_name'] %>'
2
+ set :application, '<%= @app_name %>'
3
3
 
4
4
  require "capistrano/deploy_mate_defaults"
5
5
 
6
- set :rvm_ruby_version, '<%= @config['ruby_version'] %>'
7
-
8
6
  # Set app specific vars
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'
7
+ set :stages, %w(<%= @stage_name %>)
8
+ set :default_stage, '<%= @stage_name %>'
9
+ set :repo_url, '<%= @repo_url %>'
10
+ set :db_engine, '<%= @db_engine %>'
@@ -1,7 +1,7 @@
1
- server "<%= @config['ssh_name'] %>", roles: [:app, :db, :web<% if @config['elasticsearch'] %>, :search<% end %>], :primary => true
1
+ server "<%= @ssh_name %>", roles: [:app, :web, :db], :primary => true
2
2
 
3
3
  set :unicorn_workers, "2"
4
- set :nginx_server_name, "<%= @config['host_name'] %>"
4
+ set :nginx_server_name, "<%= @host_name %>"
5
5
 
6
- set :environment, "<%= @config['environment'] %>"
7
- set :branch, ENV.fetch("branch", "<%= @config['branch_name'] %>")
6
+ set :environment, "<%= @environment %>"
7
+ set :branch, "<%= @branch_name %>"
metadata CHANGED
@@ -1,16 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deploy_mate
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.11'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Adler
8
- - Marcus Geißler
9
- - Johannes Strampe
10
8
  autorequire:
11
9
  bindir: bin
12
10
  cert_chain: []
13
- date: 2016-03-22 00:00:00.000000000 Z
11
+ date: 2015-04-02 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
14
  name: capistrano
@@ -69,7 +67,7 @@ dependencies:
69
67
  - !ruby/object:Gem::Version
70
68
  version: '0'
71
69
  description: This is how we deploy around here.
72
- email: development (at) hanseventures (dot) com
70
+ email: tim.adler (at) hanseventures (dot) com
73
71
  executables: []
74
72
  extensions: []
75
73
  extra_rdoc_files: []
@@ -78,20 +76,16 @@ files:
78
76
  - ".rubocop.yml"
79
77
  - ".ruby-gemset"
80
78
  - ".ruby-version"
81
- - CHANGELOG.md
82
79
  - Gemfile
83
80
  - Gemfile.lock
84
81
  - README.md
85
82
  - Rakefile
86
83
  - deploy-mate.gemspec
87
84
  - lib/capistrano/README.md
88
- - lib/capistrano/configs/application.pill.erb
89
- - lib/capistrano/configs/fail2ban-nginx-request-limit-filter.conf.erb
90
- - lib/capistrano/configs/fail2ban-nginx-request-limit-jail.conf.erb
91
85
  - lib/capistrano/configs/logrotate.erb
92
86
  - lib/capistrano/configs/nginx_app.conf.erb
93
87
  - lib/capistrano/configs/nginx_base.conf.erb
94
- - lib/capistrano/configs/puma.rb.erb
88
+ - lib/capistrano/configs/unicorn.pill.erb
95
89
  - lib/capistrano/configs/unicorn.rb.erb
96
90
  - lib/capistrano/configs/upstart.conf.erb
97
91
  - lib/capistrano/deploy_mate_capfile.rb
@@ -99,30 +93,22 @@ files:
99
93
  - lib/capistrano/helpers.rb
100
94
  - lib/capistrano/modules/aptitude.rb
101
95
  - lib/capistrano/modules/bluepill.rb
102
- - lib/capistrano/modules/shell.rb
103
96
  - lib/capistrano/modules/upstart.rb
104
- - lib/capistrano/modules/user_management.rb
105
- - lib/capistrano/scripts/create_ubuntu_user.sh
106
97
  - lib/capistrano/scripts/install_ruby.sh
107
98
  - lib/capistrano/scripts/install_rvm.sh
108
99
  - lib/capistrano/scripts/set_defaults.sh
109
100
  - lib/capistrano/tasks/bluepill.rake
110
- - lib/capistrano/tasks/elasticsearch.rake
111
- - lib/capistrano/tasks/fail2ban.rake
112
101
  - lib/capistrano/tasks/logrotate.rake
113
102
  - lib/capistrano/tasks/machine.rake
114
103
  - lib/capistrano/tasks/nginx.rake
115
- - lib/capistrano/tasks/puma.rake
116
104
  - lib/capistrano/tasks/rvm.rake
117
105
  - lib/capistrano/tasks/seeds.rake
118
106
  - lib/capistrano/tasks/unicorn.rake
119
107
  - lib/capistrano/tasks/upstart.rake
120
- - lib/deploy_mate.rb
121
108
  - lib/deploy_mate/tasks.rake
122
109
  - lib/deploy_mate/templates/Capfile.erb
123
110
  - lib/deploy_mate/templates/deploy.rb.erb
124
111
  - lib/deploy_mate/templates/deploy/stage.rb.erb
125
- - lib/deploy_mate/templates/deploy_mate.yml.erb
126
112
  homepage: https://github.com/hanseventures/deploy-mate
127
113
  licenses:
128
114
  - MIT
@@ -143,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
129
  version: '0'
144
130
  requirements: []
145
131
  rubyforge_project:
146
- rubygems_version: 2.4.5.1
132
+ rubygems_version: 2.4.6
147
133
  signing_key:
148
134
  specification_version: 4
149
135
  summary: This is how we deploy around here.
data/CHANGELOG.md DELETED
@@ -1,19 +0,0 @@
1
- * **0.2 (2016-05-18)**: Configuration moved to YAML-file. SSH-Keys optional. Config-templates overwritable locally.
2
- * **0.18.4 (2016-03-22)**: Added mandatory task to install `ssh_key`s
3
- * **0.18.2 (2016-03-08)**: Added basic DDoS and flooding-proof via nginx `req_limit` and `fail2ban`
4
- * **0.18.1 (2016-03-01)**: Added support for memcached
5
- * **0.18 (2016-02-25)**: Added support for capistrano 3.4, Ask before overwriting existing config-files
6
- * **2016-02-19**: Made selection of a deployed branch possible
7
- * **2016-02-17**: Added support for puma as application server
8
- * **2015-10-12**: Support additional linked-directories
9
- * **2015-08-27**: Small fix for `nginx`-config regarding gzipping of svgs
10
- * **2015-08-14**: Important small fix for `nginx`-config regarding ssl
11
- * **2015-08-07**: Small fix for `rvm`-install
12
- * **2015-08-06**: Support for optional `sidekiq`
13
- * **2015-06-23**: Support for optional `elasticsearch`
14
- * **2015-06-23**: Support for optional `whenever`
15
- * **2015-06-23**: Support for optional `imagemagick`
16
- * **2015-06-23**: Support creation of working `ubuntu` user. Error out if another user than `ubuntu` is used.
17
- * **2015-06-22**: Support for choosing your Ruby-version when creating the `Capfile`. Suggestions come from `.ruby-version` and `Gemfile`.
18
- * **2015-04-29**: Load custom rake tasks from lib/capistrano/tasks directory.
19
- You need to run the generator ```rake deploy_mate:install``` again or add ```Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }``` to your Capfile.
@@ -1,59 +0,0 @@
1
- shared_path = "<%= shared_path %>"
2
- current_path = "<%= current_path %>"
3
-
4
- Bluepill.application("<%= fetch(:application) %>", :log_file => "#{shared_path}/log/bluepill.log") do |app|
5
-
6
- app.working_dir = current_path
7
- app.uid = 'ubuntu'
8
- app.gid = 'www-data'
9
-
10
- <% if fetch(:app_server) == "puma" %>
11
- app.process("puma") do |process|
12
- process.pid_file = "#{shared_path}/system/pids/puma.pid"
13
- process.environment = { 'BUNDLE_GEMFILE' => "#{current_path}/Gemfile" }
14
-
15
- process.start_command = "/home/ubuntu/.rvm/wrappers/default/bundle exec puma -C #{shared_path}/config/puma.rb #{current_path}/config.ru"
16
- process.stop_command = "kill -QUIT {{PID}}"
17
- process.restart_command = "kill -USR2 {{PID}}"
18
-
19
- process.start_grace_time = 10.seconds
20
- process.stop_grace_time = 10.seconds
21
- process.restart_grace_time = 10.seconds
22
-
23
- process.monitor_children do |child_process|
24
- child_process.stop_command = "kill -9 {{PID}}"
25
- child_process.checks :mem_usage, :every => 30.seconds, :below => 500.megabytes, :times => [3,4], :fires => :stop
26
- end
27
- end
28
- <% else %>
29
- app.process("unicorn") do |process|
30
- process.pid_file = "#{shared_path}/system/pids/unicorn.pid"
31
- process.environment = { 'BUNDLE_GEMFILE' => "#{current_path}/Gemfile" }
32
-
33
- process.start_command = "/home/ubuntu/.rvm/wrappers/default/bundle exec unicorn -c #{shared_path}/config/unicorn.rb -E <%= fetch(:environment) %> -D"
34
- process.stop_command = "kill -QUIT {{PID}}"
35
- process.restart_command = "kill -USR2 {{PID}}"
36
-
37
- process.start_grace_time = 10.seconds
38
- process.stop_grace_time = 10.seconds
39
- process.restart_grace_time = 10.seconds
40
-
41
- process.monitor_children do |child_process|
42
- child_process.stop_command = "kill -9 {{PID}}"
43
- child_process.checks :mem_usage, :every => 30.seconds, :below => 500.megabytes, :times => [3,4], :fires => :stop
44
- end
45
- end
46
- <% end %>
47
-
48
- <% if fetch(:sidekiq) %>
49
- app.process("sidekiq") do |process|
50
- process.pid_file = "#{shared_path}/system/pids/sidekiq.pid"
51
- process.start_command = "/home/ubuntu/.rvm/wrappers/default/bundle exec sidekiq -e <%= fetch(:environment) %> -P #{process.pid_file} -d -i 0 -L #{shared_path}/log/sidekiq.log -C #{current_path}/config/sidekiq.yml"
52
- process.start_grace_time = 30.seconds
53
- process.stop_command = "/home/ubuntu/.rvm/wrappers/default/bundle exec sidekiqctl stop #{process.pid_file}"
54
- process.stop_grace_time = 15.seconds
55
- process.restart_grace_time = 45.seconds
56
- end
57
- <% end %>
58
-
59
- end
@@ -1,13 +0,0 @@
1
- # Fail2Ban configuration file
2
- #
3
- # supports: ngx_http_limit_req_module module
4
-
5
- [Definition]
6
-
7
- failregex = limiting requests, excess:.* by zone.*client: <HOST>
8
-
9
- # Option: ignoreregex
10
- # Notes.: regex to ignore. If this regex matches, the line is ignored.
11
- # Values: TEXT
12
- #
13
- ignoreregex =