Skip to content

Commit ea9be20

Browse files
committed
Added edits and style changes to Amazon guide
1 parent 3ef5057 commit ea9be20

1 file changed

Lines changed: 89 additions & 83 deletions

File tree

content/actions/guides/deploying-to-amazon-elastic-container-service.md

Lines changed: 89 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,63 @@ versions:
1111
{% data reusables.actions.enterprise-github-hosted-runners %}
1212

1313
### Introduction
14-
[Amazon ECR (Elastic Container Registry)](https://aws.amazon.com/ecr/) and [Amazon ECS (Elastic Container Service)](https://aws.amazon.com/ecs/) are a great combination for running your container-based workloads in the cloud.
1514

16-
This guide will show you how to orchestrate your deployments to Amazon ECR and ECS via GitHub Actions.
15+
This guide explains how to use {% data variables.product.prodname_actions %} to build a containerized application, push it to [Amazon Elastic Container Registry (ECR)](https://aws.amazon.com/ecr/), and deploy it to [Amazon Elastic Container Service (ECS)](https://aws.amazon.com/ecs/).
1716

18-
The included workflow will build and push a new container image to Amazon ECR, and then will deploy a new task definition to Amazon ECS, on every push to the default branch.
17+
On every new release in your {% data variables.product.company_short %} repository, the {% data variables.product.prodname_actions %} workflow builds and pushes a new container image to Amazon ECR, and then deploys a new task definition to Amazon ECS.
1918

2019
### Prerequisites
21-
To adopt this workflow, you will first need to complete the following setup steps:
2220

23-
#### Create an ECR repository to store your images
24-
For example, using [the AWS CLI](https://aws.amazon.com/cli/):
21+
Before creating your {% data variables.product.prodname_actions %} workflow, you will first need to complete the following setup steps for Amazon ECR and ECS:
2522

26-
{% raw %}
27-
```bash{:copy}
28-
aws ecr create-repository \
29-
--repository-name $ECR_REPOSITORY \
30-
--region $AWS_REGION
31-
```
32-
{% endraw %}
23+
1. Create an Amazon ECR repository to store your images.
3324

34-
Replace the value of `$ECR_REPOSITORY` in the workflow below with your repository's name.
25+
For example, using [the AWS CLI](https://aws.amazon.com/cli/):
3526

36-
Replace the value of `$AWS_REGION` in the workflow below with your repository's region.
27+
{% raw %}```bash{:copy}
28+
aws ecr create-repository \
29+
--repository-name $ECR_REPOSITORY \
30+
--region $AWS_REGION
31+
```{% endraw %}
3732
38-
#### Create an ECS task definition, an ECS cluster, and an ECS service
39-
For details, follow [the Getting Started guide on the ECS console](https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun).
33+
Ensure that you use the same Amazon ECR repository name for the `ECR_REPOSITORY` variable in the workflow below.
4034
41-
Replace the values for `$ECS_SERVICE` and `$ECS_CLUSTER` in the workflow below with your service and cluster names.
35+
Ensure that you use the same AWS region value for the `AWS_REGION` variable in the workflow below.
4236
43-
#### Store your ECS task definition as a JSON file in your repository
44-
The format should mirror the output generated by:
37+
2. Create an Amazon ECS task definition, cluster, and service.
4538
46-
{% raw %}
47-
```bash{:copy}
48-
aws ecs register-task-definition --generate-cli-skeleton
49-
```
50-
{% endraw %}
39+
For details, follow the [Getting started wizard on the Amazon ECS console](https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun), or the [Getting started guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/getting-started-fargate.html) in the Amazon ECS documentation.
40+
41+
Ensure that you note the names you set for the Amazon ECS service and cluster, and use them for the `ECS_SERVICE` and `ECS_CLUSTER` variables in the workflow below.
42+
43+
3. Store your Amazon ECS task definition as a JSON file in your {% data variables.product.company_short %} repository.
44+
45+
The format of the file should be the same as the output generated by:
5146
52-
Replace the value of `$ECS_TASK_DEFINITION` in the workflow below with your JSON file's name.
47+
{% raw %}```bash{:copy}
48+
aws ecs register-task-definition --generate-cli-skeleton
49+
```{% endraw %}
5350
54-
Replace the value of `$CONTAINER_NAME` in the workflow below with the name of the container in the containerDefinitions section of the task definition.
51+
Ensure that you set the `ECS_TASK_DEFINITION` variable in the workflow below as the path to the JSON file.
5552
56-
#### Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`
57-
See the documentation for each action used below for the recommended IAM policies for this IAM user, and best practices on handling the access key credentials.
53+
Ensure that you set the `CONTAINER_NAME` variable in the workflow below as the container name in the `containerDefinitions` section of the task definition.
5854
59-
### Workflow
60-
After updating the env section, follow these instructions to add the workflow to your repository:
55+
4. Create {% data variables.product.prodname_actions %} secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` to store the values for your Amazon IAM access key.
56+
57+
For more information on creating secrets for {% data variables.product.prodname_actions %}, see "[Encrypted secrets](t/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository)."
58+
59+
See the documentation for each action used below for the recommended IAM policies for the IAM user, and methods for handling the access key credentials.
60+
61+
### Creating the workflow
62+
63+
Once you've completed the prerequisites, you can proceed with creating the workflow.
64+
65+
The following example workflow demonstrates how to build a container image and push it to Amazon ECR. It then updates the task definition with the new image ID, and deploys the task definition to Amazon ECS.
66+
67+
Ensure that you provide your own values for all the variables in the `env:` key of the workflow.
6168
6269
{% raw %}
63-
```bash{:copy}
70+
```yaml{:copy}
6471
name: Deploy to Amazon ECS
6572
6673
on:
@@ -87,58 +94,57 @@ jobs:
8794
runs-on: ubuntu-latest
8895
8996
steps:
90-
- name: Checkout
91-
uses: actions/checkout@v2
92-
93-
- name: Configure AWS credentials
94-
uses: aws-actions/configure-aws-credentials@v1
95-
with:
96-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
97-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
98-
aws-region: $AWS_REGION
99-
100-
- name: Login to Amazon ECR
101-
id: login-ecr
102-
uses: aws-actions/amazon-ecr-login@v1
103-
104-
- name: Build, tag, and push image to Amazon ECR
105-
id: build-image
106-
env:
107-
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
108-
IMAGE_TAG: ${{ github.sha }}
109-
run: |
110-
# Build a docker container and
111-
# push it to ECR so that it can
112-
# be deployed to ECS.
113-
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
114-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
115-
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_ENV
116-
117-
- name: Fill in the new image ID in the Amazon ECS task definition
118-
id: task-def
119-
uses: aws-actions/amazon-ecs-render-task-definition@v1
120-
with:
121-
task-definition: $ECS_TASK_DEFINITION
122-
container-name: $CONTAINER_NAME
123-
image: ${{ steps.build-image.outputs.image }}
124-
125-
- name: Deploy Amazon ECS task definition
126-
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
127-
with:
128-
task-definition: ${{ steps.task-def.outputs.task-definition }}
129-
service: $ECS_SERVICE
130-
cluster: $ECS_CLUSTER
131-
wait-for-service-stability: true
97+
- name: Checkout
98+
uses: actions/checkout@v2
99+
100+
- name: Configure AWS credentials
101+
uses: aws-actions/configure-aws-credentials@v1
102+
with:
103+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
104+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
105+
aws-region: $AWS_REGION
106+
107+
- name: Login to Amazon ECR
108+
id: login-ecr
109+
uses: aws-actions/amazon-ecr-login@v1
110+
111+
- name: Build, tag, and push image to Amazon ECR
112+
id: build-image
113+
env:
114+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
115+
IMAGE_TAG: ${{ github.sha }}
116+
run: |
117+
# Build a docker container and
118+
# push it to ECR so that it can
119+
# be deployed to ECS.
120+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
121+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
122+
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_ENV
123+
124+
- name: Fill in the new image ID in the Amazon ECS task definition
125+
id: task-def
126+
uses: aws-actions/amazon-ecs-render-task-definition@v1
127+
with:
128+
task-definition: $ECS_TASK_DEFINITION
129+
container-name: $CONTAINER_NAME
130+
image: ${{ steps.build-image.outputs.image }}
131+
132+
- name: Deploy Amazon ECS task definition
133+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
134+
with:
135+
task-definition: ${{ steps.task-def.outputs.task-definition }}
136+
service: $ECS_SERVICE
137+
cluster: $ECS_CLUSTER
138+
wait-for-service-stability: true
132139
```
133140
{% endraw %}
134141

135142
### Additional resources
136-
The following additional resources may also be of use:
137-
138-
1. Best practices on handling AWS access key credentials: https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html
139-
1. Amazon ECR: https://aws.amazon.com/ecr/
140-
1. Amazon ECS: https://aws.amazon.com/ecs/
141-
1. Official AWS GitHub action to configure AWS credentials: https://github.com/aws-actions/configure-aws-credentials
142-
1. Official AWS GitHub action to login to Amazon ECR: https://github.com/aws-actions/amazon-ecr-login
143-
1. Official AWS GitHub action to “render” and Amazon ECS task definition: https://github.com/aws-actions/amazon-ecs-render-task-definition
144-
1. Official AWS GitHub action to register an Amazon ECS task definition and deploy it to an ECS service: https://github.com/aws-actions/amazon-ecs-deploy-task-definition
143+
144+
For more information on the services used in these examples, see the following documentation:
145+
146+
* "[Security best practices in IAM](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)" in the Amazon AWS documentation.
147+
* Official AWS "[Configure AWS Credentials](https://github.com/aws-actions/configure-aws-credentials)" action.
148+
* Official AWS [Amazon ECR "Login"](https://github.com/aws-actions/amazon-ecr-login) action.
149+
* Official AWS [Amazon ECS "Render Task Definition"](https://github.com/aws-actions/amazon-ecs-render-task-definition) action.
150+
* Official AWS [Amazon ECS "Deploy Task Definition"](https://github.com/aws-actions/amazon-ecs-deploy-task-definition) action.

0 commit comments

Comments
 (0)