deployinator 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  set :deploy_log_level, "debug"
2
2
  set :webserver_socket_path, -> { shared_path.join('run') }
3
3
  set :deploy_templates_path, "templates/deploy"
4
+ set :jobs_app_name, "jobs"
4
5
 
5
6
  # Default deploy_to directory is /var/www/my_app
6
7
  # set :deploy_to, '/var/www/my_app'
@@ -81,6 +82,33 @@ def deploy_run_bluepill(host)
81
82
  current_path.join('config', 'bluepill.rb')
82
83
  )
83
84
  end
85
+ def deploy_bluepill_restart(host)
86
+ execute("docker", "exec", "--tty",
87
+ fetch(:ruby_container_name),
88
+ shared_path.join('bundle', 'bin', 'bluepill'),
89
+ fetch(:application), "restart")
90
+ end
91
+ def deploy_bluepill_stop(host)
92
+ execute("docker", "exec", "--tty",
93
+ fetch(:ruby_container_name),
94
+ shared_path.join('bundle', 'bin', 'bluepill'),
95
+ fetch(:application), "stop")
96
+ end
97
+ def deploy_run_bluepill_jobs(host)
98
+ execute(
99
+ "docker", "run", "--tty", "--detach",
100
+ "--name", fetch(:ruby_jobs_container_name),
101
+ "-e", "GEM_HOME=#{shared_path.join('bundle')}",
102
+ "-e", "GEM_PATH=#{shared_path.join('bundle')}",
103
+ "-e", "BUNDLE_GEMFILE=#{current_path.join('Gemfile')}",
104
+ "-e", "PATH=#{shared_path.join('bundle', 'bin')}:$PATH",
105
+ "--restart", "always", "--memory", "#{fetch(:ruby_jobs_container_max_mem_mb)}m",
106
+ "--volume", "#{fetch(:deploy_to)}:#{fetch(:deploy_to)}:rw",
107
+ "--entrypoint", shared_path.join('bundle', 'bin', 'rabid_jobs_tasker'),
108
+ fetch(:ruby_image_name), "--rails_root", current_path,
109
+ "--environment", fetch(:rails_env), "--pid", "#{fetch(:webserver_socket_path)}/jobs.pid"
110
+ )
111
+ end
84
112
  def deploy_run_cadvisor(host)
85
113
  execute(
86
114
  "docker", "run", "--detach",
@@ -172,15 +200,3 @@ def deploy_install_bundler(host)
172
200
  "--bindir", shared_path.join('bundle', 'bin'),
173
201
  "--no-ri", "--no-rdoc", "--quiet", "bundler", "-v'#{fetch(:bundler_version)}'\"")
174
202
  end
175
- def deploy_bluepill_restart(host)
176
- execute("docker", "exec", "--tty",
177
- fetch(:ruby_container_name),
178
- shared_path.join('bundle', 'bin', 'bluepill'),
179
- fetch(:application), "restart")
180
- end
181
- def deploy_bluepill_stop(host)
182
- execute("docker", "exec", "--tty",
183
- fetch(:ruby_container_name),
184
- shared_path.join('bundle', 'bin', 'bluepill'),
185
- fetch(:application), "stop")
186
- end
@@ -1,7 +1,7 @@
1
1
  namespace :deploy do
2
2
  namespace :check do
3
3
 
4
- task :bundle_command_map => ['deployinator:deployment_user'] do
4
+ task :bundle_command_map do
5
5
  set :bundle_binstubs, -> { shared_path.join('bundle', 'bin') }
6
6
  set :bundle_gemfile, -> { release_path.join('Gemfile') }
7
7
  SSHKit.config.command_map[:bundle] = sshkit_bundle_command_map
@@ -40,15 +40,13 @@ namespace :deploy do
40
40
  # TODO make this better
41
41
  before 'deploy:check', :templates do
42
42
  run_locally do
