-
Notifications
You must be signed in to change notification settings - Fork 0
70 lines (59 loc) · 2.28 KB
/
deploy-api.yaml
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
name: Deploy investment funds api to ECS
on:
pull_request:
branches:
- main
push:
paths:
- api/**
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Configure AWS credentials for build and push
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_GITHUB_DOCKER_BUILD_AND_PUSH_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Log in to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push api Docker image
id: build-and-push-api-docker-image
uses: docker/build-push-action@v5
with:
file: Dockerfile-api
push: true
tags: |
${{ secrets.AWS_ECR_REPOSITORY }}/investmentfunds/api:latest
${{ secrets.AWS_ECR_REPOSITORY }}/investmentfunds/api:${{ github.sha }}
- name: Configure AWS credentials for deploy
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_GITHUB_ECS_DEPLOY_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Download task definition
id: download-task-definition
run: |
aws ecs describe-task-definition --task-definition ${{ vars.AWS_ECS_TASK_DEFINITION_FAMILY }} --query taskDefinition > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: ecs-render-task-definition
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ vars.AWS_ECS_API_CONTAINER_NAME }}
image: ${{ secrets.AWS_ECR_REPOSITORY }}/investmentfunds/api:${{ github.sha }}
- name: Deploy to Amazon ECS service
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.ecs-render-task-definition.outputs.task-definition }}
service: ${{ vars.AWS_ECS_API_SERVICE_NAME }}
cluster: ${{ vars.AWS_ECS_CLUSTER_NAME }}