Skip to content

Commit febafb3

Browse files
committed
initial commit
0 parents  commit febafb3

File tree

9 files changed

+517
-0
lines changed

9 files changed

+517
-0
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily
7+
time: "08:00"
8+
timezone: "America/New_York"

.github/ecs-deploy-action.png

100 KB
Loading

.github/workflows/linting.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: sourcetoad/aws-ecs-deploy-action
2+
on: push
3+
4+
jobs:
5+
bash-lint:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout code
9+
uses: actions/checkout@v3
10+
11+
- name: Lint Bash
12+
uses: azohra/shell-linter@latest
13+
with:
14+
path: '*.sh'

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
3+
# ide
4+
.idea

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM amazon/aws-cli:2.9.22
2+
3+
COPY deploy.sh /deploy.sh
4+
5+
# Get tools needed for packaging
6+
RUN yum update -y && \
7+
yum install -y jq && \
8+
yum clean all && \
9+
rm -rf /var/cache/yum

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MIT License
2+
3+
_Copyright (c) 2021 Sourcetoad, LLC_
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# AWS ECS Deploy Action
2+
_To automatically edit task definitions via jq to then deploy & monitor._
3+
4+
![](.github/ecs-deploy-action.png)
5+
6+
### How it works
7+
8+
* Optionally, the action downloads the latest task definition from the given prepare task name (`ecs_prepare_task_definition_name`).
9+
* If fulfilled, it edits the task definition for each image change in `prepare_container_image_changes`
10+
* The task is executed one-off and requires successful completion before next step.
11+
* (this may require setting `prepare_container_network_config_filepath` to a JSON file representing the network configuration)
12+
* Afterwards, the action downloads the latest task definition from given main task parameter (`service_task_definition_name`).
13+
* Task definition is edited for each image change listed in `container_image_changes`.
14+
* Service update (with forced deployment) is triggered with that modified task definition file under the named service: `ecs_service_name`.
15+
* Status updates are provided as the deployment continues until either a successful or failure state is encountered.
16+
17+
### Assumptions
18+
19+
This is used in many applications for production level deployments. However, there are a few things that are untested as we do not use them.
20+
21+
* Non-FARGATE deployments
22+
* CodeDeploy within ECS
23+
24+
---
25+
26+
## Usage
27+
_includes examples from other packages to give context_
28+
29+
```yaml
30+
- name: Configure AWS Credentials
31+
uses: aws-actions/configure-aws-credentials@v1
32+
with:
33+
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
34+
aws-region: us-east-1
35+
36+
- name: Login to Amazon ECR
37+
uses: aws-actions/amazon-ecr-login@v1
38+
39+
- name: "Build, tag, push image: ..."
40+
uses: docker/build-push-action@v4
41+
with:
42+
push: true
43+
44+
- name: ECS Deploy
45+
uses: sourcetoad/aws-ecs-deploy-action@v1
46+
with:
47+
ecs_service_name: project
48+
service_task_definition_name: project-alpha
49+
container_image_changes: >
50+
nginx|123456789100.dkr.ecr.us-east-1.amazonaws.com/nginx:version
51+
php|123456789100.dkr.ecr.us-east-1.amazonaws.com/php:version
52+
```
53+
54+
## Customizing
55+
56+
### inputs
57+
58+
Following inputs can be used as `step.with` keys
59+
60+
| Name | Required | Type | Description |
61+
|--------------------------------------------------|----------|--------|--------------------------------------------------------------------|
62+
| `ecs_cluster_name` | yes | string | ECS Cluster Name |
63+
| `aws_region` | no | string | AWS Region (default: `us-east-1`) |
64+
| `ecs_service_name` | yes | string | ECS Service Name |
65+
| `ecs_launch_type` | no | string | ECS Launch Type for tasks. (default: `FARGATE`) |
66+
| `service_task_definition_name` | yes | string | ECS Task Definition Name |
67+
| `service_container_image_changes` | yes | string | space delimited keypairs (`container|image`) |
68+
| `prepare_task_definition_name` | no | string | ECS Task Definition Name (Runs prior to execution) |
69+
| `prepare_task_container_image_changes` | no | string | space delimited keypairs for prepare step (`container|image`) |
70+
| `prepare_task_container_network_config_filepath` | no | string | filepath from context of root to json configuration |
71+
| `max_polling_iterations` | no | Number | Number of 15s iterations to poll max (default: `60`) |
72+
| `dry_run` | no | bool | Whether to skip write related AWS commands. |
73+
74+
## Skip waiting during update
75+
Some projects may not want to poll till completion. Setting `max_polling_iterations` to `0` will exit the script cleanly
76+
after the service update was triggered. Progress will have to be monitored elsewhere.
77+
78+
## Prepare Task
79+
Some projects may require a task to complete prior to the rollout of the main system. This is commonly for migrations in Laravel projects.
80+
These set of configurations allow when set require the task to execute and continue to completion prior to the main services updating.
81+
82+
* `prepare_task_definition_name` - The task name for the prepare task.
83+
* `prepare_task_container_image_changes` - Image changes, much like explained below for container images
84+
* `prepare_task_container_network_config_filepath` - JSON file for network configuration (example below)
85+
```json
86+
{
87+
"awsvpcConfiguration": {
88+
"subnets": ["string", "string2"],
89+
"securityGroups": ["string", "string2"],
90+
"assignPublicIp": "ENABLED|DISABLED"
91+
}
92+
}
93+
```
94+
95+
## Container Image Changes
96+
97+
When wishing to change multiple images in one task definition, leverage the formatting of Folded Style parameters.
98+
99+
Given this example:
100+
```yaml
101+
- uses: sourcetoad/aws-ecs-deploy-action@v1
102+
with:
103+
container_image_changes: >
104+
nginx|123456789100.dkr.ecr.us-east-1.amazonaws.com/nginx:version
105+
php|123456789100.dkr.ecr.us-east-1.amazonaws.com/php:version
106+
```
107+
* This will crawl the `containerDefinitions` of the task definition
108+
* Finding the first container that has name `nginx`
109+
* Adapting the `image` property to `123456789100.dkr.ecr.us-east-1.amazonaws.com/nginx:version`
110+
* Finding the next container that has name `php`
111+
* Adapting the `image` property to `123456789100.dkr.ecr.us-east-1.amazonaws.com/php:version`

