ecs_helper 0.0.34 → 0.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a88fdb1673cb2abe2e271e6004fd278b0c5d92bf630ab70fcf7a94c5e0730ce
4
- data.tar.gz: '0278428fd13fc8bc2dcca2b054041787f85c06b1adb94523b09db83a8c160bfe'
3
+ metadata.gz: 4b8c83b0859617581d45d79cb3a8ca067858266427fa3f1024f85aadb12640f5
4
+ data.tar.gz: 1a0416def41b5089f63b2a7beb98d61ec22e30e04c570da57025752a291ad7d0
5
5
  SHA512:
6
- metadata.gz: 52bb0aba871028e742a3ff98323d807f136ce19c2c55d3451ed429b31f32cc64d13b6e88bf4c0b8aa3cbfb61ea41a36b4014ae11a3bbae54ea4af5a223d069a3
7
- data.tar.gz: be2a51106a033db704cc57f44539670616e55e12ba6a3f1a62ae1220708d296e6c3e671687889a559c75841788cdb543aaaffce07d432524a5e89e6988534846
6
+ metadata.gz: 9682932c0088f66054ced4231eab331a8bc244a783db1e98958116dd6cebea145ea5fd24695e78d0b34a3f607831b6a42f6729e224252268d275b12199788282
7
+ data.tar.gz: cb72b81d624af0d0cfa68d4b8ea30d73fc1818aaef39117ab6bd470395b1e1fddc5257a38d3192d2da8f97d755ba034061c105c451f7f85e8ac517e5e17c3e17
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ecs_helper (0.0.34)
4
+ ecs_helper (0.0.35)
5
5
  aws-sdk-ecr (~> 1.42, >= 1.42)
6
6
  aws-sdk-ecrpublic (~> 1.3, >= 1.3)
7
7
  aws-sdk-ecs (~> 1.80, >= 1.80)
@@ -97,6 +97,7 @@ GEM
97
97
 
98
98
  PLATFORMS
99
99
  aarch64-linux
100
+ arm64-darwin-22
100
101
  x86_64-darwin-18
101
102
  x86_64-linux
102
103
 
@@ -117,4 +118,4 @@ DEPENDENCIES
117
118
  webmock
118
119
 
119
120
  BUNDLED WITH
120
- 2.2.27
121
+ 2.4.12
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # ECS Helper - A tool for managing the deployment process of an application in Amazon Elastic Container Service (ECS)
2
+
3
+ ## Introduction
4
+
5
+ ECS Helper is a command-line tool written in Ruby that allows you to control the deployment process of your application
6
+ in Amazon Elastic Container Service. The tool provides various commands for building and pushing images, deploying your
7
+ application, exporting images, logging in to Amazon Elastic Container Registry (ECR), running commands, exporting
8
+ environment variables, and more. To use it an ECS Cluster with a service running there and have task_definitons is
9
+ required. Docker images are stored in the ECR Elastic Container Registry.
10
+
11
+ ## Installation
12
+
13
+ ### Ruby Gem
14
+
15
+ To use ECS Helper, you need to install the ecs_helper gem. You can install it using the following command:
16
+
17
+ ```bash
18
+ gem install ecs_helper
19
+ ```
20
+
21
+ You can use the ecs_helper command followed by the desired command and arguments to control your application deployment
22
+ process.
23
+
24
+ ### Docker Image
25
+
26
+ Alternatively, you can use the Docker image `partos/ecs_toolbox`. This image contains the ecs_helper gem and the AWS CLI
27
+ tool. You can use the image to run the ecs_helper command in a container.
28
+
29
+ ## The available commands are:
30
+
31
+ - **build_and_push**: builds and pushes the Docker image to Amazon Elastic Container Registry (ECR).
32
+ - **deploy**: deploys the Docker image to Amazon Elastic Container Service (ECS).
33
+ - **export_images**: exports Docker images to a file.
34
+ - **ecr_login**: logs in to Amazon Elastic Container Registry (ECR).
35
+ - **run_command**: runs a command in a container.
36
+ - **export_env_secrets**: exports environment variables to a file.
37
+ - **exec**: executes a command in a running container.
38
+ - **check_exec**: checks if the command in the running container was executed successfully.
39
+
40
+ You can select the desired command by passing the argument to the ecs_helper command. For example, to build and push an
41
+ image with the tag api, you can use the following command:
42
+
43
+ ```bash
44
+ ecs_helper build_and_push --image=api
45
+ ```
46
+
47
+ ## Using in GitLab CI
48
+
49
+ ECS Helper can also be used in GitLab CI by using a pre-built Docker image. Here's an example of how to use ECS Helper
50
+ in a GitLab CI pipeline:
51
+
52
+ ```yaml
53
+ stages:
54
+ - build
55
+ - deploy
56
+
57
+
58
+ variables:
59
+ DOCKER_DRIVER: overlay2
60
+ DOCKER_TLS_CERTDIR: ''
61
+ DOCKER_IMAGE: docker:20.10.6
62
+ PROJECT: test_project
63
+ TOOLBOX_IMAGE: partos/ecs_toolbox:0.0.34
64
+ AWS_REGION: us-east-1
65
+ AWS_DEFAULT_REGION: us-east-1
66
+ APPLICATION: app
67
+
68
+ .ci_deploy: &ci_deploy
69
+
70
+ only:
71
+ - master
72
+ - staging
73
+
74
+ build_app:
75
+ <<: *ci_deploy
76
+ stage: build
77
+ image: $TOOLBOX_IMAGE
78
+ script:
79
+ - mkdir -p ./apps/api/dist/apps && cp -r ./dist/apps/api ./apps/api/dist/apps
80
+ - ecs_helper build_and_push --image=api --cache -d ./apps/api
81
+
82
+ deploy_app:
83
+ <<: *ci_deploy
84
+ stage: deploy
85
+ image: $TOOLBOX_IMAGE
86
+ variables:
87
+ APPLICATION: app
88
+ script:
89
+ - ecs_helper deploy --timeout 600
90
+ ```
91
+
92
+ In this example, ECS Helper is used to build and push the api Docker image in the build_app job, and to deploy the
93
+ application in the deploy_app job.
94
+
95
+ When a new version of an application is deployed, a new task definition revision is created in the target service.
@@ -40,10 +40,6 @@ class ECSHelper::Client
40
40
  ecs.register_task_definition(params).task_definition
