generated from pagopa/pagopa-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (108 loc) · 4.32 KB
/
04_self_hosted.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 Azure function
on:
workflow_call:
inputs:
environment:
required: true
description: The name of the environment where to deploy
type: string
target:
required: true
description: The environment target of the job
type: string
registry_image:
required: true
description: The name of the image from container registry to be used
type: string
permissions:
id-token: write
contents: read
jobs:
show_input:
runs-on: ubuntu-latest
if: ${{ inputs.target == inputs.environment }}
environment: ${{ inputs.environment }}
steps:
- name: Get input parameters
run: |
echo environment=${{ inputs.environment }}
echo target=${{ inputs.target }}
echo resource_group=${{ vars.FUNCTION_RESOURCE_GROUP }}
echo app_name=${{ vars.FUNCTION_APP_NAME }}
echo registry_image=${{ inputs.registry_image }}
# Starting the Azure Function's staging slot, if deploying in PROD
start_staging_slot:
name: Create staging slots
runs-on: ubuntu-22.04
if: ${{ inputs.target == inputs.environment && inputs.target == 'prod' }}
environment: ${{ inputs.environment }}
steps:
- 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: Create staging slots
uses: pagopa/github-actions-template/azure-function-start-staging-slot@a1b72480e9ac555364be0b7ecdcc8f5ab1c89ad9
with:
branch: ${{ github.ref_name }}
client_id: ${{ secrets.CD_CLIENT_ID }}
tenant_id: ${{ secrets.TENANT_ID }}
subscription_id: ${{ secrets.SUBSCRIPTION_ID }}
resource_group: ${{ vars.FUNCTION_RESOURCE_GROUP }}
app_name: ${{ vars.FUNCTION_APP_NAME }}
registry_image: ${{ inputs.registry_image }}
# Executing the deploy of the Azure function with the new image
deploy:
name: Deploy Azure Function
runs-on: ubuntu-22.04
needs: [ start_staging_slot ]
if: ${{ always() && inputs.target == inputs.environment }}
environment: ${{ inputs.environment }}
steps:
- 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: Deploy Azure Function
uses: pagopa/github-actions-template/azure-functions-deploy@a1b72480e9ac555364be0b7ecdcc8f5ab1c89ad9
with:
branch: ${{ github.ref_name }}
client_id: ${{ secrets.CD_CLIENT_ID }}
tenant_id: ${{ secrets.TENANT_ID }}
subscription_id: ${{ secrets.SUBSCRIPTION_ID }}
app_name: ${{ vars.FUNCTION_APP_NAME }}
registry_image: ${{ inputs.registry_image }}
# Stopping the Azure Function's staging slot, if deploying in PROD
stop_staging_slot:
name: Clean staging slots
needs: [ start_staging_slot, deploy ]
if: ${{ success() || failure() && (inputs.target == inputs.environment && inputs.target == 'prod') }}
runs-on: ubuntu-22.04
environment: ${{ inputs.environment }}
steps:
- 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: Deploy Azure Function
uses: pagopa/github-actions-template/azure-function-stop-staging-slot@a1b72480e9ac555364be0b7ecdcc8f5ab1c89ad9
with:
branch: ${{ github.ref_name }}
client_id: ${{ secrets.CD_CLIENT_ID }}
tenant_id: ${{ secrets.TENANT_ID }}
subscription_id: ${{ secrets.SUBSCRIPTION_ID }}
resource_group: ${{ vars.FUNCTION_RESOURCE_GROUP }}
app_name: ${{ vars.FUNCTION_APP_NAME }}
registry_image: ${{ inputs.registry_image }}