pagopa / dx

Devex repository for shared tools and pipelines.
https://pagopa.github.io/dx/docs/
1 stars 0 forks source link

[DEVEX-165] Added GitHub Action template for CDN Deploy #78

Closed mamu0 closed 1 week ago

mamu0 commented 3 weeks ago

List of changes

Added .github/actions/code_build/action.yaml reusable action. Added .github/actions/cdn_code_deploy/action.yaml reusable action. Added .github/actions/github_modified_files/action.yaml reusable action.

Motivation and context

The Actions for the github action that will deploy the CDN has been added. There is the possibility of listing the paths of the files to purge if it is not necessary to do it on *, just insert the value 'true' ​​in content_paths, and the github_modified_files action will start and return a list of all files changed in that commit.

A Workflow example can be:

name: NodeJS CDN - Template

on:
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-cd
  cancel-in-progress: false

jobs:
  build:
    name: Build
    runs-on: ubuntu-22.04

    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
        name: Checkout

      - uses: ./.github/actions/code_build
        name: Build Artifact
        with:
          base_workdir: '.'
          zip_artifact: 'false'

  deploy:
    name: Deploy
    if: ${{ !github.event.act }}
    environment: dev-cd
    needs: [build]
    runs-on: ubuntu-22.04
    permissions:
      id-token: write
      contents: read
      actions: read
    env:
      ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
      ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
      ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}

    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
        name: Checkout

      - uses: ./.github/actions/cdn_code_deploy
        name: Deploy Artifact
        with:
          arm_client_id: ${{ env.ARM_CLIENT_ID }}
          arm_tenant_id: ${{ env.ARM_TENANT_ID }}
          arm_subscription_id: ${{ env.ARM_SUBSCRIPTION_ID }}
          resource_group_name: 'io-test-rg-01'
          storage_account_name: 'io-test-sa-01'
          profile_cdn_name: 'io-test-dev-cdn-01'
          endpoint_name: 'io-test-dev-cdn-01'
          blob_container_name: 'io-test-dev-cdn-01'
          content_paths: 'true'

Type of changes

Does this introduce a change to production resources with possible user impact?

Other information

This template need to be tested in a real environment, a possible point of failure can be the Update Artifact of the out folder and the initial Prune.

gunzip commented 3 weeks ago

It looks like this isn't a general purpose action to deploy to a CDN, but makes some opinionated guess about the structure of repository (typescript, yarn ,...). If this is the case, we should update module name and PR description to something like "NextJS deploy to CDN"