-
Notifications
You must be signed in to change notification settings - Fork 1
77 lines (65 loc) · 3.16 KB
/
deploy_to_ecs_prod.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# This workflow will build and push a new container image to Amazon ECR
on:
push:
branches: ["release"]
name: Deploy to ECS - production
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
# uses GitHub environment
environment:
name: Production
url: "https://analytics.plio.in"
steps:
- name: Checkout
uses: actions/checkout@v2
# sets the AWS credentials for use in next steps. This hooks comes with a post-hook as well that clears these keys once workflow ends.
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
# log into ECR using the AWS credentials
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Set current timestamp for image tag
id: timestamp
run: echo "::set-output name=timestamp::$(date +'%Y-%m-%d-%H-%M-%S')"
# build the docker image and push to Elastic Container Registry.
# Sets the name of the image as output to be used in further steps.
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: plio-analytics-production
IMAGE_TAG: ${{ github.sha }}-${{ steps.timestamp.outputs.timestamp }}
run: |
# Build a docker container and push it to ECR
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
echo "Pushing image to ECR..."
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
# Download the task definition created at AWS ECS
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition plio-analytics-production --query taskDefinition > task-definition.json
# Creates a new revision of the task definition with latest image id.
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: plio-analytics-production
image: ${{ steps.build-image.outputs.image }}
# Uses the ECS service for analytics to create a new task from the new task definition. The new task is created while the previous task is already running. This happens based on the minimum healthy percentage and maximum percentage configured during service creation.
# After service completion and stability, it removes the previous task from older task definition.
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: plio-analytics-production
cluster: plio-production-cluster
wait-for-service-stability: true