Skip to content

Updated example

Updated example #5

Workflow file for this run

# week07/.github/workflows/frontend_ci.yml
name: Frontend CI - Build & Push Image
on:
# Manual trigger
workflow_dispatch:
# Automatically on pushes to main branch
push:
branches:
- main
paths: # Only trigger if changes are in the frontend directory
- 'frontend/**'
- '.github/workflows/frontend_ci.yml' # Trigger if this workflow file changes
# Define global environment variables that can be used across jobs
env:
# ACR Login Server (e.g., myregistry.azurecr.io)
# This needs to be set as a GitHub Repository Secret
ACR_LOGIN_SERVER: ${{ secrets.ACR_LOGIN_SERVER }}
# Dynamically generate image tags based on Git SHA and GitHub Run ID
# This provides unique, traceable tags for each image build
IMAGE_TAG: ${{ github.sha }}-${{ github.run_id }}
jobs:
build_and_push_frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Azure login using a Service Principal secret
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# Login to Azure Container Registry (ACR)
- name: Login to Azure Container Registry
run: az acr login --name ${{ env.ACR_LOGIN_SERVER }}
# Build and Push Docker image for Frontend
- name: Build and Push Frontend Image
run: |
docker build -t ${{ env.ACR_LOGIN_SERVER }}/frontend:latest ./frontend/
docker push ${{ env.ACR_LOGIN_SERVER }}/frontend:latest
# Logout from Azure for security (runs even if image push fails)
- name: Logout from Azure
run: az logout
if: always()