43
- keys_template = File.expand_path("./#{fetch(:deploy_templates_path)}/deployment_authorized_keys.erb")
44
- bluepill_template = File.expand_path("./#{fetch(:deploy_templates_path)}/bluepill.rb.erb")
45
- unicorn_template = File.expand_path("./#{fetch(:deploy_templates_path)}/unicorn.rb.erb")
46
- {
47
- "You need a #{fetch(:deploy_templates_path)}/deployment_authorized_keys.erb file." => keys_template,
48
- "You need a #{fetch(:deploy_templates_path)}/bluepill.rb.erb file." => bluepill_template,
49
- "You need a #{fetch(:deploy_templates_path)}/unicorn.rb.erb file." => unicorn_template,
50
- }.each do |message, file|
51
- fatal(message) and raise unless File.exists? file
43
+ path = fetch(:deploy_templates_path)
44
+ keys_template = File.expand_path("./#{path}/deployment_authorized_keys.erb")
45
+ bluepill_template = File.expand_path("./#{path}/bluepill.rb.erb")
46
+ unicorn_template = File.expand_path("./#{path}/unicorn.rb.erb")
47
+ templates = [keys_template, bluepill_template, unicorn_template]
48
+ templates.each do |file|
49
+ fatal("You need a #{file} template file.") and raise unless File.exists? file
52
50
  end
53
51
  end
54
52
  end
@@ -18,22 +18,25 @@ namespace :deployinator do
18
18
  desc 'Write example config files'
19
19
  task :write_example_configs do
20
20
  run_locally do
21
- execute "mkdir", "-p", "config/deploy", fetch(:deploy_templates_path, 'templates/deploy')
21
+ path = fetch(:deploy_templates_path, 'templates/deploy')
22
+ execute "mkdir", "-p", "config/deploy", path
22
23
  {
23
24
  "examples/Capfile" => "Capfile#{fetch(:example)}",
24
25
  "examples/config/deploy.rb" => "config/deploy#{fetch(:example)}.rb",
25
26
  "examples/config/deploy/staging.rb" => "config/deploy/staging#{fetch(:example)}.rb",
26
- "examples/Dockerfile" => "#{fetch(:deploy_templates_path, 'templates/deploy')}/Dockerfile#{fetch(:example)}",
27
- "examples/deployment_authorized_keys.erb" => "#{fetch(:deploy_templates_path, 'templates/deploy')}/deployment_authorized_keys#{fetch(:example)}.erb",
28
- "examples/unicorn.rb.erb" => "#{fetch(:deploy_templates_path, 'templates/deploy')}/unicorn#{fetch(:example)}.rb.erb",
29
- "examples/bluepill.rb.erb" => "#{fetch(:deploy_templates_path, 'templates/deploy')}/bluepill#{fetch(:example)}.rb.erb"
27
+ "examples/Dockerfile" => "#{path}/Dockerfile#{fetch(:example)}",
28
+ "examples/deployment_authorized_keys.erb" =>
29
+ "#{path}/deployment_authorized_keys#{fetch(:example)}.erb",
30
+ "examples/unicorn.rb.erb" => "#{path}/unicorn#{fetch(:example)}.rb.erb",
31
+ "examples/bluepill.rb.erb" => "#{path}/bluepill#{fetch(:example)}.rb.erb",
30
32
  }.each do |source, destination|
31
33
  config = File.read(File.dirname(__FILE__) + "/#{source}")
32
34
  File.open("./#{destination}", 'w') { |f| f.write(config) }
33
35
  info "Wrote '#{destination}'"
34
36
  end
35
37
  unless fetch(:example).empty?
36
- info "Now remove the '#{fetch(:example)}' portion of their names or diff with existing files and add the needed lines."
38
+ info("Now remove the '#{fetch(:example)}' portion of their names " +
39
+ "or diff with existing files and add the needed lines.")
37
40
  end
38
41
  end
39
42
  end
@@ -35,7 +35,7 @@ namespace :deploy do
35
35
  # Overwrite :assets:precompile to use docker
