Sha256: 6908c8cbf9ba1ae5883e7a03bf91b07e8b9a49624049790e7fdad41e4cba9ad0

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

module ContainerShip
  module Command
    module Modules
      module Ecs
        def register(task_definition)
          aws_ecs_client
            .register_task_definition(task_definition.to_h)
            .task_definition
            .revision
        end

        def update_service(task_definition, revision)
          aws_ecs_client.update_service(
            cluster: task_definition.full_cluster_name,
            service: task_definition.full_name,
            task_definition: "#{task_definition.full_name}:#{revision}"
          )
        end

        def run_task(task_definition, revision)
          aws_ecs_client
            .run_task(
              cluster: task_definition.full_cluster_name,
              task_definition: "#{task_definition.full_name}:#{revision}"
            )
            .tasks
            .first
            .task_arn
        end

        def wait_task(task_definition, task_arn)
          do_every_5_seconds do
            aws_ecs_client.describe_tasks(cluster: task_definition.full_cluster_name, tasks: [task_arn])
              .tasks
              .first
              .containers
              .first
              .exit_code
          end
        end

        private

        def aws_ecs_client
          @aws_ecs_client ||= Aws::ECS::Client.new
        end

        def do_every_5_seconds
          count = 0
          loop do
            sleep 3
            print '.'
            exit_status = yield
            count += 1
            next if exit_status.nil?
            return 124 if count > 60

            return exit_status
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
container_ship-0.1.2 lib/container_ship/command/modules/ecs.rb
container_ship-0.1.1 lib/container_ship/command/modules/ecs.rb