Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#IOCOM-1221] Changed deploy pipeline and healthcheck path #80

Merged
merged 42 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4609839
added github action to release and deploy
michaeldisaro Apr 2, 2024
49b83f6
made github actions
michaeldisaro Apr 3, 2024
290f5c3
removed wrong release action
michaeldisaro Apr 3, 2024
d1fe991
fixed paths
michaeldisaro Apr 3, 2024
8aed0ac
fixed folders structure and paths
michaeldisaro Apr 3, 2024
90a888d
fix
michaeldisaro Apr 3, 2024
1e94bf1
fixed workflow
michaeldisaro Apr 3, 2024
3790d36
added push trigger
michaeldisaro Apr 3, 2024
b44e7e6
fixed actions
michaeldisaro Apr 3, 2024
d2ea072
fix try to npm pack
michaeldisaro Apr 3, 2024
9909bf6
installed npm-pack-zip
michaeldisaro Apr 3, 2024
f7654ee
zipped whole dir
michaeldisaro Apr 3, 2024
9dc511c
fixed output
michaeldisaro Apr 3, 2024
c1cdfc6
fixed name
michaeldisaro Apr 3, 2024
555cf3c
added infra for github envs
michaeldisaro Apr 8, 2024
33d662b
fixes cr
michaeldisaro Apr 8, 2024
50b2317
added env
michaeldisaro Apr 8, 2024
465d692
fix
michaeldisaro Apr 8, 2024
f276198
fix
michaeldisaro Apr 9, 2024
e2a8334
post review changes
michaeldisaro Apr 10, 2024
6e7874c
fix
michaeldisaro Apr 10, 2024
7fc13eb
fix version
michaeldisaro Apr 10, 2024
d9e5313
fixed infra and workflows code
michaeldisaro Apr 15, 2024
61a125f
fixed with plans
michaeldisaro Apr 15, 2024
c5fbf21
update ouputs
Krusty93 Apr 15, 2024
b22f05b
fixed and applied
michaeldisaro Apr 15, 2024
45426e3
agents
Krusty93 Apr 15, 2024
a272dae
rename things
Krusty93 Apr 15, 2024
f6c72d6
update paths
Krusty93 Apr 15, 2024
7ef19dc
fix path
Krusty93 Apr 15, 2024
2455cb3
fixed download name
michaeldisaro Apr 15, 2024
e0164c7
changed artifact path
michaeldisaro Apr 15, 2024
01f2bb9
try fix upload
michaeldisaro Apr 15, 2024
6fd9367
try to fix download name
michaeldisaro Apr 15, 2024
246ed41
fixed healthcheck path
michaeldisaro Apr 15, 2024
00d18e5
fixed curl option
michaeldisaro Apr 15, 2024
51cc5fb
add private runner
Krusty93 Apr 15, 2024
9da8ac4
switch back to self hosted agent
Krusty93 Apr 15, 2024
ac5e010
fix typos
Krusty93 Apr 16, 2024
a80e3a0
updated versions
michaeldisaro Apr 16, 2024
f62fe90
Merge branch 'iocom-1221' of https://github.com/pagopa/io-functions-s…
michaeldisaro Apr 16, 2024
5d6f370
removed push trigger
michaeldisaro Apr 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/actions/node-yarn/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Build workspace"
description: "This action builds the project."

runs:
using: "composite"
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".node-version"
cache: "yarn"
cache-dependency-path: "./yarn.lock"

- name: Install dependencies
run: yarn install --frozen-lockfile
shell: bash

- name: Build io-functions-service-messages
run: yarn build
shell: bash
15 changes: 15 additions & 0 deletions .github/workflows/deploy-func.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: functions-service-messages Release
on:
workflow_dispatch:

jobs:

deploy_workspace_to_azure:
name: Deploy
uses: ./.github/workflows/deploy.yaml
with:
environment: prod
app_service_name: io-p-messages-sending-func
app_service_resource_group: io-p-service-messages-rg
healtcheck_path: /api/v1/info
secrets: inherit
80 changes: 80 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
on:
workflow_call:
inputs:
environment:
type: string
required: true
app_service_name:
type: string
required: true
app_service_resource_group:
type: string
required: true
healtcheck_path:
type: string
required: true

jobs:
build:
name: Build
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- name: Build app
uses: ./.github/actions/node-yarn

- name: Make the azure app artifact
id: make_artifact
run: |
zip -r app.zip .
echo "artifact-path=$(realpath app.zip)" >> "$GITHUB_OUTPUT"
shell: bash

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: app.zip
path: ${{ steps.make_artifact.outputs.artifact-path }}