36
36
  Rake::Task["deploy:assets:precompile"].clear_actions
37
37
  namespace :assets do
38
- task :precompile => ['deployinator:deployment_user'] do
38
+ task :precompile do
39
39
  on roles(fetch(:assets_roles)) do |host|
40
40
  deploy_assets_precompile(host)
41
41
  end
@@ -72,7 +72,7 @@ namespace :deploy do
72
72
  end
73
73
  end
74
74
 
75
- task :install_bundler => ['deployinator:deployment_user'] do
75
+ task :install_bundler do
76
76
  on roles(:app) do |host|
77
77
  unless file_exists?(shared_path.join('bundle', 'bin', 'bundle'))
78
78
  deploy_install_bundler(host)
@@ -82,7 +82,7 @@ namespace :deploy do
82
82
  before 'bundler:install', 'deploy:install_bundler'
83
83
 
84
84
  desc 'Restart application using bluepill restart inside the docker container.'
85
- task :restart => ['deployinator:webserver_user', :install_config_files] do
85
+ task :restart => [:install_config_files, 'deploy:check:settings'] do
86
86
  on roles(:app) do |host|
87
87
  name = fetch(:ruby_container_name)
88
88
  if container_exists?(name)
@@ -108,22 +108,22 @@ namespace :deploy do
108
108
 
109
109
  desc 'Restart application by recreating the docker container.'
110
110
  namespace :restart do
111
- task :force do
111
+ task :force => [:install_config_files, 'deploy:check:settings'] do
112
112
  on roles(:app) do |host|
113
- if container_exists?(fetch(:ruby_container_name))
114
- if container_is_running?(fetch(:ruby_container_name))
113
+ name = fetch(:ruby_container_name)
114
+ if container_exists?(name)
115
+ if container_is_running?(name)
115
116
  deploy_bluepill_stop(host)
116
117
  sleep 5
117
- execute("docker", "stop", fetch(:ruby_container_name))
118
- execute("docker", "wait", fetch(:ruby_container_name))
119
- else
118
+ execute("docker", "stop", name)
119
+ execute("docker", "wait", name)
120
120
  end
121
121
  begin
122
- execute("docker", "rm", fetch(:ruby_container_name))
122
+ execute("docker", "rm", name)
123
123
  rescue
124
124
  sleep 5
125
125
  begin
126
- execute("docker", "rm", fetch(:ruby_container_name))
126
+ execute("docker", "rm", name)
127
127
  rescue
128
128
  fatal "We were not able to remove the container for some reason. Try running 'cap <stage> deploy:restart:force' again."
129
129
  end
@@ -143,12 +143,9 @@ namespace :deploy do
143
143
  # end
144
144
  # end
145
145
 
146
- task :install_config_files => ['deployinator:deployment_user', 'deployinator:webserver_user'] do
146
+ task :install_config_files do
147
147
  on roles(:app) do |host|
148
- set :bluepill_config, -> { "bluepill.rb" }
149
- set :unicorn_config, -> { "unicorn.rb" }
150
- set :socket_path, -> { fetch(:webserver_socket_path) }
151
- [fetch(:bluepill_config), fetch(:unicorn_config)].each do |config_file|
148
+ ["bluepill.rb", "unicorn.rb"].each do |config_file|
152
149
  template_path = File.expand_path("./#{fetch(:deploy_templates_path)}/#{config_file}.erb")
153
150
  generated_config_file = ERB.new(File.new(template_path).read).result(binding)
154
151
  set :final_path, -> { release_path.join('config', config_file) }
@@ -22,6 +22,7 @@ require 'capistrano/rails/assets'
22
22
  require 'capistrano/rails/migrations'
23
23
 
24
24
  require 'deployinator'
25
+ require 'deployinator/jobs'
25
26
 
26
27
  # Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
27
28
  Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
@@ -1,4 +1,3 @@
1
- # vi: ft=config
2
1
  FROM ubuntu:12.04
