Skip to content

Commit d4c1e75

Browse files
Merge pull request #291 from silinternational/develop
Release 3.10.17 - Convert to Github Actions
2 parents 859686e + 91e2521 commit d4c1e75

File tree

7 files changed

+91
-81
lines changed

7 files changed

+91
-81
lines changed

.github/workflows/ci.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Continuous Integration
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
test:
8+
name: Test
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Run tests
13+
run: docker-compose -f action-services.yml run test
14+
15+
build-and-publish:
16+
name: Build and Publish
17+
needs: test
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Log in to Docker Hub
23+
uses: docker/login-action@v3
24+
with:
25+
username: ${{ secrets.DOCKERHUB_USERNAME }}
26+
password: ${{ secrets.DOCKERHUB_TOKEN }}
27+
28+
- name: Extract metadata (tags, labels) for Docker
29+
id: meta
30+
uses: docker/metadata-action@v5
31+
with:
32+
images: ${{ vars.DOCKER_ORG }}/ecs-deploy
33+
34+
- name: Build and push Docker image
35+
uses: docker/build-push-action@v5
36+
with:
37+
context: .
38+
push: true
39+
tags: ${{ steps.meta.outputs.tags }}
40+
labels: ${{ steps.meta.outputs.labels }}

README.md

+44-51
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
ecs-deploy
2-
=================
1+
# ecs-deploy
32

