-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (105 loc) · 2.8 KB
/
deploy.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: 'Deploy'
on:
push:
branches: ['workshop/*']
jobs:
setup:
name: 'Setup'
outputs:
my_name: ${{ steps.set-name.outputs.my_name }}
runs-on: ubuntu-latest
steps:
- name: 'Setup'
id: set-name
run: echo "my_name=${BRANCH##*/}" >> "$GITHUB_OUTPUT"
env:
BRANCH: ${{ github.ref_name }}
run-tests:
name: 'Run frontend tests'
runs-on: ubuntu-latest
defaults:
run:
working-directory: 'frontend'
steps:
- name: Checkout repository
# Task A.1:
#
# Answer A.1:
uses: actions/checkout@v4
#
- name: Install dependencies
# Task A.1:
#
# Answer A.1:
run: yarn install
#
- name: Run tests
# Task A.1:
#
# Answer A.1:
run: yarn test
#
build:
name: 'Build Docker image and push to registry'
# Task A.2:
# needs: [setup]
# Answer A.2:
needs: [setup, run-tests]
#
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: 'ghcr.io'
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push image to registry
uses: docker/build-push-action@v5
with:
push: 'true'
tags: 'ghcr.io/${{ github.repository }}/${{ needs.setup.outputs.my_name }}:latest'
context: 'frontend'
deploy:
name: 'Deploy using Terraform'
runs-on: ubuntu-latest
needs: [build, setup]
env:
TF_VAR_revision_suffix: ${{ github.sha }}
TF_VAR_my_name: ${{ needs.setup.outputs.my_name }}
TF_VAR_repository: ${{ github.repository }}
ARM_CLIENT_ID: ${{ vars.ARM_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ vars.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ vars.ARM_TENANT_ID }}
ARM_USE_OIDC: 'true'
permissions:
contents: read
id-token: write
environment: prod
defaults:
run:
working-directory: 'terraform'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Init Terraform
run: terraform init
- name: Set Terraform workspace
run: terraform workspace new $TF_VAR_my_name || terraform workspace select $TF_VAR_my_name
- name: Run Terraform plan
run: terraform plan
- name: Run Terraform apply
# Task A.3
#
# Answer A.3
run: terraform apply -auto-approve
#