3
2
  MAINTAINER david amick <docker@davidamick.com>
4
3
 
@@ -1,12 +1,15 @@
1
1
  ##### deployinator
2
2
  ### ------------------------------------------------------------------
3
- set :domain, "my-app-staging.example.com"
3
+ set :domain, "my-app-staging.example.com"
4
4
  server fetch(:domain),
5
- :user => fetch(:deployment_username),
6
- :roles => ["app", "web", "db"]
7
- set :rails_env, 'production'
8
- set :ruby_image_name, "snarlysodboxer/ruby:1.9.3-p547"
9
- set :ruby_container_name, "#{fetch(:domain)}-ruby-bluepill"
10
- set :ruby_container_max_mem_mb, "1024"
11
- set :postgres_port, "5432"
5
+ :user => fetch(:deployment_username),
6
+ :roles => ["app", "web", "db"]
7
+ set :rails_env, 'production'
8
+ set :ruby_image_name, "snarlysodboxer/ruby:1.9.3-p547"
9
+ set :ruby_container_name, "#{fetch(:domain)}-ruby-bluepill"
10
+ set :ruby_container_max_mem_mb, "1024"
11
+ set :postgres_port, "5432"
12
+ ### deployinator jobs
13
+ set :ruby_jobs_container_name, "#{fetch(:domain)}-ruby-bluepill_jobs"
14
+ set :ruby_jobs_container_max_mem_mb, "512"
12
15
  ### ------------------------------------------------------------------
@@ -0,0 +1,55 @@
1
+ namespace :deploy do
2
+ namespace :jobs do
3
+
4
+ desc 'Restart jobs using bluepill restart inside the docker container.'
5
+ task :restart => ['deploy:check:settings'] do
6
+ on roles(:app) do |host|
7
+ name = fetch(:ruby_jobs_container_name)
8
+ if container_exists?(name)
9
+ if container_is_restarting?(name)
10
+ execute("docker", "stop", name)
11
+ end
12
+ if container_is_running?(name)
13
+ restart_container(fetch(:ruby_jobs_container_name))
14
+ else
15
+ start_container(name)
16
+ end
17
+ else
18
+ as :root do
19
+ execute("rm", "-f", fetch(:webserver_socket_path).join('jobs.pid'))
20
+ end
21
+ warn "Starting a new container named #{name} on #{host}"
22
+ deploy_run_bluepill_jobs(host)
23
+ check_stayed_running(name)
24
+ end
25
+ end
26
+ end
27
+ after 'deploy:restart', :restart
28
+
29
+ desc 'Restart application by recreating the docker container.'
30
+ namespace :restart do
31
+ task :force => ['deploy:check:settings'] do
32
+ on roles(:app) do |host|
33
+ name = fetch(:ruby_jobs_container_name)
34
+ if container_exists?(name)
35
+ if container_is_running?(name)
36
+ execute("docker", "stop", name)
37
+ end
38
+ begin
39
+ execute("docker", "rm", name)
40
+ rescue
41
+ sleep 5
42
+ begin
43
+ execute("docker", "rm", name)
44
+ rescue
45
+ fatal "We were not able to remove the container for some reason. Try running 'cap <stage> deploy:jobs:restart:force' again."
46
+ end
47
+ end
48
+ end
49
+ Rake::Task['deploy:jobs:restart'].invoke
50
+ end
51
+ end
52
+ end
53
+
54
+ end
55
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deployinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-17 00:00:00.000000000 Z
12
+ date: 2015-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -71,6 +71,7 @@ files:
71
71
  - lib/deployinator/config.rb
72
72
  - lib/deployinator/helpers.rb
73
73
  - lib/deployinator/built-in.rb
74
+ - lib/deployinator/jobs.rb
74
75
  - lib/deployinator/examples/Capfile
75
76
  - lib/deployinator/examples/config/deploy.rb
76
77
  - lib/deployinator/examples/config/deploy/staging.rb