@@ -7,10 +7,6 @@ name: build
7
7
# name of GitHub event that triggers workflow
8
8
# https://help.github.com/en/actions/reference/events-that-trigger-workflows#watch-event-watch
9
9
on :
10
- # trigger when I star my own repo
11
- watch :
12
- types : [started]
13
-
14
10
# trigger via webhook
15
11
# https://github.com/adamrushuk/devops-lab/blob/master/TriggerCustomAction.ps1#L28
16
12
repository_dispatch :
21
17
workflow_dispatch :
22
18
inputs : {}
23
19
20
+ # permissions for oidc login
21
+ # https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect
22
+ permissions :
23
+ id-token : write # This is required for requesting the JWT
24
+ contents : read # This is required for actions/checkout
25
+
24
26
# global environment variables
25
27
# https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables
26
28
env :
27
29
# prefix: used for some globally unique name requirements
28
30
PREFIX : arshz
29
31
30
32
# debug
31
- CI_DEBUG : false
33
+ CI_DEBUG : true
32
34
33
- # azure creds
35
+ # azure creds (used with OIDC auth)
34
36
ARM_CLIENT_ID : ${{ secrets.ARM_CLIENT_ID }}
35
- ARM_CLIENT_SECRET : ${{ secrets.ARM_CLIENT_SECRET }}
36
37
ARM_SUBSCRIPTION_ID : ${{ secrets.ARM_SUBSCRIPTION_ID }}
37
38
ARM_TENANT_ID : ${{ secrets.ARM_TENANT_ID }}
38
39
46
47
FORCE_TEST_FAIL : false
47
48
K8S_TLS_SECRET_NAME : tls-secret
48
49
KEY_VAULT_CERT_NAME : wildcard-thehypepipe-co-uk
49
- KEY_VAULT_NAME : kv-rush-iz6y
50
+ KEY_VAULT_NAME : kv-rush-aqy2
50
51
KEY_VAULT_RESOURCE_GROUP_NAME : rg-keyvault-acmebot
51
52
# NOTE: "eastus" is cheaper than "uksouth"
52
53
LOCATION : eastus
59
60
# terraform
60
61
TF_IN_AUTOMATION : " true"
61
62
TF_INPUT : " false"
63
+ # https://developer.hashicorp.com/terraform/internals/debugging
64
+ TF_LOG : " ERROR" # TRACE, DEBUG, INFO, WARN or ERROR
62
65
TF_PLAN : " tfplan"
63
66
# https://github.com/hashicorp/terraform/releases
64
- TF_VERSION : " 1.0.10 "
67
+ TF_VERSION : " 1.3.7 "
65
68
TF_WORKING_DIR : ./terraform
66
- # https://github.com/terraform-linters/tflint-ruleset- azurerm/releases
67
- TFLINT_RULESET_AZURERM_VERSION : " v0.13.2 "
68
- # https://github. com/terraform-linters/tflint/releases
69
- TFLINT_VERSION : " v0.33.1 "
69
+ # azurerm provider oidc
70
+ # https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/service_principal_oidc
71
+ # https://developer.hashicorp. com/terraform/language/settings/backends/azurerm#oidc_request_token
72
+ ARM_USE_OIDC : " true "
70
73
71
74
# Env var concatenation is currently not supported at Workflow or Job scope. See workaround below:
72
75
# https://github.community/t5/GitHub-Actions/How-can-we-concatenate-multiple-env-vars-at-workflow-and-job/td-p/48489
@@ -75,11 +78,11 @@ jobs:
75
78
build-and-deploy :
76
79
# always pin versions
77
80
# view installed software: https://docs.github.com/en/free-pro-team@latest/actions/reference/specifications-for-github-hosted-runners#supported-software
78
- runs-on : ubuntu-18 .04
81
+ runs-on : ubuntu-22 .04
79
82
80
83
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idenvironment
81
84
environment :
82
- name : dev_environment
85
+ name : dev
83
86
url : " https://argocd.${{ env.ROOT_DOMAIN_NAME }}"
84
87
85
88
# only run if owner triggered action
88
91
steps :
89
92
# Checkout
90
93
# https://github.com/marketplace/actions/checkout
91
- - uses : actions/checkout@v2
94
+ - uses : actions/checkout@v3
92
95
# specify different branch
93
96
# NOT required as I've changed the default branch to develop
94
97
# with:
@@ -105,13 +108,19 @@ jobs:
105
108
echo "DNS_DOMAIN_NAME=nexus.${{ env.ROOT_DOMAIN_NAME }}" >> $GITHUB_ENV
106
109
echo "DOCKER_FQDN=docker.${{ env.ROOT_DOMAIN_NAME }}" >> $GITHUB_ENV
107
110
echo "TERRAFORM_STORAGE_ACCOUNT=${{ env.PREFIX }}sttfstate${{ env.LOCATION }}001" >> $GITHUB_ENV
111
+ echo "TERRAFORM_STORAGE_CONTAINER=terraform" >> $GITHUB_ENV
108
112
echo "TERRAFORM_STORAGE_RG=${{ env.PREFIX }}-rg-tfstate-dev-001" >> $GITHUB_ENV
109
113
echo "VELERO_STORAGE_ACCOUNT=${{ env.PREFIX }}stbckuksouth001" >> $GITHUB_ENV
110
- echo "VELERO_STORAGE_RG=${{ env.PREFIX }}-rg-velero-dev-001" >> $GITHUB_ENV
111
114
112
115
# Login
113
- - name : Login to Azure
114
- run : ./scripts/azure_login.sh
116
+ # https://github.com/Azure/login
117
+ - name : Login via OIDC to Azure Public Cloud (az cli and az powershell)
118
+ uses : azure/login@v1
119
+ with :
120
+ client-id : ${{ secrets.ARM_CLIENT_ID }}
121
+ tenant-id : ${{ secrets.ARM_TENANT_ID }}
122
+ subscription-id : ${{ secrets.ARM_SUBSCRIPTION_ID }}
123
+ enable-AzPSSession : true
115
124
116
125
# This is required when developing after the initial build, and the AKS cluster may have been stopped
117
126
# Ensure AKS cluster is running, else timeouts will occur on k8s Terraform apply tasks
@@ -123,8 +132,9 @@ jobs:
123
132
- name : Create Storage Account for Terraform state
124
133
run : ./scripts/storage_create.sh
125
134
126
- - name : Lookup Storage Key
127
- run : ./scripts/storage_key.sh
135
+ # TODO remove this step
136
+ # - name: Lookup Storage Key
137
+ # run: ./scripts/storage_key.sh
128
138
129
139
- name : Replace tokens in Terraform config files
130
140
run : pwsh -command "./scripts/Replace-Tokens.ps1"
@@ -133,26 +143,47 @@ jobs:
133
143
HELM_CHART_REPO_DEPLOY_PRIVATE_KEY : ${{ secrets.HELM_CHART_REPO_DEPLOY_PRIVATE_KEY }}
134
144
IFTTT_WEBHOOK_KEY : ${{ secrets.IFTTT_WEBHOOK_KEY }}
135
145
136
- - name : Create zip file of Function App
137
- run : pwsh -command "./function_app/CreateFunctionAppZip.ps1"
138
-
139
146
# Terraform
140
- - uses : hashicorp/setup-terraform@v1
147
+ # https://github.com/hashicorp/setup-terraform
148
+ - uses : hashicorp/setup-terraform@v2
141
149
with :
142
150
terraform_version : ${{ env.TF_VERSION }}
143
151
144
152
- name : Terraform Init / Validate
145
153
run : |
146
- terraform init
154
+ echo 'Running terraform init...'
155
+ terraform init \
156
+ -backend-config="resource_group_name=$TERRAFORM_STORAGE_RG" \
157
+ -backend-config="storage_account_name=$TERRAFORM_STORAGE_ACCOUNT"
158
+
159
+ # validate
160
+ echo 'Running terraform validate...'
147
161
terraform validate
148
162
working-directory : ${{ env.TF_WORKING_DIR }}
149
163
150
- - name : Terraform Lint
151
- run : ./scripts/tflint.sh
152
- env :
153
- TF_WORKING_DIR : ${{ env.TF_WORKING_DIR }}
154
- TFLINT_RULESET_AZURERM_VERSION : ${{ env.TFLINT_RULESET_AZURERM_VERSION }}
155
- TFLINT_VERSION : ${{ env.TFLINT_VERSION }}
164
+ # https://github.com/aquasecurity/tfsec-action
165
+ - name : Run tfsec security scan
166
+ uses : aquasecurity/tfsec-action@v1.0.3
167
+ with :
168
+ working_directory : ${{ env.TF_WORKING_DIR }}
169
+ soft_fail : true
170
+
171
+ # https://github.com/bridgecrewio/checkov-action
172
+ - name : Run Checkov security scan
173
+ id : checkov
174
+ uses : bridgecrewio/checkov-action@master
175
+ with :
176
+ directory : ${{ env.TF_WORKING_DIR }}
177
+ # check: CKV_AWS_1 # optional: run only a specific check_id. can be comma separated list
178
+ # optional: skip a specific check_id. can be comma separated list
179
+ skip_check : CKV2_AZURE_1,CKV_AZURE_4,CKV_AZURE_6,CKV2_AZURE_8,CKV2_AZURE_21,CKV_AZURE_33,CKV_AZURE_35,CKV_AZURE_117,CKV_AZURE_141
180
+ quiet : true # optional: display only failed checks
181
+ soft_fail : true # optional: do not return an error code if there are failed checks
182
+ framework : terraform # optional: run only on a specific infrastructure {cloudformation,terraform,kubernetes,all}
183
+ output_format : sarif # optional: the output format, one of: cli, json, junitxml, github_failed_only, or sarif. Default: sarif
184
+ download_external_modules : true # optional: download external terraform modules from public git repositories and terraform registry
185
+ # log_level: DEBUG # optional: set log level. Default WARNING
186
+ # config_file: path/this_file
156
187
157
188
- name : 👀 Terraform Plan
158
189
id : plan
@@ -182,6 +213,7 @@ jobs:
182
213
NEXUS_USER_PASSWORD : ${{ secrets.NEXUS_USER_PASSWORD }}
183
214
184
215
# Docker
216
+ # https://github.com/Azure/docker-login
185
217
- name : Docker repo login
186
218
uses : Azure/docker-login@v1
187
219
with :
@@ -197,17 +229,18 @@ jobs:
197
229
run : pwsh -command "./scripts/Fix-FunctionApp.ps1"
198
230
env :
199
231
FUNCTION_APP_NAME : " ${{ env.PREFIX }}-funcapp"
200
- FUNCTION_APP_RG : " ${{ env.PREFIX }}-rg-function-app "
232
+ FUNCTION_APP_RG : " ${{ env.PREFIX }}-rg-aks-dev-001 "
201
233
202
234
# Pester tests
203
235
- name : 🧪 Run Pester tests
204
236
continue-on-error : true
205
237
run : pwsh -command "./scripts/Start-Test.ps1"
206
238
239
+ # https://github.com/actions/upload-artifact
207
240
- name : Archive test artifacts
208
- uses : actions/upload-artifact@v1
241
+ uses : actions/upload-artifact@v3
209
242
with :
210
- name : test results
243
+ name : test- results
211
244
path : test/pester-test-results.xml
212
245
if : always()
213
246
@@ -216,35 +249,47 @@ jobs:
216
249
run : pwsh -command "Unregister-PSRepository -Name nuget.org-proxy -Verbose"
217
250
218
251
# Shows at the bottom of a run: https://github.com/adamrushuk/devops-lab/runs/1035347513?check_suite_focus=true
219
- - name : Pester report
220
- uses : zyborg/pester-tests-report@v1
221
- with :
222
- test_results_path : test/pester-test-results.xml
223
- report_name : pester_tests
224
- report_title : Pester Tests
225
- github_token : ${{ secrets.GITHUB_TOKEN }}
252
+ # https://github.com/zyborg/pester-tests-report
253
+ # - name: Pester report
254
+ # uses: zyborg/pester-tests-report@v1
255
+ # with:
256
+ # test_results_path: test/pester-test-results.xml
257
+ # report_name: pester_tests
258
+ # report_title: Pester Tests
259
+ # github_token: ${{ secrets.GITHUB_TOKEN }}
260
+
261
+ # - uses: dorny/test-reporter@v1.6.0
262
+ # with:
263
+ # # artifact: test-results # artifact name
264
+ # name: Pester Tests Results # Name of the check run which will be created
265
+ # path: 'test/pester-test-results.xml' # Path to test results (inside artifact .zip)
266
+ # reporter: java-junit # Format of test results
226
267
227
268
# Notify
228
269
- name : Notify slack
229
270
continue-on-error : true
230
271
env :
231
272
SLACK_CHANNEL_ID : ${{ secrets.SLACK_CHANNEL_ID }}
232
273
SLACK_BOT_TOKEN : ${{ secrets.SLACK_BOT_TOKEN }}
233
- run : ./scripts/send_slack_message.sh "[aks-nexus-velero ] Build complete"
274
+ run : ./scripts/send_slack_message.sh "[devops-lab ] Build complete"
234
275
235
276
# used for any windows-only tasks
236
277
test-windows :
237
278
needs : build-and-deploy
238
279
239
280
# https://github.com/actions/virtual-environments
240
- runs-on : windows-2019
281
+ runs-on : windows-2022
282
+
283
+ # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idenvironment
284
+ environment :
285
+ name : dev
241
286
242
287
# only run if owner triggered action
243
288
if : github.actor == github.event.repository.owner.login
244
289
245
290
steps :
246
291
# Checkout
247
- - uses : actions/checkout@v2
292
+ - uses : actions/checkout@v3
248
293
249
294
# Init tasks - inc Env var concatenation
250
295
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files
@@ -256,8 +301,14 @@ jobs:
256
301
echo "DNS_DOMAIN_NAME=nexus.${{ env.ROOT_DOMAIN_NAME }}" | Out-File -Append -Encoding utf8 -FilePath "$env:GITHUB_ENV"
257
302
258
303
# Login
259
- - name : Login to Azure
260
- run : ./scripts/azure_login.ps1
304
+ # https://github.com/Azure/login
305
+ - name : Login via OIDC to Azure Public Cloud (az cli and az powershell)
306
+ uses : azure/login@v1
307
+ with :
308
+ client-id : ${{ secrets.ARM_CLIENT_ID }}
309
+ tenant-id : ${{ secrets.ARM_TENANT_ID }}
310
+ subscription-id : ${{ secrets.ARM_SUBSCRIPTION_ID }}
311
+ enable-AzPSSession : true
261
312
262
313
# Chocolatey
263
314
- name : Test Nexus Chocolatey proxy repo
0 commit comments