Class: Dockerploy::Deploy

Inherits:
Object
  • Object
show all
Defined in:
lib/dockerploy/deploy.rb

Constant Summary collapse

SSH_PORT =
22
HTTP_PORT =
80

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Deploy

Returns a new instance of Deploy.



6
7
8
# File 'lib/dockerploy/deploy.rb', line 6

def initialize(config)
  @config = config
end

Instance Method Details

#deployObject



26
27
28
29
30
31
32
33
# File 'lib/dockerploy/deploy.rb', line 26

def deploy
  create_tag if @config.tagging?
  @config.servers.each do |server|
    ssh_client = SSHClient.new(server[:host], server[:username], server[:password], server[:port])
    destroy(ssh_client, server)
    run(ssh_client, server)
  end
end

#destroy(ssh_client, server) ⇒ Object



10
11
12
13
# File 'lib/dockerploy/deploy.rb', line 10

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



15
16
17
18
19
20
21
22
23
24
# File 'lib/dockerploy/deploy.rb', line 15

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
  command << option_delimiter + @config.image_name
  ssh_client.command(command)
end