Skip to content

Commit

Permalink
Merge pull request #497 from DFE-Digital/refactor/194327
Browse files Browse the repository at this point in the history
refactor/194327 - Azure Function Pipeline Optimisation
  • Loading branch information
Zac-Digital authored Feb 7, 2024
2 parents dee960a + 68e9c8d commit edf8366
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 99 deletions.
58 changes: 0 additions & 58 deletions .github/workflows/build-and-deploy-azure-function.yml

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/build-azure-function.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build .NET Azure Function App

on:
workflow_call:
inputs:
artifact:
type: string
required: true

concurrency:
group: ${{ github.workflow }}-build-azure-function
cancel-in-progress: true

env:
DOTNET_VERSION: ${{ vars.DOTNET_VERSION }}

jobs:
build-image:
runs-on: ubuntu-22.04
name: Build .NET Azure Function App & Upload Zip Artifact

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Install Dependencies
shell: bash
run: dotnet restore ./src/Dfe.PlanTech.AzureFunctions/Dfe_PlanTech_AzureFunctions.csproj

- name: Build Azure Function App
shell: bash
run: dotnet publish ./src/Dfe.PlanTech.AzureFunctions/Dfe_PlanTech_AzureFunctions.csproj --configuration Release --no-restore --output ./build

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact }}
path: ./build
47 changes: 47 additions & 0 deletions .github/workflows/deploy-azure-function.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
on:
workflow_call:
inputs:
environment:
type: string
required: true
artifact:
type: string
required: true

concurrency:
group: ${{ github.workflow }}-deploy-${{ inputs.environment }}-azure-function
cancel-in-progress: true

jobs:
deploy-image:
runs-on: ubuntu-22.04
name: Deploy .NET Azure Function App
environment: ${{ inputs.environment }}
env:
AZURE_FUNCTIONAPP_NAME: "${{ secrets.AZ_ENVIRONMENT }}plantechcontentfulfunction"

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact }}
path: ./build

- name: Azure CLI Login
uses: ./.github/actions/azure-login
with:
az_tenant_id: ${{ secrets.AZ_TENANT_ID }}
az_subscription_id: ${{ secrets.AZ_SUBSCRIPTION_ID }}
az_client_id: ${{ secrets.AZ_CLIENT_ID }}
az_client_secret: ${{ secrets.AZ_CLIENT_SECRET }}

- name: Deploy Azure Function App
uses: Azure/functions-action@v1
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: ./build
76 changes: 76 additions & 0 deletions .github/workflows/matrix-deploy-azure-function.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Multi-Stage Build & Deploy (Azure Function)

on:
workflow_dispatch:
push:
branches: ["main", "development"]
paths:
- "src/Dfe.PlanTech.AzureFunctions/**"
- ".github/workflows/matrix-deploy-azure-function.yml"
- ".github/workflows/build-azure-function.yml"
- ".github/workflows/deploy-azure-function.yml"

jobs:
set-env:
runs-on: ubuntu-22.04
name: Set Environment (Matrix Deploy Azure Function)
outputs:
branch: ${{ steps.var.outputs.branch }}
artifact: ${{ steps.var.outputs.artifact }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- id: var
run: |
GIT_BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}}
ARTIFACT=Dfe-PlanTech-AzureFunction
echo "branch=$GIT_BRANCH" >> $GITHUB_OUTPUT
echo "artifact=$ARTIFACT" >> $GITHUB_OUTPUT
build-azure-function:
needs: set-env
name: Build Azure Function
uses: ./.github/workflows/build-azure-function.yml
with:
artifact: ${{ needs.set-env.outputs.artifact }}

deploy-azure-function-for-dev-test:
needs: [set-env, build-azure-function]
name: Deploy Azure Function
strategy:
fail-fast: true
max-parallel: 2
matrix:
target: [Dev, Tst]
uses: ./.github/workflows/deploy-azure-function.yml
with:
environment: ${{ matrix.target }}
artifact: ${{ needs.set-env.outputs.artifact }}
secrets: inherit

deploy-azure-function-for-staging:
needs: [set-env, build-azure-function, deploy-azure-function-for-dev-test]
name: Deploy Azure Function (Staging)
if: ${{ needs.set-env.outputs.branch == 'main' }}
uses: ./.github/workflows/deploy-azure-function.yml
with:
environment: Staging
artifact: ${{ needs.set-env.outputs.artifact }}
secrets: inherit

deploy-azure-function-for-production:
needs:
[
set-env,
build-azure-function,
deploy-azure-function-for-dev-test,
deploy-azure-function-for-staging,
]
name: Deploy Azure Function (Production)
if: ${{ needs.set-env.outputs.branch == 'main' }}
uses: ./.github/workflows/deploy-azure-function.yml
with:
environment: Production
artifact: ${{ needs.set-env.outputs.artifact }}
secrets: inherit
41 changes: 0 additions & 41 deletions .github/workflows/matrix-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ jobs:
branch: ${{ needs.set-env.outputs.branch }}
checked-out-sha: ${{ needs.set-env.outputs.checked-out-sha }}

build-and-deploy-azure-function-for-dev-test:
needs: set-env
name: Build & Deploy Azure Function
strategy:
fail-fast: true
max-parallel: 1
matrix:
target: [Dev, Tst]
uses: ./.github/workflows/build-and-deploy-azure-function.yml
with:
environment: ${{ matrix.target }}
secrets: inherit

check-for-terraform-changes:
needs: create-and-publish-image
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -108,20 +95,6 @@ jobs:
checked-out-sha: ${{ needs.set-env.outputs.checked-out-sha }}
secrets: inherit

build-and-deploy-azure-function-for-staging:
needs: [set-env, deploy-to-dev-and-test]
name: Build & Deploy Azure Function
if: ${{ needs.set-env.outputs.branch == 'main' }}
strategy:
fail-fast: true
max-parallel: 1
matrix:
target: [Staging]
uses: ./.github/workflows/build-and-deploy-azure-function.yml
with:
environment: ${{ matrix.target }}
secrets: inherit

plan-terraform-for-staging:
needs: [set-env, deploy-to-dev-and-test, check-for-terraform-changes]
name: Plan Terraform Infrastructure for staging
Expand Down Expand Up @@ -152,20 +125,6 @@ jobs:
checked-out-sha: ${{ needs.set-env.outputs.checked-out-sha }}
secrets: inherit

build-and-deploy-azure-function-for-production:
needs: [set-env, deploy-to-dev-and-test, deploy-to-staging]
name: Build & Deploy Azure Function
if: ${{ needs.set-env.outputs.branch == 'main' }}
strategy:
fail-fast: true
max-parallel: 1
matrix:
target: [Production]
uses: ./.github/workflows/build-and-deploy-azure-function.yml
with:
environment: ${{ matrix.target }}
secrets: inherit

plan-terraform-for-production:
needs:
[
Expand Down

0 comments on commit edf8366

Please sign in to comment.