Skip to content

Commit 35a9c73

Browse files
[#IOPLT-950] Add rg permission for CD pipeline and refactor inputs (#1187)
* [#IOPLT-950] Add permission for Resource Group for CD pipeline * [#IOPLT-950] Refactor CD pipeline with less input values * [#IOPLT-950] Remove `use_staging_slot` hardcoded parameters dispatch mode * [#IOPLT-950] Add github runner * [#IOPLT-950] Refactor infra runner file structure
1 parent f4b5369 commit 35a9c73

28 files changed

+114
-38
lines changed

.github/workflows/deploy-pipelines.yml

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,11 @@ name: Deploy Pipelines - Legacy
66
on:
77
workflow_dispatch:
88
inputs:
9-
environment:
10-
description: Environment where the artifact will be deployed.
11-
type: string
12-
required: true
13-
resource_group_name:
14-
description: Web App resource group name.
15-
type: string
16-
required: true
17-
default: 'io-p-rg-linux'
189
app_names:
1910
description: Web App names.
2011
type: string
2112
required: true
2213
default: "['io-p-app-appbackendli', 'io-p-app-appbackendl1', 'io-p-app-appbackendl2']"
23-
health_check_path:
24-
description: The health probe path exposed by the Function App.
25-
type: string
26-
required: false
27-
default: '/info'
28-
use_staging_slot:
29-
description: True if artifact should be deployed to staging slot
30-
type: boolean
31-
required: false
32-
default: true
3314
use_private_agent:
3415
description: Use a private agent to deploy the built artifact.
3516
type: boolean
@@ -38,6 +19,8 @@ on:
3819

3920
env:
4021
BUNDLE_NAME: bundle
22+
resource_group_name: io-p-rg-linux
23+
health_check_path: /info
4124

4225
concurrency:
4326
group: ${{ github.workflow }}-cd
@@ -142,7 +125,7 @@ jobs:
142125
matrix:
143126
app_name: ${{ fromJSON(inputs.app_names) }}
144127
runs-on: ${{ inputs.use_private_agent == true && 'self-hosted' || 'ubuntu-latest' }}
145-
environment: ${{ inputs.environment }}-cd
128+
environment: prod-cd
146129
permissions:
147130
id-token: write
148131
contents: read
@@ -168,22 +151,10 @@ jobs:
168151
tenant-id: ${{ env.ARM_TENANT_ID }}
169152
subscription-id: ${{ env.ARM_SUBSCRIPTION_ID }}
170153

171-
- name: Deploy
172-
if: ${{ inputs.use_staging_slot == false }}
173-
run: |
174-
az webapp deploy \
175-
--resource-group ${{ inputs.resource_group_name }} \
176-
--name ${{ matrix.app_name }} \
177-
--src-path ${{ github.workspace }}/${{ env.BUNDLE_NAME }}.zip \
178-
--type zip \
179-
--async false \
180-
| grep -v "hidden-link:"
181-
182154
- name: Deploy to Staging Slot
183-
if: ${{ inputs.use_staging_slot == true }}
184155
run: |
185156
az webapp deploy \
186-
--resource-group ${{ inputs.resource_group_name }} \
157+
--resource-group ${{ env.resource_group_name }} \
187158
--name ${{ matrix.app_name }} \
188159
--slot staging \
189160
--src-path ${{ github.workspace }}/${{ env.BUNDLE_NAME }}.zip \
@@ -192,19 +163,17 @@ jobs:
192163
| grep -v "hidden-link:"
193164
194165
- name: Ping Staging Health
195-
if: ${{ inputs.use_staging_slot == true }}
196166
run: |
197167
curl \
198168
--retry 5 \
199169
--retry-max-time 120 \
200170
--retry-all-errors \
201-
-f 'https://${{ matrix.app_name }}-staging.azurewebsites.net${{ inputs.health_check_path }}'
171+
-f 'https://${{ matrix.app_name }}-staging.azurewebsites.net${{ env.health_check_path }}'
202172
203173
- name: Swap Staging and Production Slots
204-
if: ${{ inputs.use_staging_slot == true }}
205174
run: |
206175
az webapp deployment slot swap \
207-
-g ${{ inputs.resource_group_name }} \
176+
-g ${{ env.resource_group_name }} \
208177
-n ${{ matrix.app_name }} \
209178
--slot staging \
210179
--target-slot production

.gitignore

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,20 @@ local.*
5151
.eslintcache
5252

5353
# Exclude swagger codegen (needed to generate PN specs)
54-
swagger-codegen-cli-*.jar
54+
swagger-codegen-cli-*.jar
55+
56+
# Local .terraform directories
57+
**/.terraform/*
58+
59+
# .tfstate files
60+
*.tfstate
61+
*.tfstate.*
62+
63+
# Ignore override files as they are usually used to override resources locally and so
64+
# are not checked in
65+
override.tf
66+
override.tf.json
67+
*_override.tf
68+
*_override.tf.json
69+
70+
**/.tfsec/*

.terraform-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.11.0

infra/github-runner/prod/.terraform.lock.hcl

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/github-runner/prod/data.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
data "azurerm_container_app_environment" "github-runner-cae" {
2+
name = "${local.prefix}-${local.env_short}-${local.location_short}-github-runner-cae-01"
3+
resource_group_name = "${local.prefix}-${local.env_short}-${local.location_short}-github-runner-rg-01"
4+
}

infra/github-runner/prod/locals.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
locals {
2+
prefix = "io"
3+
env_short = "p"
4+
location = "italynorth"
5+
location_short = "itn"
6+
7+
tags = {
8+
CostCenter = "TS000 - Tecnologia e Servizi"
9+
CreatedBy = "Terraform"
10+
Environment = "App IO"
11+
ManagementTeam = "IO Platform"
12+
Source = "https://github.com/pagopa/io-backend/blob/main/infra/github-runner/prod"
13+
}
14+
}

infra/github-runner/prod/main.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
terraform {
2+
required_providers {
3+
azurerm = {
4+
source = "hashicorp/azurerm"
5+
version = "~> 4"
6+
}
7+
}
8+
9+
backend "azurerm" {
10+
resource_group_name = "terraform-state-rg"
11+
storage_account_name = "iopitntfst001"
12+
container_name = "terraform-state"
13+
key = "io-backend.github-runner.tfstate"
14+
}
15+
}
16+
17+
provider "azurerm" {
18+
features {
19+
}
20+
}

infra/github-runner/prod/runner.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module "dx-github-selfhosted-runner-on-container-app-jobs" {
2+
source = "pagopa/dx-github-selfhosted-runner-on-container-app-jobs/azurerm"
3+
version = "~> 1"
4+
repository = { name : "io-backend" }
5+
6+
environment = {
7+
prefix = local.prefix
8+
env_short = local.env_short
9+
location = local.location
10+
instance_number = "01"
11+
}
12+
13+
container_app_environment = {
14+
id = data.azurerm_container_app_environment.github-runner-cae.id
15+
location = local.location
16+
replica_timeout_in_seconds = 3600
17+
}
18+
19+
resource_group_name = "${local.prefix}-${local.env_short}-rg-linux"
20+
21+
key_vault = {
22+
name = "${local.prefix}-${local.env_short}-kv-common"
23+
resource_group_name = "${local.prefix}-${local.env_short}-rg-common"
24+
}
25+
26+
tags = local.tags
27+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

.identity/env/prod/terraform.tfvars renamed to infra/identity/env/prod/terraform.tfvars

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ environment_cd_roles = {
4646
],
4747
"dashboards" = [
4848
"Contributor"
49+
],
50+
"io-p-rg-linux" = [
51+
"Contributor"
4952
]
5053
}
5154
}
File renamed without changes.

0 commit comments

Comments
 (0)