ecs_helper 0.0.34 → 0.0.36
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 +4 -4
- data/Gemfile.lock +18 -17
- data/README.md +95 -0
- data/lib/ecs_helper/client.rb +0 -4
- data/lib/ecs_helper/command/base.rb +0 -1
- data/lib/ecs_helper/command/build_and_push.rb +18 -10
- data/lib/ecs_helper/command/deploy.rb +2 -3
- data/lib/ecs_helper/command/ecr_login.rb +1 -1
- data/lib/ecs_helper/common_helper.rb +19 -6
- data/lib/ecs_helper/version.rb +1 -1
- data/lib/ecs_helper.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0d05f26ad2e1cfadd91160c700ecd339e3484fadf00e547d666c589eb74017cd
|
|
4
|
+
data.tar.gz: 3e69e86b2c95f659ca2638d874c13ab11130fda06fe31c95e66247fa662ea861
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bacf9314c83c7d19ddbdfd1571f467b4fcbebfdb4888c83fc4127cfd9eb9009262115e3828d98acb8711e58d364442c42975ed6566926c65d040f845521e3fcd
|
|
7
|
+
data.tar.gz: 98d256e205ba4ee2170edea30685f5e1b7bafa4d3627d488ff3e3d1dba036bc6fd6283e9e9e37599521223d225da7fcd77bf98305b0528fff2390d1f1e20ea97
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
ecs_helper (0.0.
|
|
4
|
+
ecs_helper (0.0.36)
|
|
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)
|
|
@@ -17,26 +17,26 @@ GEM
|
|
|
17
17
|
public_suffix (>= 2.0.2, < 5.0)
|
|
18
18
|
ast (2.4.2)
|
|
19
19
|
awesome_print (1.9.2)
|
|
20
|
-
aws-eventstream (1.
|
|
21
|
-
aws-partitions (1.
|
|
22
|
-
aws-sdk-core (3.
|
|
23
|
-
aws-eventstream (~> 1, >= 1.0
|
|
24
|
-
aws-partitions (~> 1, >= 1.
|
|
25
|
-
aws-sigv4 (~> 1.
|
|
26
|
-
jmespath (~> 1.
|
|
27
|
-
aws-sdk-ecr (1.
|
|
28
|
-
aws-sdk-core (~> 3, >= 3.
|
|
20
|
+
aws-eventstream (1.3.0)
|
|
21
|
+
aws-partitions (1.920.0)
|
|
22
|
+
aws-sdk-core (3.193.0)
|
|
23
|
+
aws-eventstream (~> 1, >= 1.3.0)
|
|
24
|
+
aws-partitions (~> 1, >= 1.651.0)
|
|
25
|
+
aws-sigv4 (~> 1.8)
|
|
26
|
+
jmespath (~> 1, >= 1.6.1)
|
|
27
|
+
aws-sdk-ecr (1.70.0)
|
|
28
|
+
aws-sdk-core (~> 3, >= 3.193.0)
|
|
29
29
|
aws-sigv4 (~> 1.1)
|
|
30
|
-
aws-sdk-ecrpublic (1.
|
|
31
|
-
aws-sdk-core (~> 3, >= 3.
|
|
30
|
+
aws-sdk-ecrpublic (1.27.0)
|
|
31
|
+
aws-sdk-core (~> 3, >= 3.193.0)
|
|
32
32
|
aws-sigv4 (~> 1.1)
|
|
33
|
-
aws-sdk-ecs (1.
|
|
34
|
-
aws-sdk-core (~> 3, >= 3.
|
|
33
|
+
aws-sdk-ecs (1.146.0)
|
|
34
|
+
aws-sdk-core (~> 3, >= 3.193.0)
|
|
35
35
|
aws-sigv4 (~> 1.1)
|
|
36
36
|
aws-sdk-ssm (1.0.0)
|
|
37
37
|
aws-sdk-core (~> 3)
|
|
38
38
|
aws-sigv4 (~> 1.0)
|
|
39
|
-
aws-sigv4 (1.
|
|
39
|
+
aws-sigv4 (1.8.0)
|
|
40
40
|
aws-eventstream (~> 1, >= 1.0.2)
|
|
41
41
|
bump (0.10.0)
|
|
42
42
|
byebug (11.1.3)
|
|
@@ -46,8 +46,8 @@ GEM
|
|
|
46
46
|
crack (0.4.5)
|
|
47
47
|
rexml
|
|
48
48
|
hashdiff (1.0.1)
|
|
49
|
-
jmespath (1.
|
|
50
|
-
json (2.
|
|
49
|
+
jmespath (1.6.2)
|
|
50
|
+
json (2.7.2)
|
|
51
51
|
method_source (1.0.0)
|
|
52
52
|
minitest (5.14.4)
|
|
53
53
|
minitest-power_assert (0.3.1)
|
|
@@ -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
|
|
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.
|
data/lib/ecs_helper/client.rb
CHANGED
|
@@ -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
|
|
@@ -11,9 +11,12 @@ class ECSHelper::Command::BuildAndPush < ECSHelper::Command::Base
|
|
|
11
11
|
'Set image name, will be used to detect ecr repo where to push image, for example web/nginx/toolbox (required)') do |c|
|
|
12
12
|
options[:image] = processEqual(c)
|
|
13
13
|
end
|
|
14
|
-
opts.on('-d VALUE', '--directory VALUE', "Set directory for
|
|
14
|
+
opts.on('-d VALUE', '--directory VALUE', "Set directory for build context, default = './'") do |c|
|
|
15
15
|
options[:directory] = processEqual(c)
|
|
16
16
|
end
|
|
17
|
+
opts.on('-f VALUE', '--file VALUE', "Set path for Dockerfile, default = './Dockerfile'") do |c|
|
|
18
|
+
options[:file] = processEqual(c)
|
|
19
|
+
end
|
|
17
20
|
opts.on('-p VALUE', '--project VALUE',
|
|
18
21
|
"Set project name, if not specified will look at ENV['PROJECT'], will be used to detect cluster") do |p|
|
|
19
22
|
options[:project] = processEqual(p)
|
|
@@ -33,17 +36,17 @@ class ECSHelper::Command::BuildAndPush < ECSHelper::Command::Base
|
|
|
33
36
|
end
|
|
34
37
|
|
|
35
38
|
def run
|
|
36
|
-
log(
|
|
37
|
-
log(
|
|
38
|
-
log(
|
|
39
|
-
log(
|
|
40
|
-
should_cache? && log(
|
|
41
|
-
log(
|
|
42
|
-
log(
|
|
39
|
+
log('Command', type)
|
|
40
|
+
log('Options', options)
|
|
41
|
+
log('Repository', repository)
|
|
42
|
+
log('Auth Private', auth_private)
|
|
43
|
+
should_cache? && log('Pull', pull)
|
|
44
|
+
log('Build', build)
|
|
45
|
+
log('Push', push)
|
|
43
46
|
end
|
|
44
47
|
|
|
45
48
|
def auth_private
|
|
46
|
-
auth_cmd =
|
|
49
|
+
auth_cmd = helper.auth_private_cmd
|
|
47
50
|
auth_cmd.run
|
|
48
51
|
end
|
|
49
52
|
|
|
@@ -63,7 +66,8 @@ class ECSHelper::Command::BuildAndPush < ECSHelper::Command::Base
|
|
|
63
66
|
build_args = options[:build_args].map { |a| "--build-arg=#{a}" }
|
|
64
67
|
cache_command = should_cache? ? ["--cache-from #{latest_tag}"] : []
|
|
65
68
|
tags_command = ["--tag #{latest_tag} --tag #{version_tag}"]
|
|
66
|
-
|
|
69
|
+
file_command = ["--file #{file}"]
|
|
70
|
+
command = (build_command + file_command + build_args + cache_command + tags_command).join(' ')
|
|
67
71
|
build_cmd = Terrapin::CommandLine.new(command)
|
|
68
72
|
|
|
69
73
|
console "Building with two tags: #{latest_tag} & #{version_tag}"
|
|
@@ -85,6 +89,10 @@ class ECSHelper::Command::BuildAndPush < ECSHelper::Command::Base
|
|
|
85
89
|
options[:directory] || './'
|
|
86
90
|
end
|
|
87
91
|
|
|
92
|
+
def file
|
|
93
|
+
options[:file] || './Dockerfile'
|
|
94
|
+
end
|
|
95
|
+
|
|
88
96
|
def latest_tag
|
|
89
97
|
"#{repository}:latest"
|
|
90
98
|
end
|
|
@@ -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
|
|
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
|
|
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)
|
|
@@ -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[
|
|
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
|
|
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[
|
|
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[
|
|
37
|
+
ENV['PROJECT']
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
def application
|
|
40
|
-
ENV[
|
|
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[
|
|
67
|
+
ENV['CI_COMMIT_SHA'] || `git rev-parse HEAD`.strip
|
|
55
68
|
end
|
|
56
69
|
|
|
57
70
|
def use_image_tag_env_prefix?
|
data/lib/ecs_helper/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.0.36
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Artem Petrov
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-04-26 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
|
|
@@ -370,7 +371,7 @@ homepage: https://github.com/artempartos/ecs_helper
|
|
|
370
371
|
licenses:
|
|
371
372
|
- MIT
|
|
372
373
|
metadata: {}
|
|
373
|
-
post_install_message:
|
|
374
|
+
post_install_message:
|
|
374
375
|
rdoc_options: []
|
|
375
376
|
require_paths:
|
|
376
377
|
- lib
|
|
@@ -385,9 +386,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
385
386
|
- !ruby/object:Gem::Version
|
|
386
387
|
version: '0'
|
|
387
388
|
requirements: []
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
signing_key:
|
|
389
|
+
rubygems_version: 3.5.9
|
|
390
|
+
signing_key:
|
|
391
391
|
specification_version: 4
|
|
392
392
|
summary: ECSHelper
|
|
393
393
|
test_files: []
|