-
Notifications
You must be signed in to change notification settings - Fork 34
81 lines (69 loc) · 2.3 KB
/
build-deploy-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
78
79
80
81
# Copyright 2020 ChainSafe Systems
# SPDX-License-Identifier: LGPL-3.0-only
name: Build & Deploy PROD
on:
workflow_call:
inputs:
tag:
required: true
type: string
secrets:
aws_region:
required: true
aws_account_id:
required: true
ecr_repo:
required: true
ecs_cluster:
required: true
ecs_service:
required: true
env:
ENVIRONMENT: PROD
jobs:
build:
name: build_deploy_prod
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
# download the source code into the runner
- name: checkout
uses: actions/checkout@v2
- name: Set output
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.aws_account_id }}:role/github-actions-role
aws-region: ${{ secrets.aws_region }}
role-session-name: GithubActions
# gather metadata from git & github actions to reference in docker
- name: git & github metadata
id: metadata
uses: docker/metadata-action@v3
with:
images: ${{ secrets.aws_account_id }}.dkr.ecr.${{ secrets.aws_region }}.amazonaws.com/${{ secrets.ecr_repo }}
# login in docker repository
- name: docker login
uses: aws-actions/amazon-ecr-login@v1
# build a docker image
- name: docker & push image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ secrets.aws_account_id }}.dkr.ecr.${{ secrets.aws_region }}.amazonaws.com/${{ secrets.ecr_repo }}:latest
${{ secrets.aws_account_id }}.dkr.ecr.${{ secrets.aws_region }}.amazonaws.com/${{ secrets.ecr_repo }}:${{ steps.vars.outputs.tag }}
# deploy to AWS ECS
- name: Deploy to Amazon ECS
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: infra/aws-ecs/task_definition_${{ env.ENVIRONMENT }}.json
service: ${{ secrets.ecs_service }}
cluster: ${{ secrets.ecs_cluster }}
wait-for-service-stability: true