generated from pagopa/template-java-microservice
-
Notifications
You must be signed in to change notification settings - Fork 1
122 lines (114 loc) · 4.61 KB
/
deploy_with_github_runner.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
121
122
name: Deploy on AKS
on:
workflow_call:
inputs:
environment:
required: true
description: The name of the environment where to deploy
type: string
env:
NAMESPACE: afm
APP_NAME: pagopaafmcalculator
permissions:
id-token: write
contents: read
jobs:
create_runner:
name: Create Runner
runs-on: ubuntu-22.04
environment:
name: ${{ inputs.environment }}
outputs:
runner_name: ${{ steps.create_github_runner.outputs.runner_name }}
steps:
- name: Create GitHub Runner
id: create_github_runner
# from https://github.com/pagopa/eng-github-actions-iac-template/tree/main/azure/github-self-hosted-runner-azure-create-action
uses: pagopa/eng-github-actions-iac-template/azure/github-self-hosted-runner-azure-create-action@main
with:
client_id: ${{ secrets.CD_CLIENT_ID }}
tenant_id: ${{ secrets.TENANT_ID }}
subscription_id: ${{ secrets.SUBSCRIPTION_ID }}
container_app_environment_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_NAME }}
resource_group_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_RESOURCE_GROUP_NAME }} # RG of the runner
pat_token: ${{ secrets.BOT_TOKEN_GITHUB }}
self_hosted_runner_image_tag: "latest"
deploy:
needs: [ create_runner ]
runs-on: [ self-hosted, "${{ needs.create_runner.outputs.runner_name }}" ]
name: Deploy on AKS
environment: ${{ inputs.environment }}
steps:
- name: Deploy
uses: pagopa/github-actions-template/aks-deploy@main
with:
branch: ${{ github.ref_name }}
client_id: ${{ secrets.CD_CLIENT_ID }}
subscription_id: ${{ secrets.SUBSCRIPTION_ID }}
tenant_id: ${{ secrets.TENANT_ID }}
env: ${{ inputs.environment }}
namespace: ${{ vars.NAMESPACE }}
cluster_name: ${{ vars.CLUSTER_NAME }}
resource_group: ${{ vars.CLUSTER_RESOURCE_GROUP }}
app_name: ${{ env.APP_NAME }}
helm_upgrade_options: "--debug"
timeout: '10m0s'
cleanup_runner:
name: Cleanup Runner
needs: [ create_runner, deploy ]
if: ${{ success() || failure() }}
runs-on: ubuntu-22.04
environment: ${{ inputs.environment }}
steps:
- name: Cleanup GitHub Runner
id: cleanup_github_runner
# from https://github.com/pagopa/eng-github-actions-iac-template/tree/main/azure/github-self-hosted-runner-azure-cleanup-action
uses: pagopa/eng-github-actions-iac-template/azure/github-self-hosted-runner-azure-cleanup-action@0ee2f58fd46d10ac7f00bce4304b98db3dbdbe9a
with:
client_id: ${{ secrets.CD_CLIENT_ID }}
tenant_id: ${{ secrets.TENANT_ID }}
subscription_id: ${{ secrets.SUBSCRIPTION_ID }}
resource_group_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_RESOURCE_GROUP_NAME }}
runner_name: ${{ needs.create_runner.outputs.runner_name }}
pat_token: ${{ secrets.BOT_TOKEN_GITHUB }}
# update_openapi:
# needs: [ deploy ]
# runs-on: ubuntu-latest
# name: Update OpenAPI
# if: ${{ inputs.target == inputs.environment }}
# environment: ${{ inputs.environment }}
# steps:
# - name: Checkout
# id: checkout
# # from https://github.com/actions/checkout/commits/main
# uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707
# with:
# persist-credentials: false
#
# - name: Setup Terraform
# # from https://github.com/hashicorp/setup-terraform/commits/main
# uses: hashicorp/setup-terraform@8feba2b913ea459066180f9cb177f58a881cf146
# with:
# terraform_version: "1.3.6"
#
# - name: Login
# id: login
# # from https://github.com/Azure/login/commits/master
# uses: azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2
# with:
# client-id: ${{ secrets.CD_CLIENT_ID }}
# tenant-id: ${{ secrets.TENANT_ID }}
# subscription-id: ${{ secrets.SUBSCRIPTION_ID }}
#
#
# - name: Terraform Apply
# shell: bash
# run: |
# cd ./infra
# export ARM_CLIENT_ID="${{ secrets.CD_CLIENT_ID }}"
# export ARM_SUBSCRIPTION_ID=$(az account show --query id --output tsv)
# export ARM_TENANT_ID=$(az account show --query tenantId --output tsv)
# export ARM_USE_OIDC=true
# export ARM_ACCESS_KEY=$(az storage account keys list --resource-group io-infra-rg --account-name pagopainfraterraform${{inputs.environment}} --query '[0].value' -o tsv)
# bash ./terraform.sh init weu-${{ inputs.environment }}
# bash ./terraform.sh apply weu-${{ inputs.environment }} -auto-approve