Class: Shipitron::Client::CreateEcsServices

Inherits:
Object
  • Object
show all
Includes:
Metaractor, EcsClient
Defined in:
lib/shipitron/client/create_ecs_services.rb

Instance Method Summary collapse

Methods included from EcsClient

#ecs_client, #generate_ecs_client

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/shipitron/client/create_ecs_services.rb', line 18

def call
  Logger.info 'Creating ECS services'

  service_defs = Pathname.new(service_directory)
  unless service_defs.directory?
    fail_with_error!(
      message: "service directory '#{service_directory}' does not exist"
    )
  end

  service_defs.find do |path|
    next if path.directory?

    service_def = Smash.load(
      path.to_s,
      parser: MustacheYamlParser,
      context: {
        cluster: cluster_name,
        revision: nil, # ECS will default to latest ACTIVE
        count: service_count
      }
    ).merge(
      client_token: SecureRandom.uuid
    )

    Logger.info "Creating service '#{service_def.service_name}'"
    Logger.debug "Service definition: #{service_def.to_h}"
    begin
      ecs_client(region: region).create_service(
        service_def.to_h
      )
    rescue Aws::ECS::Errors::InvalidParameterException => e
      raise if e.message != 'Creation of service was not idempotent.'

      Logger.info "Service '#{service_def.service_name}' already exists."
    end
  end

  Logger.info 'Done'
rescue Aws::ECS::Errors::ServiceError => e
  fail_with_errors!(messages: [
    "Error: #{e.message}",
    e.backtrace.join("\n")
  ])
end