deploy:
name: Deploy App
if: ${{ !github.event.act }}
needs: [build]
runs-on: self-hosted
michaeldisaro marked this conversation as resolved.
Show resolved Hide resolved
environment: ${{ inputs.environment }}-cd
permissions:
id-token: write
contents: read
env:
ARM_USE_OIDC: true
ARM_USE_AZUREAD: true
ARM_STORAGE_USE_AZUREAD: true

steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: app.zip

- name: Login to Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.ARM_CLIENT_ID }}
tenant-id: ${{ secrets.ARM_TENANT_ID }}
subscription-id: ${{ secrets.ARM_SUBSCRIPTION_ID }}

- name: Deploy App to Staging Slot
uses: azure/webapps-deploy@v2
with:
resource-group-name: ${{ inputs.app_service_resource_group }}
app-name: ${{ inputs.app_service_name }}
slot-name: staging
package: app.zip

- name: Check Staging Health
run: curl --retry 5 --retry-max-time 120 -f 'https://${{ inputs.app_service_name }}-staging.azurewebsites.net${{ inputs.healtcheck_path }}'

- name: Swap Staging and Production Slots
run: az webapp deployment slot swap -g ${{ inputs.app_service_resource_group }} -n ${{ inputs.app_service_name }} --slot staging --target-slot production
38 changes: 0 additions & 38 deletions .github/workflows/release.yml

This file was deleted.

51 changes: 50 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ dist
# Python Environments
.env
.venv
env/
venv/
env/
ENV/
env.bak/
venv.bak/
Expand Down Expand Up @@ -63,3 +63,52 @@ helm/charts**
helm/charts/*

docker-compose.override.yml

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

**/.tfsec/*
**/.ignore/*

*.DS_Store
*.log
*.h2.db
settings.json
__TMP
.metals/
*.log
*.h2.db
settings.json
__TMP
.metals/
__azurite_*
/.idea

**/modules/**/.terraform.lock.hcl
1 change: 1 addition & 0 deletions .terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.6.6
2 changes: 1 addition & 1 deletion Info/function.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "ready",
"route": "v1/info",
"methods": [
"get"
]
Expand Down
2 changes: 1 addition & 1 deletion Info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const app = express();
secureExpressApp(app);

// Add express route
app.get("/api/ready", Info(cosmosdbClient));
app.get("/api/v1/info", Info(cosmosdbClient));

const azureFunctionHandler = createAzureFunctionHandler(app);

Expand Down
48 changes: 48 additions & 0 deletions infra/github-runner/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions infra/github-runner/container_app_job_runner.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module "container_app_job" {
lucacavallaro marked this conversation as resolved.
Show resolved Hide resolved
source = "github.com/pagopa/terraform-azurerm-v3//container_app_job_gh_runner?ref=v7.76.0"

location = local.location
prefix = local.prefix
env_short = local.env_short

key_vault = {
resource_group_name = data.azurerm_key_vault.key_vault_common.resource_group_name
name = data.azurerm_key_vault.key_vault_common.name
secret_name = "github-runner-pat"
}

environment = {
name = data.azurerm_container_app_environment.container_app_environment_runner.name
resource_group_name = data.azurerm_container_app_environment.container_app_environment_runner.resource_group_name
}

job = {
name = "f-services-messages"
lucacavallaro marked this conversation as resolved.
Show resolved Hide resolved
repo = "io-functions-services-messages"
}

tags = local.tags
}
9 changes: 9 additions & 0 deletions infra/github-runner/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
data "azurerm_key_vault" "key_vault_common" {
name = local.key_vault_common.name
resource_group_name = local.key_vault_common.resource_group_name
}

data "azurerm_container_app_environment" "container_app_environment_runner" {
name = local.container_app_environment.name
resource_group_name = local.container_app_environment.resource_group_name
}
25 changes: 25 additions & 0 deletions infra/github-runner/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
locals {
location = "westeurope"
prefix = "io"
env_short = "p"
project = "${local.prefix}-${local.env_short}"

key_vault_common = {
name = "${local.project}-kv-common"
resource_group_name = "${local.project}-rg-common"
}

container_app_environment = {
name = "${local.project}-github-runner-cae"
resource_group_name = "${local.project}-github-runner-rg"
}

tags = {
CostCenter = "TS310 - PAGAMENTI & SERVIZI"
CreatedBy = "Terraform"
Environment = "Prod"
Owner = "IO"
ManagementTeam = "IO Comunicazione"
Source = "https://github.com/pagopa/io-functions-service-messages/tree/main/infra/github-runner"
}
}
19 changes: 19 additions & 0 deletions infra/github-runner/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "<= 3.98.0"
}
}

backend "azurerm" {
resource_group_name = "terraform-state-rg"
storage_account_name = "tfappprodio"
container_name = "terraform-state"
key = "io-functions-service-messages.github-runner.tfstate"
}
}

provider "azurerm" {
features {}
}
25 changes: 25 additions & 0 deletions infra/identity/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading