Class: DockerDeploy::Stage

Inherits:
Object
  • Object
show all
Includes:
Rake::FileUtilsExt
Defined in:
lib/docker_deploy/stage.rb

Direct Known Subclasses

LocalStage, RemoteStage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, name) ⇒ Stage

Returns a new instance of Stage.



7
8
9
10
11
12
13
14
15
16
# File 'lib/docker_deploy/stage.rb', line 7

def initialize(context, name)
  @context = context
  @name = name
  @env_files = []
  @services = []
  @variables = {}
  @ports = {}
  @links = {}
  @deploy = ["docker:build", "docker:push", :pull, :restart]
end

Instance Attribute Details

#container(name = nil) ⇒ Object (readonly)

Returns the value of attribute container.



5
6
7
# File 'lib/docker_deploy/stage.rb', line 5

def container
  @container
end

#deployObject (readonly)

Returns the value of attribute deploy.



5
6
7
# File 'lib/docker_deploy/stage.rb', line 5

def deploy
  @deploy
end

#env_filesObject (readonly)

Returns the value of attribute env_files.



5
6
7
# File 'lib/docker_deploy/stage.rb', line 5

def env_files
  @env_files
end

Returns the value of attribute links.



5
6
7
# File 'lib/docker_deploy/stage.rb', line 5

def links
  @links
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/docker_deploy/stage.rb', line 5

def name
  @name
end

#serversObject (readonly)

Returns the value of attribute servers.



5
6
7
# File 'lib/docker_deploy/stage.rb', line 5

def servers
  @servers
end

#servicesObject (readonly)

Returns the value of attribute services.



5
6
7
# File 'lib/docker_deploy/stage.rb', line 5

def services
  @services
end

#variablesObject (readonly)

Returns the value of attribute variables.



5
6
7
# File 'lib/docker_deploy/stage.rb', line 5

def variables
  @variables
end

Instance Method Details

#env(variables = {}) ⇒ Object



18
19
20
# File 'lib/docker_deploy/stage.rb', line 18

def env(variables = {})
  @variables.merge!(variables)
end

#env_file(env_file) ⇒ Object



30
31
32
# File 'lib/docker_deploy/stage.rb', line 30

def env_file(env_file)
  @env_files.push(env_file)
end

#host(name = nil) ⇒ Object



34
35
36
37
# File 'lib/docker_deploy/stage.rb', line 34

def host(name = nil)
  @host = name if name
  @host
end


26
27
28
# File 'lib/docker_deploy/stage.rb', line 26

def link(links = {})
  @links.merge!(links)
end


39
40
41
# File 'lib/docker_deploy/stage.rb', line 39

def link_mappings
  DockerDeploy.format_params("--link %s:%s", @context.links.merge(@links))
end

#optionsObject



47
48
49
50
# File 'lib/docker_deploy/stage.rb', line 47

def options
  DockerDeploy.format_params("--env-file %s", @context.env_files + @env_files) + " " +
  DockerDeploy.format_params("-e %s=%s", @context.variables.merge(@variables))
end

#port(ports = {}) ⇒ Object



22
23
24
# File 'lib/docker_deploy/stage.rb', line 22

def port(ports = {})
  @ports.merge!(ports)
end

#port_mappingsObject



43
44
45
# File 'lib/docker_deploy/stage.rb', line 43

def port_mappings
  DockerDeploy.format_params("-p %s:%s", @context.ports.merge(@ports))
end

#service(name, &block) ⇒ Object



57
58
59
60
61
# File 'lib/docker_deploy/stage.rb', line 57

def service(name, &block)
  service = Service.new(self, name)
  service.instance_eval(&block)
  @services << service
end