41
41
  end
42
42
 
43
- def deregister_task_definition(params = {})
44
- ecs.deregister_task_definition(params).task_definition
45
- end
46
-
47
43
  def update_service(params = {})
48
44
  ecs.update_service(params)
49
45
  end
@@ -62,4 +62,3 @@ class ECSHelper::Command::Base
62
62
  value.start_with?('=') ? value[1..-1] : value
63
63
  end
64
64
  end
65
-
@@ -33,17 +33,17 @@ class ECSHelper::Command::BuildAndPush < ECSHelper::Command::Base
33
33
  end
34
34
 
35
35
  def run
36
- log("Command", type)
37
- log("Options", options)
38
- log("Repository", repository)
39
- log("Auth Private", auth_private)
40
- should_cache? && log("Pull", pull)
41
- log("Build", build)
42
- log("Push", push)
36
+ log('Command', type)
37
+ log('Options', options)
38
+ log('Repository', repository)
39
+ log('Auth Private', auth_private)
40
+ should_cache? && log('Pull', pull)
41
+ log('Build', build)
42
+ log('Push', push)
43
43
  end
44
44
 
45
45
  def auth_private
46
- auth_cmd = Terrapin::CommandLine.new('aws ecr get-login --no-include-email | sh')
46
+ auth_cmd = helper.auth_private_cmd
47
47
  auth_cmd.run
48
48
  end
49
49
 
@@ -34,14 +34,13 @@ class ECSHelper::Command::Deploy < ECSHelper::Command::Base
34
34
  log("Service task definition", service_task_definition.task_definition_arn)
35
35
  log("Containers", task_definition_helper.pretty_container_definitions)
36
36
  log("New task definition", new_task_definition.task_definition_arn)
37
- update_service(new_task_definition.task_definition_arn, service_task_definition.task_definition_arn) && log("Update service", "Service task definition was updated")
37
+ update_service(new_task_definition.task_definition_arn) && log("Update service", "Service task definition was updated")
38
38
  log("Waiting for deployment...")
39
39
  wait_for_deployment && log("Success", "Application was succesfully deployed", :cyan)
40
40
  end
41
41
 
42
- def update_service(task_definition_arn, old_task_definition_arn)
42
+ def update_service(task_definition_arn)
43
43
  helper.update_service(cluster_arn, service_arn, task_definition_arn)
44
- helper.client.deregister_task_definition(task_definition: old_task_definition_arn)
45
44
  end
46
45
 
47
46
  def wait_for_deployment(time = 0)
@@ -20,7 +20,7 @@ class ECSHelper::Command::ECRLogin < ECSHelper::Command::Base
20
20
  end
21
21
 
22
22
  def auth_private
