Skip to content

Commit 30c5383

Browse files
Create aws.yml
1 parent 083554d commit 30c5383

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

.github/workflows/aws.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# This workflow will build and push a new container image to Amazon ECR,
2+
# and then will deploy a new task definition to Amazon ECS, when a release is created
3+
#
4+
# To use this workflow, you will need to complete the following set-up steps:
5+
#
6+
# 1. Create an ECR repository to store your images.
7+
# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`.
8+
# Replace the value of `ECR_REPOSITORY` in the workflow below with your repository's name.
9+
# Replace the value of `aws-region` in the workflow below with your repository's region.
10+
#
11+
# 2. Create an ECS task definition, an ECS cluster, and an ECS service.
12+
# For example, follow the Getting Started guide on the ECS console:
13+
# https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun
14+
# Replace the values for `service` and `cluster` in the workflow below with your service and cluster names.
15+
#
16+
# 3. Store your ECS task definition as a JSON file in your repository.
17+
# The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`.
18+
# Replace the value of `task-definition` in the workflow below with your JSON file's name.
19+
# Replace the value of `container-name` in the workflow below with the name of the container
20+
# in the `containerDefinitions` section of the task definition.
21+
#
22+
# 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.
23+
# See the documentation for each action used below for the recommended IAM policies for this IAM user,
24+
# and best practices on handling the access key credentials.
25+
26+
on:
27+
release:
28+
types: [created]
29+
30+
name: Deploy to Amazon ECS
31+
32+
jobs:
33+
deploy:
34+
name: Deploy
35+
runs-on: ubuntu-latest
36+
environment: production
37+
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v2
41+
42+
- name: Configure AWS credentials
43+
uses: aws-actions/configure-aws-credentials@v1
44+
with:
45+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
46+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
47+
aws-region: us-east-2
48+
49+
- name: Login to Amazon ECR
50+
id: login-ecr
51+
uses: aws-actions/amazon-ecr-login@v1
52+
53+
- name: Build, tag, and push image to Amazon ECR
54+
id: build-image
55+
env:
56+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
57+
ECR_REPOSITORY: my-ecr-repo
58+
IMAGE_TAG: ${{ github.sha }}
59+
run: |
60+
# Build a docker container and
61+
# push it to ECR so that it can
62+
# be deployed to ECS.
63+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
64+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
65+
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
66+
67+
- name: Fill in the new image ID in the Amazon ECS task definition
68+
id: task-def
69+
uses: aws-actions/amazon-ecs-render-task-definition@v1
70+
with:
71+
task-definition: task-definition.json
72+
container-name: sample-app
73+
image: ${{ steps.build-image.outputs.image }}
74+
75+
- name: Deploy Amazon ECS task definition
76+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
77+
with:
78+
task-definition: ${{ steps.task-def.outputs.task-definition }}
79+
service: sample-app-service
80+
cluster: default
81+
wait-for-service-stability: true

0 commit comments

Comments
 (0)