Skip to content

Commit 4bb3b26

Browse files
Create aws.yml
1 parent 1a30b6f commit 4bb3b26

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

.github/workflows/aws.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
push:
28+
branches:
29+
- master
30+
31+
name: Deploy to Amazon ECS
32+
33+
jobs:
34+
deploy:
35+
name: Deploy
36+
runs-on: ubuntu-latest
37+
environment: production
38+
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v2
42+
43+
- name: Configure AWS credentials
44+
uses: aws-actions/configure-aws-credentials@v1
45+
with:
46+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
47+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
48+
aws-region: us-east-2
49+
50+
- name: Login to Amazon ECR
51+
id: login-ecr
52+
uses: aws-actions/amazon-ecr-login@v1
53+
54+
- name: Build, tag, and push image to Amazon ECR
55+
id: build-image
56+
env:
57+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
58+
ECR_REPOSITORY: git-deploy-aws-ecs
59+
IMAGE_TAG: ${{ github.sha }}
60+
run: |
61+
# Build a docker container and
62+
# push it to ECR so that it can
63+
# be deployed to ECS.
64+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
65+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
66+
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
67+
68+
- name: Fill in the new image ID in the Amazon ECS task definition
69+
id: task-def
70+
uses: aws-actions/amazon-ecs-render-task-definition@v1
71+
with:
72+
task-definition: task-definition.json
73+
container-name: git-deploy-aws-ecs-container
74+
image: ${{ steps.build-image.outputs.image }}
75+
76+
- name: Deploy Amazon ECS task definition
77+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
78+
with:
79+
task-definition: ${{ steps.task-def.outputs.task-definition }}
80+
service: git-deploy-aws-ecs-container-service
81+
cluster: test-cluster
82+
wait-for-service-stability: true

0 commit comments

Comments
 (0)