Class: EcsDeployer::Client
- Inherits:
-
Object
- Object
- EcsDeployer::Client
- Defined in:
- lib/ecs_deployer/client.rb
Constant Summary collapse
- LOG_SEPARATOR =
'-' * 96
- ENCRYPT_PATTERN =
/^\${(.+)}$/
Instance Attribute Summary collapse
-
#cli ⇒ Object
readonly
Returns the value of attribute cli.
-
#pauling_interval ⇒ Object
Returns the value of attribute pauling_interval.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #decrypt(value) ⇒ String
- #encrypt(master_key, value) ⇒ String
- #initialize(aws_options = {}, runtime_options = {}) ⇒ EcsDeployer::Client constructor
- #register_clone_task(cluster, service) ⇒ String
- #register_task(path, replace_variables = {}) ⇒ String
- #register_task_hash(task_definition, replace_variables = {}) ⇒ String
- #update_service(cluster, service, wait = true) ⇒ String
Constructor Details
#initialize(aws_options = {}, runtime_options = {}) ⇒ EcsDeployer::Client
18 19 20 21 22 23 24 |
# File 'lib/ecs_deployer/client.rb', line 18 def initialize( = {}, = {}) @runtime = RuntimeCommand::Builder.new() @cli = Aws::ECS::Client.new() @kms = Aws::KMS::Client.new() @timeout = 600 @pauling_interval = 20 end |
Instance Attribute Details
#cli ⇒ Object (readonly)
Returns the value of attribute cli.
12 13 14 |
# File 'lib/ecs_deployer/client.rb', line 12 def cli @cli end |
#pauling_interval ⇒ Object
Returns the value of attribute pauling_interval.
13 14 15 |
# File 'lib/ecs_deployer/client.rb', line 13 def pauling_interval @pauling_interval end |
#timeout ⇒ Object
Returns the value of attribute timeout.
13 14 15 |
# File 'lib/ecs_deployer/client.rb', line 13 def timeout @timeout end |
Instance Method Details
#decrypt(value) ⇒ String
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ecs_deployer/client.rb', line 38 def decrypt(value) match = value.match(ENCRYPT_PATTERN) raise KmsDecryptError, 'Encrypted string is invalid.' unless match begin @kms.decrypt(ciphertext_blob: Base64.strict_decode64(match[1])).plaintext rescue => e raise KmsDecryptError, e.to_s end end |
#encrypt(master_key, value) ⇒ String
29 30 31 32 33 34 |
# File 'lib/ecs_deployer/client.rb', line 29 def encrypt(master_key, value) encode = @kms.encrypt(key_id: "alias/#{master_key}", plaintext: value) "${#{Base64.strict_encode64(encode.ciphertext_blob)}}" rescue => e raise KmsEncryptError, e.to_s end |
#register_clone_task(cluster, service) ⇒ String
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/ecs_deployer/client.rb', line 81 def register_clone_task(cluster, service) detected_service = false result = @cli.describe_services( cluster: cluster, services: [service] ) result[:services].each do |svc| next unless svc[:service_name] == service result = @cli.describe_task_definition( task_definition: svc[:task_definition] ) @new_task_definition_arn = register_task_hash(result[:task_definition].to_hash) detected_service = true break end raise ServiceNotFoundError, "'#{service}' service is not found." unless detected_service @new_task_definition_arn end |
#register_task(path, replace_variables = {}) ⇒ String
52 53 54 55 56 |
# File 'lib/ecs_deployer/client.rb', line 52 def register_task(path, replace_variables = {}) raise IOError, "File does not exist. [#{path}]" unless File.exist?(path) register_task_hash(YAML.load(File.read(path)), replace_variables) end |
#register_task_hash(task_definition, replace_variables = {}) ⇒ String
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ecs_deployer/client.rb', line 61 def register_task_hash(task_definition, replace_variables = {}) task_definition = Oj.load(Oj.dump(task_definition), symbol_keys: true) replace_parameter_variables!(task_definition, replace_variables) decrypt_environment_variables!(task_definition) result = @cli.register_task_definition( container_definitions: task_definition[:container_definitions], family: task_definition[:family], task_role_arn: task_definition[:task_role_arn] ) @family = result[:task_definition][:family] @revision = result[:task_definition][:revision] @new_task_definition_arn = result[:task_definition][:task_definition_arn] end |
#update_service(cluster, service, wait = true) ⇒ String
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ecs_deployer/client.rb', line 108 def update_service(cluster, service, wait = true) register_clone_task(cluster, service) if @new_task_definition_arn.nil? result = @cli.update_service( cluster: cluster, service: service, task_definition: @family + ':' + @revision.to_s ) wait_for_deploy(cluster, service) if wait result.service.service_arn end |