Class: Dockerploy::Deploy
- Inherits:
-
Object
- Object
- Dockerploy::Deploy
- Defined in:
- lib/dockerploy/deploy.rb
Constant Summary collapse
- SSH_PORT =
22- HTTP_PORT =
80
Instance Method Summary collapse
- #deploy ⇒ Object
- #destroy(ssh_client, server) ⇒ Object
-
#initialize(config, options = {}) ⇒ Deploy
constructor
A new instance of Deploy.
- #run(ssh_client, server) ⇒ Object
- #run_after_hooks(server) ⇒ Object
- #run_before_hooks(server) ⇒ Object
- #run_hook(server, hook) ⇒ Object
Constructor Details
#initialize(config, options = {}) ⇒ Deploy
Returns a new instance of Deploy.
6 7 8 9 |
# File 'lib/dockerploy/deploy.rb', line 6 def initialize(config, = {}) @config = config = end |
Instance Method Details
#deploy ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dockerploy/deploy.rb', line 29 def deploy create_tag if @config.tagging? @config.servers.each do |server| run_before_hooks(server) ssh_client = SSHClient.new(server[:host], server[:username], server[:password], server[:port]) destroy(ssh_client, server) run(ssh_client, server) run_after_hooks(server) end end |
#destroy(ssh_client, server) ⇒ Object
11 12 13 14 |
# File 'lib/dockerploy/deploy.rb', line 11 def destroy(ssh_client, server) container_name = sprintf('%s_%s', @config.application_name, server[:container][:http_port]) ssh_client.command(sprintf('docker rm -f %s', container_name)) end |
#run(ssh_client, server) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dockerploy/deploy.rb', line 16 def run(ssh_client, server) option_delimiter = ' ' command = sprintf('docker run -d --name %s_%s', @config.application_name, server[:container][:http_port]) command << option_delimiter + hostname_option command << option_delimiter + port_option(server) command << option_delimiter + volume_option command << option_delimiter + environment_variables_option custom_variables = custom_environment_variables_option(server) command << option_delimiter + custom_variables if custom_variables.length > 0 command << option_delimiter + image_name ssh_client.command(command) end |
#run_after_hooks(server) ⇒ Object
45 46 47 48 |
# File 'lib/dockerploy/deploy.rb', line 45 def run_after_hooks(server) @config.after_all_hooks.each { |hook| run_hook(server, hook) } @config.after_hooks.each { |hook| run_hook(server, hook) } end |
#run_before_hooks(server) ⇒ Object
40 41 42 43 |
# File 'lib/dockerploy/deploy.rb', line 40 def run_before_hooks(server) @config.before_all_hooks.each { |hook| run_hook(server, hook) } @config.before_hooks.each { |hook| run_hook(server, hook) } end |
#run_hook(server, hook) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dockerploy/deploy.rb', line 50 def run_hook(server, hook) if hook[:local] hook[:local].each do |command| ShellClient.new(abort_on_failure: true).command(command) end elsif hook[:remote] hook[:remote].each do |command| SSHClient.new(server[:host], server[:username], server[:password], server[:port]).command(command) end end end |