generated from pagopa/pagopa-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 0
227 lines (197 loc) · 8.25 KB
/
release_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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
name: Release And Deploy Azure Function
# Controls when the workflow will run
on:
pull_request:
types: [ closed ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
environment:
required: true
type: choice
description: Select the Environment
options:
- dev
- uat
- prod
- all
beta:
required: false
type: boolean
description: deploy beta function version on Azure
default: false
skip_release:
required: false
type: boolean
description: skip the release. Only deploy
default: false
permissions:
packages: write
contents: write
issues: write
id-token: write
actions: read
env:
REGISTRY: 'ghcr.io'
NAMESPACE: 'pagopa'
IMAGE: 'pagopa-gpd-reporting-service'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
semver: ${{ steps.get_semver.outputs.semver }}
environment: ${{ steps.get_env.outputs.environment }}
steps:
- name: pull request rejected
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged != true
run: |
echo "❌ PR was closed without a merge"
exit 1
# Set Semvar
- run: echo "SEMVER=patch" >> $GITHUB_ENV
- if: ${{ (github.event.pull_request.merged && contains(github.event.pull_request.labels.*.name, 'breaking-change ')) }}
run: echo "SEMVER=major" >> $GITHUB_ENV
- if: ${{ inputs.environment == 'uat' }}
run: echo "SEMVER=minor" >> $GITHUB_ENV
- if: ${{ inputs.environment == 'prod' }}
run: echo "SEMVER=skip" >> $GITHUB_ENV
- if: ${{ github.ref_name != 'main' }}
run: echo "SEMVER=buildNumber" >> $GITHUB_ENV
- if: ${{ inputs.skip_release }}
run: echo "SEMVER=skip" >> $GITHUB_ENV
- id: get_semver
name: Set Output
run: echo "semver=${{env.SEMVER}}" >> $GITHUB_OUTPUT
# Set Environment
- run: echo "ENVIRNOMENT=${{ inputs.environment}}" >> $GITHUB_ENV
- if: ${{ inputs.environment == null }}
run: echo "ENVIRNOMENT=dev" >> $GITHUB_ENV
- id: get_env
name: Set Output
run: echo "environment=${{env.ENVIRNOMENT}}" >> $GITHUB_OUTPUT
release:
name: Create a New Release
runs-on: ubuntu-latest
needs: [ setup ]
outputs:
version: ${{ steps.release.outputs.version }}
steps:
- name: Make Release
id: release
uses: pagopa/github-actions-template/maven-release@d91a1fd0b913c9830589be5d86cdb71c90813fae # v1.5.4
with:
semver: ${{ needs.setup.outputs.semver }}
github_token: ${{ secrets.BOT_TOKEN_GITHUB }}
beta: ${{ inputs.beta }}
skip_ci: false
build-and-push:
needs: [ setup, release ]
name: Build and Push Docker Image
runs-on: ubuntu-latest
if: ${{ inputs.semver != 'skip' }}
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
with:
ref: ${{ needs.release.outputs.version }}
- name: Login to GitHub Container Registry
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0
with:
images: ghcr.io/${{ github.repository }}
tags: |
latest
${{ needs.release.outputs.version }}
type=ref,event=branch
type=sha
- name: Build and push
uses: docker/build-push-action@1104d471370f9806843c095c1db02b5a90c5f8b6 # v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: ${{ inputs.build_args }}
deploy_azure_fn:
name: Deploy Azure function
environment: ${{ inputs.environment }}
needs: [ setup, release, build-and-push ]
runs-on: ubuntu-latest
if: ${{ always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
- name: 'Login via Azure CLI'
uses: azure/login@cb79c773a3cfa27f31f25eb3f677781210c9ce3d # v1
with:
client-id: ${{ secrets.CLIENT_ID }}
tenant-id: ${{ secrets.TENANT_ID }}
subscription-id: ${{ secrets.SUBSCRIPTION_ID }}
- name: 'Azure CLI script: start staging slot'
uses: azure/CLI@4db43908b9df2e7ac93c8275a8f9a448c59338dd # v1
if: ${{ contains(github.event.inputs.environment, 'prod') }}
env:
ENV_SHORT: ${{ (contains(github.event.inputs.environment,'prod') && 'p') }}
with:
inlineScript: |
az functionapp start --name pagopa-${{ env.ENV_SHORT }}-weu-fn-gpd-service --resource-group pagopa-${{ env.ENV_SHORT }}-weu-gps-gpd-rg --slot staging
- name: 'Run Azure Functions Container Action DEV|UAT: deploy on production slot'
uses: Azure/functions-container-action@0aec6197033a72d3ca813f1aebd9391f639c2a8f # v1.2.1
if: ${{ contains(github.event.inputs.environment, 'dev') || contains(github.event.inputs.environment, 'uat') }}
env:
ENV_SHORT: ${{ (contains(github.event.inputs.environment,'dev') && 'd') || (contains(github.event.inputs.environment, 'uat') && 'u') }}
TAG: ${{needs.release.outputs.version}}
with:
app-name: "pagopa-${{ env.ENV_SHORT }}-weu-fn-gpd-service"
image: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE }}:${{ env.TAG }}
slot-name: production
- name: 'Run Azure Functions Container Action PROD: deploy on staging slot'
uses: Azure/functions-container-action@0aec6197033a72d3ca813f1aebd9391f639c2a8f # v1.2.1
if: ${{ contains(github.event.inputs.environment, 'prod') }}
env:
ENV_SHORT: ${{ (contains(github.event.inputs.environment,'prod') && 'p') }}
TAG: ${{needs.release.outputs.version}}
with:
app-name: "pagopa-${{ env.ENV_SHORT }}-weu-fn-gpd-service"
image: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE }}:${{ env.TAG }}
slot-name: staging
- name: 'PROD Deploy Approval'
uses: trstringer/manual-approval@662b3ddbc7685f897992051e87e1b4b58c07dc03 # v1
if: ${{ contains(github.event.inputs.environment, 'prod') }}
with:
secret: ${{ secrets.BOT_TOKEN_GITHUB }}
approvers: pagopa-team-core
minimum-approvals: 1
issue-title: "Deploying ${{ env.TAG }} to prod from staging"
issue-body: "Please approve or deny the deployment of version ${{ env.TAG }}."
exclude-workflow-initiator-as-approver: false
timeout-minutes: 360
- name: 'Run Azure Functions Container Action PROD: deploy on production slot'
uses: Azure/functions-container-action@0aec6197033a72d3ca813f1aebd9391f639c2a8f # v1.2.1
if: ${{ contains(github.event.inputs.environment, 'prod') }}
env:
ENV_SHORT: ${{ (contains(github.event.inputs.environment,'prod') && 'p') }}
TAG: ${{needs.release.outputs.version}}
with:
app-name: "pagopa-${{ env.ENV_SHORT }}-weu-fn-gpd-service"
image: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE }}:${{ env.TAG }}
slot-name: production
- name: 'Azure CLI script: stop staging slot'
uses: azure/CLI@4db43908b9df2e7ac93c8275a8f9a448c59338dd # v1
if: ${{ contains(github.event.inputs.environment, 'prod') }}
env:
ENV_SHORT: ${{ (contains(github.event.inputs.environment,'prod') && 'p') }}
with:
inlineScript: |
az functionapp stop --name pagopa-${{ env.ENV_SHORT }}-weu-fn-gpd-service --resource-group pagopa-${{ env.ENV_SHORT }}-weu-gps-gpd-rg --slot staging
- name: Azure logout
run: |
az logout