lib/percheron/actions/exec.rb in percheron-0.7.6 vs lib/percheron/actions/exec.rb in percheron-0.7.7
- old
+ new
@@ -2,47 +2,47 @@
module Actions
class Exec
include Base
- def initialize(container, dependant_containers, scripts, description)
- @container = container
- @dependant_containers = dependant_containers
+ def initialize(unit, dependant_units, scripts, description)
+ @unit = unit
+ @dependant_units = dependant_units
@scripts = scripts
@description = description
end
def execute!
- $logger.debug "Executing #{description} #{scripts.inspect} on '#{container.name}' container"
+ $logger.debug "Executing #{description} #{scripts.inspect} on '#{unit.name}' unit"
results = exec!
- results.compact.empty? ? nil : container
+ results.compact.empty? ? nil : unit
end
private
- attr_reader :container, :dependant_containers, :scripts, :description
+ attr_reader :unit, :dependant_units, :scripts, :description
def exec!
results = []
- started_dependant_containers = start_containers!(dependant_containers)
- results << execute_scripts_on_running_container!
- results << stop_containers!(started_dependant_containers)
+ started_dependant_units = start_units!(dependant_units)
+ results << execute_scripts_on_running_unit!
+ results << stop_units!(started_dependant_units)
results
end
- def execute_scripts_on_running_container!
- container_running = container.running?
- Start.new(container, exec_scripts: false).execute! unless container_running
+ def execute_scripts_on_running_unit!
+ unit_running = unit.running?
+ Start.new(unit, exec_scripts: false).execute! unless unit_running
execute_scripts!
commit_and_tag_new_image!
- Stop.new(container).execute! unless container_running
+ Stop.new(unit).execute! unless unit_running
end
# FIXME
def commit_and_tag_new_image!
- new_image = container.docker_container.commit
- new_image.tag(repo: container.image_repo, tag: container.version.to_s, force: true)
+ new_image = unit.container.commit
+ new_image.tag(repo: unit.image_repo, tag: unit.version.to_s, force: true)
end
def execute_scripts!
scripts.each do |script|
in_working_directory(base_dir) do
@@ -51,32 +51,32 @@
end
end
end
def execute_command!(command)
- $logger.info "Executing #{description} '#{command}' for '#{container.name}' container"
- container.docker_container.exec(command.split(' ')) do |stream, out|
+ $logger.info "Executing #{description} '#{command}' for '#{unit.name}' unit"
+ unit.container.exec(command.split(' ')) do |stream, out|
$logger.debug '%s: %s' % [ stream, out.strip ]
end
end
- def stop_containers!(containers)
- exec_on_containers!(containers) do |container|
- Stop.new(container).execute! if container.running?
+ def stop_units!(units)
+ exec_on_units!(units) do |unit|
+ Stop.new(unit).execute! if unit.running?
end
end
- def start_containers!(containers, scripts: true)
- exec_on_containers!(containers) do |container|
- next if container.running?
- containers = container.startable_dependant_containers.values
- Start.new(container, dependant_containers: containers, exec_scripts: scripts).execute!
+ def start_units!(units, scripts: true)
+ exec_on_units!(units) do |unit|
+ next if unit.running?
+ units = unit.startable_dependant_units.values
+ Start.new(unit, dependant_units: units, exec_scripts: scripts).execute!
end
end
- def exec_on_containers!(containers)
- containers.each_with_object([]) do |container, all|
- all << container if yield(container)
+ def exec_on_units!(units)
+ units.each_with_object([]) do |unit, all|
+ all << unit if yield(unit)
end.compact
end
end
end