Repository navigation
82 lines (76 loc) · 2.68 KB
/
Copy pathdeploy.yml
File metadata and controls
82 lines (76 loc) · 2.68 KB
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
82
name: deploy
on:
push:
branches: [main]
pull_request:
schedule:
- cron: "5 23 * * 1-5"
workflow_dispatch:
inputs:
production:
description: Also deploy to production (needs approval)
type: boolean
default: false
permissions:
contents: read
env:
SIMULATE: ${{ vars.LIVE_DEPLOYS != 'true' }}
AWS_REGION: ap-southeast-2
ECR_REPOSITORY: payments-quote
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Unit tests
run: python3 -m unittest discover -s tests -t .
deploy-staging:
if: github.event_name != 'pull_request'
needs: test
runs-on: ubuntu-latest
timeout-minutes: 15
environment: staging
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
if: vars.AWS_ROLE_ARN != ''
with:
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
- name: Build and push image
run: |
source .github/simulate.sh
docker build -t "$ECR_REPOSITORY:${{ github.sha }}" .
docker push "$ECR_REPOSITORY:${{ github.sha }}"
- name: Deploy to ECS
run: |
source .github/simulate.sh
aws ecs register-task-definition --cli-input-json file://deploy/task-definition.json
aws ecs update-service --cluster payments-staging --service quote-api --force-new-deployment
aws ecs wait services-stable --cluster payments-staging --services quote-api
deploy-production:
if: github.event_name == 'workflow_dispatch' && inputs.production
needs: deploy-staging
runs-on: ubuntu-latest
timeout-minutes: 15
environment: production
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
if: vars.AWS_ROLE_ARN != ''
with:
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
- name: Deploy to ECS
run: |
source .github/simulate.sh
aws ecs register-task-definition --cli-input-json file://deploy/task-definition.json
aws ecs update-service --cluster payments-production --service quote-api --force-new-deployment
aws ecs wait services-stable --cluster payments-production --services quote-api