class KumoDockerCloud::Environment
Public Class Methods
new(params = {})
click to toggle source
# File lib/kumo_dockercloud/environment.rb, line 18 def initialize(params = {}) @env_name = params.fetch(:name) @env_vars = params.fetch(:env_vars, {}) @stack_template_path = params.fetch(:stack_template_path) @timeout = params.fetch(:timeout, 120) @confirmation_timeout = params.fetch(:confirmation_timeout, 30) @app_name = params.fetch(:app_name) @app_image = params.fetch(:app_image, "redbubble/#{@app_name}:master") @config = EnvironmentConfig.new(app_name: @app_name, env_name: @env_name, config_path: params.fetch(:config_path), app_image: @app_image) @stack = Stack.new(@app_name, @env_name) end
Public Instance Methods
apply(stack_checker = StackChecker.new)
click to toggle source
# File lib/kumo_dockercloud/environment.rb, line 30 def apply(stack_checker = StackChecker.new) if @config.image_tag == 'latest' ConsoleJockey.write_line 'WARNING: Deploying latest. The deployed container version may arbitrarily change' end stack_file = write_stack_config_file(configure_stack(stack_template)) run_command(stack_command(stack_file)) stack_file.unlink run_command("docker-cloud stack redeploy #{stack_name}") begin stack_checker.verify(@stack) rescue StackCheckError raise EnvironmentApplyError.new("The stack is not in the expected state.") end end
destroy()
click to toggle source
# File lib/kumo_dockercloud/environment.rb, line 48 def destroy ConsoleJockey.flash_message "Warning! You are about to delete the Docker Cloud Stack #{stack_name}, enter 'yes' to continue." return unless ConsoleJockey.get_confirmation(@confirmation_timeout) run_command("docker-cloud stack terminate --sync #{stack_name}") end
Private Instance Methods
configure_stack(stack_template)
click to toggle source
# File lib/kumo_dockercloud/environment.rb, line 56 def configure_stack(stack_template) StackFile.create_from_template(stack_template, @config, @env_vars) end
evaluate_command(cmd)
click to toggle source
# File lib/kumo_dockercloud/environment.rb, line 65 def evaluate_command(cmd) `#{cmd}` end
exists?()
click to toggle source
# File lib/kumo_dockercloud/environment.rb, line 77 def exists? @stack.exists? end
run_command(cmd)
click to toggle source
# File lib/kumo_dockercloud/environment.rb, line 60 def run_command(cmd) puts "Executing -> #{cmd}" puts `#{cmd}` end
stack_command(stack_file)
click to toggle source
# File lib/kumo_dockercloud/environment.rb, line 69 def stack_command(stack_file) if exists? "docker-cloud stack update -f #{stack_file.path} #{stack_name}" else "docker-cloud stack create -f #{stack_file.path} -n #{stack_name}" end end
stack_template()
click to toggle source
# File lib/kumo_dockercloud/environment.rb, line 88 def stack_template File.read(@stack_template_path) end
write_stack_config_file(stack_file_data)
click to toggle source
# File lib/kumo_dockercloud/environment.rb, line 81 def write_stack_config_file(stack_file_data) output_file = Tempfile.new('docker-cloud_stack_config') output_file.write(stack_file_data.to_yaml) output_file.close output_file end