Skip to content

Commit 42a1e96

Browse files
authored
Create README.md
1 parent 70a58fd commit 42a1e96

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

stable/ecs-deploy/README.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
2+
# cf-ecs-deploy
3+
Deployment to Amazon ECS Service
4+
5+
### Prerequiests
6+
- Configured ECS Cluster with at least one running instance.
7+
- Configured ECS Service and task definition with an image being deployed.
8+
See http://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html
9+
10+
- AWS Credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) with following priviledges:
11+
```json
12+
{
13+
"Version": "2012-10-17",
14+
"Statement": [
15+
{
16+
"Sid": "Stmt1479146904000",
17+
"Effect": "Allow",
18+
"Action": [
19+
"ecs:DescribeServices",
20+
"ecs:DescribeTaskDefinition",
21+
"ecs:DescribeTasks",
22+
"ecs:ListClusters",
23+
"ecs:ListServices",
24+
"ecs:ListTasks",
25+
"ecs:RegisterTaskDefinition",
26+
"ecs:UpdateService"
27+
],
28+
"Resource": [
29+
"*"
30+
]
31+
}
32+
]
33+
}
34+
```
35+
36+
### Deployment with Codefresh
37+
- Add encrypted environment variables for aws credentials.
38+
* AWS_ACCESS_KEY_ID
39+
* AWS_SECRET_ACCESS_KEY
40+
- Add "deploy to ecs" step to codefresh.yml which runs codefresh/cf-deploy-ecs image with command cfecs-update
41+
Specify the aws region, ecs cluster and service names. See `cfecs-update -h` for parameter references
42+
43+
```yaml
44+
# codefresh.yml example with deploy to ecs step
45+
version: '1.0'
46+
47+
steps:
48+
build-step:
49+
type: build
50+
image-name: repo/image:tag
51+
52+
push to registry:
53+
type: push
54+
candidate: ${{build-step}}
55+
tag: ${{CF_BRANCH}}
56+
57+
deploy to ecs:
58+
image: codefresh/cf-deploy-ecs
59+
commands:
60+
- cfecs-update <aws-region> <ecs-cluster-name> <ecs-service-name>
61+
environment:
62+
- AWS_ACCESS_KEY_ID=${{AWS_ACCESS_KEY_ID}}
63+
- AWS_SECRET_ACCESS_KEY=${{AWS_SECRET_ACCESS_KEY}}
64+
65+
when:
66+
- name: "Execute for 'master' branch"
67+
condition: "'${{CF_BRANCH}}' == 'master'"
68+
```
69+
70+
71+
### Deployment Flow
72+
- get ECS service by specified aws region, ecs cluster and service names
73+
- create new revision from current task definition of the service. If --image-name and --image-tag are provided, replace the tag of the image
74+
- launch update-service with new task definition revision
75+
- wait for deployment to complete (by default, if running withou --no-wait)
76+
* deployment is considered as completed successfully if runningCount == desiredCount for PRIMARY deployment - see `aws ecs describe-service`
77+
* cfecs-update exits with timeout if after --timeout (default = 900s) runningCount != desiredCount script exits with timeout
78+
* cfecs-update exits with error if --max-failed (default = 2) or more ecs tasks were stopped with error for the task definition being deployed.
79+
ECS retries failed tasks continuously
80+
81+
### Usage with docker
82+
83+
```bash
84+
docker run --rm -it -e AWS_ACCESS_KEY_ID=**** -e AWS_SECRET_ACCESS_KEY=**** codefresh/cf-ecs-deploy cfecs-update [options] <aws-region> <ecs-cluster-name> <ecs-service-name>
85+
```
86+
87+
### cfecs-update -h
88+
```
89+
usage: cfecs-update [-h] [-i IMAGE_NAME] [-t IMAGE_TAG] [--wait | --no-wait]
90+
[--timeout TIMEOUT] [--max-failed MAX_FAILED] [--debug]
91+
region_name cluster_name service_name
92+
93+
Codefresh ECS Deploy
94+
95+
positional arguments:
96+
region_name AWS Region, ex. us-east-1
97+
cluster_name ECS Cluster Name
98+
service_name ECS Service Name
99+
100+
optional arguments:
101+
-h, --help show this help message and exit
102+
--wait Wait for deployment to complete (default)
103+
--no-wait No Wait for deployment to complete
104+
--timeout TIMEOUT deployment wait timeout (default 900s)
105+
--max-failed MAX_FAILED
106+
max failed tasks to consider deployment as failed
107+
(default 2)
108+
--debug show debug messages
109+
110+
-i IMAGE_NAME, --image-name IMAGE_NAME
111+
Image Name in ECS Task Definition to set new tag
112+
-t IMAGE_TAG, --image-tag IMAGE_TAG
113+
Tag for the image
114+
```

0 commit comments

Comments
 (0)