action.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: 'Sourcetoad - AWS ECS Deploy Action'
2+
description: 'Edit Task Definitions in ECS with jq and deploy.'
3+
author: Sourcetoad
4+
branding:
5+
color: 'yellow'
6+
icon: 'server'
7+
8+
inputs:
9+
ecs_cluster_name:
10+
description: 'ECS Cluster Name'
11+
required: true
12+
aws_region:
13+
description: 'AWS Region'
14+
required: false
15+
default: 'us-east-1'
16+
ecs_launch_type:
17+
description: 'ECS Launch Type (One of `ECS`, `FARGATE` or `EXTERNAL`).'
18+
required: false
19+
default: 'FARGATE'
20+
ecs_service_name:
21+
description: 'ECS Service Name'
22+
required: true
23+
service_task_definition_name:
24+
description: 'ECS Task Definition Name'
25+
required: true
26+
service_container_image_changes:
27+
description: 'Container images to change in format of (containername:image) using folded block scalar.'
28+
required: true
29+
prepare_task_definition_name:
30+
description: 'ECS Task Definition Name (Runs prior to execution)'
31+
required: false
32+
prepare_task_container_image_changes:
33+
description: 'Prepare step container images to change in format of (containername:image) using folded block scalar.'
34+
required: false
35+
prepare_task_container_network_config_filepath:
36+
description: 'Location to JSON file representing the network configuration for the optional prepare job. This is required when `awsvpc` is in use.'
37+
required: false
38+
max_polling_iterations:
39+
description: 'Max amount of iterations (15s increments) to wait for a service update'
40+
required: false
41+
default: '60'
42+
dry_run:
43+
description: 'Whether to skip all AWS related write steps.'
44+
required: false
45+
default: 'false'
46+
runs:
47+
using: 'docker'
48+
image: 'Dockerfile'
49+
entrypoint: '/deploy.sh'

0 commit comments

Comments
 (0)