23
- auth_cmd = Terrapin::CommandLine.new("aws ecr get-login --no-include-email | sh")
23
+ auth_cmd = helper.auth_private_cmd
24
24
  auth_cmd.run
25
25
  end
26
26
  end
@@ -1,5 +1,6 @@
1
1
  BRANCH_TO_ENV_MAPPING = {
2
2
  master: 'production',
3
+ main: 'production',
3
4
  qa: 'qa',
4
5
  uat: 'uat',
5
6
  staging: 'staging',
@@ -14,13 +15,13 @@ class ECSHelper::CommonHelper
14
15
  end
15
16
 
16
17
  def branch
17
- @branch ||= ENV["CI_COMMIT_BRANCH"] || `git rev-parse --abbrev-ref HEAD`.strip
18
+ @branch ||= ENV['CI_COMMIT_BRANCH'] || `git rev-parse --abbrev-ref HEAD`.strip
18
19
  end
19
20
 
20
21
  def version
21
22
  @version ||=
22
23
  begin
23
- if deployable_branch? && use_image_tag_env_prefix?
24
+ if use_image_tag_env_prefix?
24
25
  "#{environment}-#{commit_sha}"
25
26
  else
26
27
  commit_sha
@@ -29,15 +30,27 @@ class ECSHelper::CommonHelper
29
30
  end
30
31
 
31
32
  def environment
32
- @env ||= helper.options[:environment] || ENV["ENVIRONMENT"] || env_from_branch || raise(StandardError.new("Environment not detected"))
33
+ @env ||= helper.options[:environment] || ENV['ENVIRONMENT'] || env_from_branch || raise(StandardError, 'Environment not detected')
33
34
  end
34
35
 
35
36
  def project
36
- ENV["PROJECT"]
37
+ ENV['PROJECT']
37
38
  end
38
39
 
39
40
  def application
40
- ENV["APPLICATION"]
41
+ ENV['APPLICATION']
42
+ end
43
+
44
+ def region
45
+ @region ||= ENV['AWS_REGION']
46
+ end
47
+
48
+ def account_id
49
+ @account_id ||= ENV['AWS_ACCOUNT_ID'] || `aws sts get-caller-identity --query "Account" --output text`.strip
50
+ end
51
+
52
+ def auth_private_cmd
53
+ @auth_private_cmd ||= Terrapin::CommandLine.new("docker login -u AWS -p $(aws ecr get-login-password --region=#{region}) #{account_id}.dkr.ecr.#{region}.amazonaws.com")
41
54
  end
42
55
 
43
56
  private
@@ -51,7 +64,7 @@ class ECSHelper::CommonHelper
51
64
  end
52
65
 
53
66
  def commit_sha
54
- ENV["CI_COMMIT_SHA"] || `git rev-parse HEAD`.strip
67
+ ENV['CI_COMMIT_SHA'] || `git rev-parse HEAD`.strip
55
68
  end
56
69
 
57
70
  def use_image_tag_env_prefix?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ECSHelper
4
- VERSION = '0.0.34'
4
+ VERSION = '0.0.35'
5
5
  end
data/lib/ecs_helper.rb CHANGED
@@ -17,7 +17,7 @@ class ECSHelper
17
17
  autoload :Command, 'ecs_helper/command'
18
18
 
19
19
  def_delegators :client, :task_definitions, :clusters, :services, :tasks, :repositories, :repositories, :task_definition, :run_task
20
- def_delegators :common_helper, :version, :branch, :environment, :project, :application
20
+ def_delegators :common_helper, :version, :branch, :environment, :project, :application, :region, :account_id, :auth_private_cmd
21
21
  def_delegators :cluster_helper, :current_cluster, :clusters
22
22
  def_delegators :service_helper, :current_service, :services, :update_service
23
23
  def_delegators :command, :run, :options, :type
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecs_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.34
4
+ version: 0.0.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Petrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-15 00:00:00.000000000 Z
11
+ date: 2023-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -338,6 +338,7 @@ files:
338
338
  - Gemfile
339
339
  - Gemfile.lock
340
340
  - Makefile
341
+ - README.md
341
342
  - Rakefile
342
343
  - bin/console
343
344
  - bin/ecs_helper
@@ -385,8 +386,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
385
386
  - !ruby/object:Gem::Version
386
387
  version: '0'
387
388
  requirements: []
388
- rubyforge_project:
389
- rubygems_version: 2.7.6
389
+ rubygems_version: 3.4.12
390
390
  signing_key:
391
391
  specification_version: 4
392
392
  summary: ECSHelper