@@ -7,10 +7,6 @@ name: build
77# name of GitHub event that triggers workflow
88# https://help.github.com/en/actions/reference/events-that-trigger-workflows#watch-event-watch
99on :
10- # trigger when I star my own repo
11- watch :
12- types : [started]
13-
1410 # trigger via webhook
1511 # https://github.com/adamrushuk/devops-lab/blob/master/TriggerCustomAction.ps1#L28
1612 repository_dispatch :
2117 workflow_dispatch :
2218 inputs : {}
2319
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+
2426# global environment variables
2527# https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables
2628env :
2729 # prefix: used for some globally unique name requirements
2830 PREFIX : arshz
2931
3032 # debug
31- CI_DEBUG : false
33+ CI_DEBUG : true
3234
33- # azure creds
35+ # azure creds (used with OIDC auth)
3436 ARM_CLIENT_ID : ${{ secrets.ARM_CLIENT_ID }}
35- ARM_CLIENT_SECRET : ${{ secrets.ARM_CLIENT_SECRET }}
3637 ARM_SUBSCRIPTION_ID : ${{ secrets.ARM_SUBSCRIPTION_ID }}
3738 ARM_TENANT_ID : ${{ secrets.ARM_TENANT_ID }}
3839
4647 FORCE_TEST_FAIL : false
4748 K8S_TLS_SECRET_NAME : tls-secret
4849 KEY_VAULT_CERT_NAME : wildcard-thehypepipe-co-uk
49- KEY_VAULT_NAME : kv-rush-iz6y
50+ KEY_VAULT_NAME : kv-rush-aqy2
5051 KEY_VAULT_RESOURCE_GROUP_NAME : rg-keyvault-acmebot
5152 # NOTE: "eastus" is cheaper than "uksouth"
5253 LOCATION : eastus
5960 # terraform
6061 TF_IN_AUTOMATION : " true"
6162 TF_INPUT : " false"
63+ # https://developer.hashicorp.com/terraform/internals/debugging
64+ TF_LOG : " ERROR" # TRACE, DEBUG, INFO, WARN or ERROR
6265 TF_PLAN : " tfplan"
6366 # https://github.com/hashicorp/terraform/releases
64- TF_VERSION : " 1.0.10 "
67+ TF_VERSION : " 1.3.7 "
6568 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 "
7073
7174 # Env var concatenation is currently not supported at Workflow or Job scope. See workaround below:
7275 # 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:
7578 build-and-deploy :
7679 # always pin versions
7780 # 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
7982
8083 # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idenvironment
8184 environment :
82- name : dev_environment
85+ name : dev
8386 url : " https://argocd.${{ env.ROOT_DOMAIN_NAME }}"
8487
8588 # only run if owner triggered action
8891 steps :
8992 # Checkout
9093 # https://github.com/marketplace/actions/checkout
91- - uses : actions/checkout@v2
94+ - uses : actions/checkout@v3
9295 # specify different branch
9396 # NOT required as I've changed the default branch to develop
9497 # with:
@@ -105,13 +108,19 @@ jobs:
105108 echo "DNS_DOMAIN_NAME=nexus.${{ env.ROOT_DOMAIN_NAME }}" >> $GITHUB_ENV
106109 echo "DOCKER_FQDN=docker.${{ env.ROOT_DOMAIN_NAME }}" >> $GITHUB_ENV
107110 echo "TERRAFORM_STORAGE_ACCOUNT=${{ env.PREFIX }}sttfstate${{ env.LOCATION }}001" >> $GITHUB_ENV
111+ echo "TERRAFORM_STORAGE_CONTAINER=terraform" >> $GITHUB_ENV
108112 echo "TERRAFORM_STORAGE_RG=${{ env.PREFIX }}-rg-tfstate-dev-001" >> $GITHUB_ENV
109113 echo "VELERO_STORAGE_ACCOUNT=${{ env.PREFIX }}stbckuksouth001" >> $GITHUB_ENV
110- echo "VELERO_STORAGE_RG=${{ env.PREFIX }}-rg-velero-dev-001" >> $GITHUB_ENV
111114
112115 # 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
115124
116125 # This is required when developing after the initial build, and the AKS cluster may have been stopped
117126 # Ensure AKS cluster is running, else timeouts will occur on k8s Terraform apply tasks
@@ -123,8 +132,9 @@ jobs:
123132 - name : Create Storage Account for Terraform state
124133 run : ./scripts/storage_create.sh
125134
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
128138
129139 - name : Replace tokens in Terraform config files
130140 run : pwsh -command "./scripts/Replace-Tokens.ps1"
@@ -133,26 +143,47 @@ jobs:
133143 HELM_CHART_REPO_DEPLOY_PRIVATE_KEY : ${{ secrets.HELM_CHART_REPO_DEPLOY_PRIVATE_KEY }}
134144 IFTTT_WEBHOOK_KEY : ${{ secrets.IFTTT_WEBHOOK_KEY }}
135145
136- - name : Create zip file of Function App
137- run : pwsh -command "./function_app/CreateFunctionAppZip.ps1"
138-
139146 # Terraform
140- - uses : hashicorp/setup-terraform@v1
147+ # https://github.com/hashicorp/setup-terraform
148+ - uses : hashicorp/setup-terraform@v2
141149 with :
142150 terraform_version : ${{ env.TF_VERSION }}
143151
144152 - name : Terraform Init / Validate
145153 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...'
147161 terraform validate
148162 working-directory : ${{ env.TF_WORKING_DIR }}
149163
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/[email protected] 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
156187
157188 - name : 👀 Terraform Plan
158189 id : plan
@@ -182,6 +213,7 @@ jobs:
182213 NEXUS_USER_PASSWORD : ${{ secrets.NEXUS_USER_PASSWORD }}
183214
184215 # Docker
216+ # https://github.com/Azure/docker-login
185217 - name : Docker repo login
186218 uses : Azure/docker-login@v1
187219 with :
@@ -197,17 +229,18 @@ jobs:
197229 run : pwsh -command "./scripts/Fix-FunctionApp.ps1"
198230 env :
199231 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 "
201233
202234 # Pester tests
203235 - name : 🧪 Run Pester tests
204236 continue-on-error : true
205237 run : pwsh -command "./scripts/Start-Test.ps1"
206238
239+ # https://github.com/actions/upload-artifact
207240 - name : Archive test artifacts
208- uses : actions/upload-artifact@v1
241+ uses : actions/upload-artifact@v3
209242 with :
210- name : test results
243+ name : test- results
211244 path : test/pester-test-results.xml
212245 if : always()
213246
@@ -216,35 +249,47 @@ jobs:
216249 run : pwsh -command "Unregister-PSRepository -Name nuget.org-proxy -Verbose"
217250
218251 # 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+ 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
226267
227268 # Notify
228269 - name : Notify slack
229270 continue-on-error : true
230271 env :
231272 SLACK_CHANNEL_ID : ${{ secrets.SLACK_CHANNEL_ID }}
232273 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"
234275
235276 # used for any windows-only tasks
236277 test-windows :
237278 needs : build-and-deploy
238279
239280 # 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
241286
242287 # only run if owner triggered action
243288 if : github.actor == github.event.repository.owner.login
244289
245290 steps :
246291 # Checkout
247- - uses : actions/checkout@v2
292+ - uses : actions/checkout@v3
248293
249294 # Init tasks - inc Env var concatenation
250295 # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files
@@ -256,8 +301,14 @@ jobs:
256301 echo "DNS_DOMAIN_NAME=nexus.${{ env.ROOT_DOMAIN_NAME }}" | Out-File -Append -Encoding utf8 -FilePath "$env:GITHUB_ENV"
257302
258303 # 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
261312
262313 # Chocolatey
263314 - name : Test Nexus Chocolatey proxy repo
0 commit comments