Skip to content

Frontend - Build and Deploy on Azure #3

Frontend - Build and Deploy on Azure

Frontend - Build and Deploy on Azure #3

name: Frontend - Build and Deploy on Azure
on:
push:
branches: [ development ]
paths:
- 'frontend/**'
- '.github/workflows/azure-deploy-frontend-dev.yml'
workflow_dispatch:
env:
REGISTRY: ghcr.io
FRONTEND_IMAGE_NAME: ${{ github.repository }}-frontend-dev
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
short_sha: ${{ steps.extract-sha.outputs.short_sha }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract short SHA
id: extract-sha
run: |
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT
echo "Using short SHA: $SHORT_SHA"
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}
tags: |
type=sha,format=short
type=ref,event=branch
latest
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy:
needs: build-and-push
runs-on: ubuntu-latest
environment: production
steps:
- name: Azure login
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy to Azure Container Apps
id: deploy
uses: azure/container-apps-deploy-action@v2
with:
registryUrl: ${{ env.REGISTRY }}
registryUsername: ${{ github.actor }}
registryPassword: ${{ secrets.GHCR_PASS }}
containerAppName: mploy-frontend-dev
resourceGroup: ${{ secrets.AZURE_RESOURCE_GROUP }}
imageToDeploy: ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}:sha-${{ needs.build-and-push.outputs.short_sha }}
targetPort: 3000