feat: migrate from Azure Static Web Apps to Azure Container Apps #4
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: 'Azure Container Apps CD' | |
on: | |
push: | |
branches: ['main'] | |
pull_request: | |
branches: ['main'] | |
workflow_dispatch: | |
permissions: | |
id-token: write | |
contents: read | |
env: | |
CONTAINER_APP_NAME: microblog-ai | |
CONTAINER_APP_RESOURCE_GROUP: aswa-remix | |
REGISTRY_NAME: microblogairegistry | |
NODE_VERSION: '20' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
steps: | |
- uses: actions/[email protected] | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
cache: 'npm' | |
- name: Azure Login | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
buildkitd-flags: --debug | |
- name: Login to Azure Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ secrets.REGISTRY_LOGIN_SERVER }} | |
username: ${{ secrets.REGISTRY_USERNAME }} | |
password: ${{ secrets.REGISTRY_PASSWORD }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ secrets.REGISTRY_LOGIN_SERVER }}/microblog-ai:${{ github.sha }} | |
${{ secrets.REGISTRY_LOGIN_SERVER }}/microblog-ai:latest | |
build-args: | | |
NODE_ENV=production | |
NEXT_TELEMETRY_DISABLED=1 | |
AZURE_OPENAI_API_KEY=${{ secrets.AZURE_OPENAI_API_KEY }} | |
AZURE_OPENAI_ENDPOINT=${{ secrets.AZURE_OPENAI_ENDPOINT }} | |
AZURE_OPENAI_DEPLOYMENT_NAME=${{ secrets.AZURE_OPENAI_DEPLOYMENT_NAME }} | |
AZURE_OPENAI_API_VERSION=${{ secrets.AZURE_OPENAI_API_VERSION }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
labels: | | |
org.opencontainers.image.source=https://github.com/${{ github.repository }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Azure Login | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
- name: Deploy to Azure Container Apps | |
uses: azure/container-apps-deploy-action@v1 | |
with: | |
containerAppName: ${{ env.CONTAINER_APP_NAME }} | |
resourceGroup: ${{ env.CONTAINER_APP_RESOURCE_GROUP }} | |
imageToDeploy: ${{ secrets.REGISTRY_LOGIN_SERVER }}/microblog-ai:${{ github.sha }} | |
targetPort: 3000 | |
ingress: external | |
environmentName: env-microblog-ai |