-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (87 loc) · 2.92 KB
/
init.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Init
on:
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
ecs-check:
runs-on: ubuntu-latest
outputs:
service_exists: ${{ steps.set-output.outputs.service_exists }}
task_definition_arn: ${{ steps.set-output.outputs.task_definition_arn }}
steps:
- uses: actions/checkout@v4
- name: Check ECS Service
id: check-ecs-service
uses: ./.github/actions/check_svc
with:
aws_region: ${{ vars.aws_region }}
aws_role: ${{ vars.aws_account_id }}:role/${{ vars.aws_role }}
tfvars_file: "tf/variables.tfvars"
- name: Set output for service existence
id: set-output
shell: bash
run: |
echo "service_exists=${{ env.SERVICE_EXISTS }}" >> $GITHUB_OUTPUT
echo "task_definition_arn=${{ env.TASK_DEFINITION_ARN }}" >> $GITHUB_OUTPUT
ecr:
runs-on: ubuntu-latest
env:
TF_VAR_ecr_repository_name: ${{ github.event.repository.name }}
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ vars.aws_region }}
role-to-assume: arn:aws:iam::${{ vars.aws_account_id }}:role/${{ vars.aws_role }}
role-session-name: GitHubActions
- name: Init
shell: bash
run: |
cd tf/ecr
terraform init
- name: Deploy
shell: bash
id: deploy
run: |
cd tf/ecr
terraform apply -auto-approve -var-file=${{ github.workspace }}/tf/variables.tfvars
build:
needs:
- ecs-check
- ecr
if: ${{ needs.ecs-check.outputs.service_exists == 'false' }}
uses: ./.github/workflows/build.yml
with:
aws_account_id: ${{ vars.AWS_ACCOUNT_ID }}
aws_region: ${{ vars.AWS_REGION }}
aws_role: ${{ vars.AWS_ROLE }}
setup:
needs:
- ecs-check
- build
if: always()
uses: ./.github/workflows/setup.yml
with:
aws_account_id: ${{ vars.AWS_ACCOUNT_ID }}
aws_region: ${{ vars.AWS_REGION }}
aws_role: ${{ vars.AWS_ROLE }}
# Conditionally use task definition ARN from check if service exists, or from build if not
task_definition_arn: ${{ needs.ecs-check.outputs.service_exists == 'true' && needs.ecs-check.outputs.task_definition_arn || needs.build.outputs.task_definition_arn }}
test:
needs: setup
runs-on: ubuntu-latest
steps:
- name: echo url
run: echo url is ${{ needs.setup.outputs.api_invoke_url }}
- name: Check if API returns 200
run: |
STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}\n" ${{ needs.setup.outputs.api_invoke_url }}/host)
if [ "$STATUS_CODE" -eq 200 ]; then
echo "API is working correctly. Status code: $STATUS_CODE"
else
echo "API test failed. Status code: $STATUS_CODE"
exit 1
fi