4-
[ ![Codeship Status for silinternational/ecs-deploy](https://app.codeship.com/projects/393a91e0-da8d-0134-6603-1e487e818871/status?branch=master)](https://app.codeship.com/projects/203720)
3+
![Status for silinternational/ecs-deploy](https://github.com/silinternational/ecs-deploy/actions/workflows/build-and-deploy.yml/badge.svg?branch=master)
54

65
This script uses the Task Definition and Service entities in Amazon's ECS to instigate an automatic blue/green deployment.
76

8-
NOTE: Maintenance Only
9-
----------------------
7+
## NOTE: Maintenance Only
108

119
`ecs-deploy` is now in maintenance mode. In other words, we are considering it
1210
"feature complete" and will generally only consider PRs if they are bugfixes or
1311
are to add support for new AWS CLI features.
1412

15-
Usage
16-
-----
13+
## Usage
1714

1815
One of the following is required:
1916
-n | --service-name Name of service to deploy
@@ -66,19 +63,19 @@ Usage
6663
Examples:
6764
Simple deployment of a service (Using env vars for AWS settings):
6865

69-
ecs-deploy -c production1 -n doorman-service -i docker.repo.com/doorman:latest
66+
ecs-deploy -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container:latest
7067

7168
All options:
7269

73-
ecs-deploy -k ABC123 -s SECRETKEY -r us-east-1 -c production1 -n doorman-service -i docker.repo.com/doorman -m 50 -M 100 -t 240 -D 2 -e CI_TIMESTAMP -v
70+
ecs-deploy -k ABC123 -s SECRETKEY -r us-east-1 -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container -m 50 -M 100 -t 240 -D 2 -e CI_TIMESTAMP -v
7471

7572
Updating a task definition with a new image:
7673

77-
ecs-deploy -d open-door-task -i docker.repo.com/doorman:17
74+
ecs-deploy -d my-task-definition -i my.private.repo.com/frontend_container:17
7875

7976
Using profiles (for STS delegated credentials, for instance):
8077

81-
ecs-deploy -p PROFILE -c production1 -n doorman-service -i docker.repo.com/doorman -t 240 -e CI_TIMESTAMP -v
78+
ecs-deploy -p my-profile -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container -t 240 -e CI_TIMESTAMP -v
8279

8380
Update just the tag on whatever image is found in ECS Task (supports multi-container tasks):
8481

@@ -87,21 +84,19 @@ Usage
8784
Notes:
8885
- If a tag is not found in image and an ENV var is not used via -e, it will default the tag to "latest"
8986

90-
Installation
91-
------------
87+
## Installation
88+
89+
- Install and configure [aws-cli](http://docs.aws.amazon.com/cli/latest/userguide/tutorial-ec2-ubuntu.html#install-cli)
90+
- Install [jq](https://github.com/stedolan/jq/wiki/Installation)
91+
- Install ecs-deploy:
9292

93-
* Install and configure [aws-cli](http://docs.aws.amazon.com/cli/latest/userguide/tutorial-ec2-ubuntu.html#install-cli)
94-
* Install [jq](https://github.com/stedolan/jq/wiki/Installation)
95-
* Install ecs-deploy:
9693
```
9794
curl https://raw.githubusercontent.com/silinternational/ecs-deploy/master/ecs-deploy | sudo tee /usr/bin/ecs-deploy
9895
sudo chmod +x /usr/bin/ecs-deploy
9996
10097
```
10198

102-
103-
How it works
104-
------------
99+
## How it works
105100

106101
_Note: Some nouns in the next paragraphs are capitalized to indicate that they are words which have specific meanings in AWS_
107102

@@ -129,11 +124,11 @@ _Naturally, enough computing resources must be available in the ECS cluster for
129124
Consequently, all that is needed to deploy a new version of an application is to update the Service which is running its
130125
Tasks to point at a new version of the Task Definition. `ecs-deploy` uses the python `aws` utility to do this. It,
131126

132-
* Pulls the JSON representation of the in-use Task Definition; or the most recently created if using `--use-latest-task-def`
133-
* Edits it
134-
* Defines a new version, with the changes
135-
* Updates the Service to use the new version
136-
* Waits, querying Amazon's API to make sure that the Service has been able to create a new Task
127+
- Pulls the JSON representation of the in-use Task Definition; or the most recently created if using `--use-latest-task-def`
128+
- Edits it
129+
- Defines a new version, with the changes
130+
- Updates the Service to use the new version
131+
- Waits, querying Amazon's API to make sure that the Service has been able to create a new Task
137132

138133
The second step merits more explanation: since a Task Definition [may] define multiple containers, the question arises, "what
139134
must be changed to create a new revision?" Empirically, the surprising answer is nothing; Amazon allows you to create a new
@@ -152,42 +147,39 @@ be an unlikely use case._
152147
This behavior allows two possible process to specify which images, and therefore which configurations, to deploy. First, you
153148
may set the tag to always be `latest` (or some other static value), like so:
154149

155-
ecs-deploy -c CLUSTERNAME -n SERVICENAME -i my.private.repo.com/frontend_container:latest
150+
ecs-deploy -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container:latest
156151

157152
This will result in identical new versions of the Task Definition being created, but the Service will still do a blue/green
158153
deployment, and will so will pull down the latest version (if you previously pushed it into the registry).
159154

160155
Alternatively, you may specify some other means of obtaining the tag, since the script `eval`s the image string. You could use
161156
git tags as a map to docker tags:
162157

163-
ecs-deploy -c CLUSTERNAME -n SERVICENAME -i 'my.private.repo.com/frontend_container:`git describe`'
158+
ecs-deploy -c my-cluster-name -n my-service-name -i 'my.private.repo.com/frontend_container:`git describe`'
164159

165160
Or perhaps just obtain read the docker tag from another file in your development:
166161

167-
ecs-deploy -c CLUSTERNAME -n SERVICENAME -i 'my.private.repo.com/frontend_container:$(< VERSION)'
162+
ecs-deploy -c my-cluster-name -n my-service-name -i 'my.private.repo.com/frontend_container:$(< VERSION)'
168163

169164
In any case, just make sure your process builds, tags, and pushes the docker image you use to the repository before running
170165
this script.
171166

172-
Use Environment Variable for tag name value
173-
-------------------------------------------
167+
## Use Environment Variable for tag name value
168+
174169
In some cases you may want to use an environment variable for the tag name of your image.
175-
For instance, we use Codeship for continuous integration and deployment. In their Docker
176-
environment they can build images and tag them with different variables, such as
177-
the current unix timestamp. We want to use these unique and changing values for image tags
178-
so that each task definition refers to a unique docker image/tag. This gives us the
179-
ability to revert/rollback changes by just selecting a previous task definition and
180-
updating the service. We plan to add a revert command/option to ecs-deploy to simplify this further.
170+
For example, we want to use a unique docker image/tag for each task definition. This
171+
gives us the ability to revert/rollback changes by just selecting a previous task
172+
definition and updating the service.
173+
174+
Using the `-e` argument you can provide the name of an environment variable that
175+
holds the value you wish to use for the tag.
181176

182-
Using the ```-e``` argument you can provide the name of an environment variable that
183-
holds the value you wish to use for the tag. On Codeship they set an env var named CI_TIMESTAMP.
177+
For example:
184178

185-
So we use ```ecs-deploy``` like this:
179+
ecs-deploy -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container -e CI_TIMESTAMP
186180

187-
ecs-deploy -c production1 -n doorman-api -i my.private.repo/doorman-api -e CI_TIMESTAMP
181+
## AWS IAM Policy Configuration
188182

189-
AWS IAM Policy Configuration
190-
-------------------------------------------
191183
Here's an example of a suitable custom policy for [AWS IAM](https://aws.amazon.com/documentation/iam/):
192184

193185
```json
@@ -215,15 +207,15 @@ Here's an example of a suitable custom policy for [AWS IAM](https://aws.amazon.c
215207
}
216208
```
217209

218-
Troubleshooting
219-
---------------
220-
- You must provide AWS credentials in one of the supported formats. If you do
221-
not, you'll see some error output from the AWS CLI, something like:
210+
## Troubleshooting
222211

223-
You must specify a region. You can also configure your region by running "aws configure".
212+
- You must provide AWS credentials in one of the supported formats. If you do
213+
not, you'll see some error output from the AWS CLI, something like:
214+
215+
You must specify a region. You can also configure your region by running "aws configure".
216+
217+
## Testing
224218

225-
Testing
226-
-------
227219
Automated tests are performed using [bats](https://github.com/sstephenson/bats).
228220
The goal of testing is to ensure that updates/changes do not break core functionality.
229221
Unfortunately not all of `ecs-deploy` is testable since portions interact with
@@ -232,9 +224,10 @@ is tested.
232224

233225
Any new functionality and pull requests should come with tests as well (if possible).
234226

235-
Github Actions Support
236-
-------
237-
Github Actions support is available. Add a code block similar to that below to your actions yaml file. Parameters are passed to the ecs-deploy tool under 'with' section. For each parameter, the parameter name followed by _cmd must be called with the appropriate parameter option like '--aws-access-key' in addition to supplying the parameter aws_access_key with the appropriate value.
227+
## Github Actions Support
228+
229+
Github Actions support is available. Add a code block similar to that below to your actions yaml file. Parameters are passed to the ecs-deploy tool under 'with' section. For each parameter, the parameter name followed by \_cmd must be called with the appropriate parameter option like '--aws-access-key' in addition to supplying the parameter aws_access_key with the appropriate value.
230+
238231
```
239232
deploy_to_ecs:
240233
name: 'Deploy updated container image via blue/green deployment to ECS service.'

action-services.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "3"
2+
3+
services:
4+
test:
5+
build: .
6+
entrypoint: ["/run-tests.sh"]

codeship-services.yml

-6
This file was deleted.

codeship-steps.yml

-21
This file was deleted.

dockercfg.encrypted

-2
This file was deleted.

ecs-deploy

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# Setup default values for variables
4-
VERSION="3.10.16"
4+
VERSION="3.10.17"
55
CLUSTER=false
66
SERVICE=false
77
TASK_DEFINITION=false

0 commit comments

Comments
 (0)