This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
Build and deploy from branch #41
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and deploy from branch | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
type: choice | |
required: false | |
description: "Environment where to deploy" | |
options: | |
- dev-cd | |
env: | |
TARGET_PLATFORMS: linux/amd64 | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
environment: ${{ inputs.environment }} | |
outputs: | |
docker-tags: ${{ steps.meta.outputs.tags }} | |
image-digest: ${{ steps.image.outputs.digest }} | |
permissions: | |
id-token: write | |
packages: write | |
contents: write | |
steps: | |
- name: Checkout the source code | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1 | |
with: | |
fetch-depth: 0 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 #v3.0.0 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 #v3.0.0 | |
- name: Log in to the Container registry | |
id: docker_login | |
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d #v3.0.0 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.BOT_WRITE_PACKAGE_TOKEN }} | |
- name: Generate Docker Metadata | |
id: meta | |
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 #v5.5.1 | |
with: | |
images: ghcr.io/${{ github.repository }} | |
flavor: | |
latest=false | |
tags: | | |
type=semver,pattern={{version}} | |
type=ref,event=branch | |
type=raw,value=latest,enable={{is_default_branch}} | |
labels: | | |
maintainer=https://pagopa.it | |
org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
- name: Build and push Docker image | |
id: image | |
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 #v5.0.0 | |
with: | |
file: src/main/docker/Dockerfile.native-micro | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: ${{ env.TARGET_PLATFORMS }} | |
deploy: | |
needs: [build_and_push] | |
name: Deploy on ${{ inputs.environment }} | |
runs-on: ubuntu-latest | |
environment: ${{ inputs.environment }} | |
permissions: | |
id-token: write | |
steps: | |
- name: Login to Azure | |
uses: azure/login@8c334a195cbb38e46038007b304988d888bf676a #v2.0.0 | |
with: | |
client-id: ${{ secrets.AZURE_CD_IDENTITY_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_CD_IDENTITY_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Get image tag to deploy | |
id: tagToDeploy | |
run: echo "tag=$(echo ${{ needs.build_and_push.outputs.docker-tags }} | awk '{print $1}')" >> $GITHUB_OUTPUT | |
- name: Deploy Container App | |
uses: azure/container-apps-deploy-action@02d045129c058b13312276b50a552834cf74e2af #v2.0.0 | |
with: | |
containerAppName: ${{ secrets.AZURE_CONTAINER_APP_NAME }} | |
resourceGroup: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} | |
imageToDeploy: ${{ steps.tagToDeploy.outputs.tag }}@${{ needs.build_and_push.outputs.image-digest }} |