Skip to content

Commit

Permalink
hotfix: deploy pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
balanza committed May 5, 2023
1 parent 6468aea commit 9b437dc
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 9 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/azure-deploy-manual.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: "Azure Deploy"

on:
workflow_dispatch:
inputs:
app_name:
required: true
type: string
package_url:
required: true
type: string

permissions:
id-token: write
contents: read

env:
ENV_SHORT: p
FUNCTION_SLOT: staging
PREFIX: io
RESOURCE_GROUP: io-p-services-cms-rg

jobs:
create_runner:
name: Create Runner
runs-on: ubuntu-22.04
environment: prod-runner
outputs:
runner_name: ${{ steps.create_github_runner.outputs.runner_name }}
steps:
- name: Create GitHub Runner
id: create_github_runner
# from https://github.com/pagopa/github-self-hosted-runner-azure-create-action/commits/main
uses: pagopa/github-self-hosted-runner-azure-create-action@63534a04613b420ce6474ccbb52ac7884129ff6f
with:
client_id: ${{ secrets.AZURE_CLIENT_ID }}
tenant_id: ${{ secrets.AZURE_TENANT_ID }}
subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
container_app_environment_name: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_NAME }}
resource_group_name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
pat_token: ${{ secrets.BOT_TOKEN }}
self_hosted_runner_image_tag: v1.4.0

runner_job:
name: Runner Job
runs-on: [self-hosted, "${{ needs.create_runner.outputs.runner_name }}"]
environment: prod-cd #### use your specific identity!
needs: create_runner
steps:
- name: Download artifact
run: "curl --output artifact.zip --location ${{ github.event.inputs.package_url }}"

# - name: Identify workload
# id: workload
# shell: bash
# run: |
# # Parse the release artifact name to extract type, domain and name
# set -euo pipefail
#
# echo name=$(echo "${{ github.event.inputs.name }}" | sed -En "s/^([a-z0-9\-]+).+$/\3/p" | tr -d '\n') >> "$GITHUB_OUTPUT"

- name: Login
id: login
# from https://github.com/Azure/login/commits/master
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Deploy
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.PREFIX }}-${{ env.ENV_SHORT }}-services-cms-webapp-fn
package: artifact.zip
resource-group-name: ${{ env.RESOURCE_GROUP }}
slot-name: staging

cleanup_runner:
name: Cleanup Runner
if: always()
runs-on: ubuntu-22.04
environment: prod-runner
needs: [create_runner, runner_job]
steps:
- name: Cleanup GitHub Runner
id: cleanup_github_runner
# from https://github.com/pagopa/github-self-hosted-runner-azure-cleanup-action/commits/main
uses: pagopa/github-self-hosted-runner-azure-cleanup-action@d4c7a8dc3e8ca7be7b71358fdeee17429e28fcc4
with:
client_id: ${{ secrets.AZURE_CLIENT_ID }}
tenant_id: ${{ secrets.AZURE_TENANT_ID }}
subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
resource_group_name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
runner_name: ${{ needs.create_runner.outputs.runner_name }}
pat_token: ${{ secrets.BOT_TOKEN }}
16 changes: 7 additions & 9 deletions .github/workflows/azure-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ jobs:
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Function
shell: bash
run: |
az webapp deploy \
--resource-group ${{ env.RESOURCE_GROUP }} \
--name ${{ env.PREFIX }}-${{ env.ENV_SHORT }}-services-cms-webapp-fn \
--slot ${{ env.FUNCTION_SLOT }} \
--type zip \
--src-path artifact.zip --verbose
- name: Deploy
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.PREFIX }}-${{ env.ENV_SHORT }}-services-cms-webapp-fn
package: artifact.zip
resource-group-name: ${{ env.RESOURCE_GROUP }}
slot-name: staging

cleanup_runner:
name: Cleanup Runner
Expand Down

0 comments on commit 9b437dc

Please sign in to comment.