generated from pagopa/pagopa-functions-template
-
Notifications
You must be signed in to change notification settings - Fork 1
182 lines (156 loc) · 6.02 KB
/
call_release_cdc.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
on:
workflow_call:
inputs:
environment:
type: string
required: true
tf_environment:
type: string
required: false
env:
DIR: "./infra/container_apps/onboarding-cdc"
ARM_SUBSCRIPTION_ID: ${{ vars.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ vars.ARM_TENANT_ID }}
ARM_USE_OIDC: true
ARM_USE_AZUREAD: true
ARM_STORAGE_USE_AZUREAD: true
jobs:
build:
name: 'Build Docker image'
runs-on: ubuntu-20.04
environment: ${{ inputs.environment }}-cd
permissions:
packages: write
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
name: Checkout
- name: Setup Docker buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
- name: Login to GitHub Container Registry
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Meta
id: meta
uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c # v5.5.0
with:
images: ghcr.io/${{ github.repository }}-cdc
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=sha
labels:
org.opencontainers.image.title=${{ github.repository }}-cdc
org.opencontainers.image.description=SelfCare onboarding-cdc microservice
org.opencontainers.image.authors=PagoPA
org.opencontainers.image.url=github.com/pagopa/${{ github.repository }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
- name: Build and Push Image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
with:
context: .
file: ./apps/onboarding-cdc/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=min
build-args: |
REPO_ID=selfcare-github
REPO_USERNAME=${{ github.actor }}
REPO_PASSWORD=${{ secrets.GITHUB_TOKEN }}
tf_plan:
name: 'Terraform Plan'
runs-on: ubuntu-20.04
environment: ${{ inputs.environment }}-ci
permissions:
id-token: write
contents: read
outputs:
terraform_version: ${{ steps.set-terraform-version.outputs.terraform_version}}
image_tag: ${{ steps.setsha.outputs.short_sha }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
name: Checkout
- name: Set Short Git Commit SHA
id: setsha
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "short_sha=sha-$calculatedSha" >> $GITHUB_OUTPUT
- name: Set Terraform Version
id: set-terraform-version
run: |
echo "terraform_version=$(cat .terraform-version)" >> $GITHUB_OUTPUT
- uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36 # v3.0.0
name: Setup Terraform
with:
terraform_version: ${{ steps.set-terraform-version.outputs.terraform_version}}
- name: Terraform Plan
uses: pagopa/terraform-preapply-azure-action@54ded8cda3437c3f6a9f46baf69cb321ce82f5cd
with:
client_id: ${{ secrets.ARM_CLIENT_ID }}
tenant_id: ${{ vars.ARM_TENANT_ID }}
subscription_id: ${{ vars.ARM_SUBSCRIPTION_ID }}
dir: ${{ env.DIR }}
azure_environment: ${{ inputs.tf_environment }}
env:
TF_VAR_image_tag: ${{ steps.setsha.outputs.short_sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Upload Terraform Plan as Artifact"
uses: actions/upload-artifact@694cdabd8bdb0f10b2cea11669e1bf5453eed0a6 # v4.2.0
with:
name: tfplan
path: ${{ env.DIR }}/tfplan-${{ inputs.tf_environment }}-${{ github.sha }}
if-no-files-found: error
retention-days: 14
release:
name: 'Release'
runs-on: ubuntu-20.04
needs: [build, tf_plan]
environment: ${{ inputs.environment }}-cd
permissions:
id-token: write
contents: read
env:
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
name: Checkout
- name: Azure Login
uses: azure/login@cb79c773a3cfa27f31f25eb3f677781210c9ce3d # v1.6.1
with:
client-id: ${{ secrets.ARM_CLIENT_ID }}
tenant-id: ${{ vars.ARM_TENANT_ID }}
subscription-id: ${{ vars.ARM_SUBSCRIPTION_ID }}
- name: Download Terraform Plan as Artifact
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 # v4.1.1
with:
name: tfplan
path: ${{ env.DIR }}
- name: Retrieve Terraform Modules from Cache
id: cache-terraform-modules
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
with:
path: ${{ env.DIR }}/.terraform
key: terraform-${{ env.DIR }}-${{ github.sha }}
restore-keys: |
terraform-${{ env.DIR }}
- uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36 # v3.0.0
name: Setup Terraform
with:
terraform_version: ${{ needs.tf_plan.outputs.terraform_version }}
- name: Terraform Init
shell: bash
working-directory: ${{ env.DIR }}
run: |
bash ./terraform.sh init ${{ inputs.tf_environment }}
- name: Terraform Apply
shell: bash
working-directory: ${{ env.DIR }}
run: |
terraform apply -lock-timeout=3000s -auto-approve -input=false tfplan-${{ inputs.tf_environment }}-${{ github.sha }}
env:
TF_VAR_image_tag: ${{ needs.tf_plan.outputs.image_tag }}