Docker Build, Push, and Deploy #173
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: Docker Build, Push, and Deploy | |
on: | |
workflow_dispatch: | |
inputs: | |
workspace: | |
description: Choose environment | |
type: choice | |
required: true | |
options: | |
- dev-preview | |
- dev | |
- prod | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
docker: | |
name: 'Docker Build and Push' | |
runs-on: ubuntu-latest | |
environment: ${{ github.event.inputs.workspace }} | |
env: | |
ARM_SUBSCRIPTION_ID: ${{ vars.ARM_SUBSCRIPTION_ID }} | |
ARM_CLIENT_ID: ${{ vars.ARM_CLIENT_ID }} | |
ARM_TENANT_ID: ${{ vars.ARM_TENANT_ID }} | |
ARM_USE_OIDC: "true" | |
APP_NAME: ${{vars.APP_NAME || 'imo-msw'}} | |
defaults: | |
run: | |
shell: bash | |
working-directory: ./terraform | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: 'Az CLI login using OIDC' | |
uses: azure/login@v2 | |
with: | |
client-id: ${{ vars.ARM_CLIENT_ID }} | |
tenant-id: ${{ vars.ARM_TENANT_ID }} | |
subscription-id: ${{ vars.ARM_SUBSCRIPTION_ID }} | |
- name: Prep workspace name | |
run: | | |
WORKSPACE="${{ github.event.inputs.workspace }}" | |
MODIFIED_WORKSPACE="${WORKSPACE//-/}" | |
APP_NAME="${{ env.APP_NAME}}" | |
MODIFIED_APP_NAME="${APP_NAME//-/}" | |
echo "WORKSPACE=$WORKSPACE" >> $GITHUB_ENV | |
echo "MODIFIED_APP_NAME=$MODIFIED_APP_NAME" >> $GITHUB_ENV | |
echo "MODIFIED_WORKSPACE=$MODIFIED_WORKSPACE" >> $GITHUB_ENV | |
- name: Log in to ACR | |
run: az acr login --name cr${{env.MODIFIED_APP_NAME}}${{ env.MODIFIED_WORKSPACE }} | |
- name: Build and push Client Docker image | |
run: | | |
pwd && docker buildx build --push --tag cr${{env.MODIFIED_APP_NAME}}${{ env.MODIFIED_WORKSPACE }}.azurecr.io/client:${{ github.sha }} ../IMOMaritimeSingleWindow/Client | |
- name: Build and push Server Docker image | |
run: | | |
pwd && docker buildx build --push --tag cr${{env.MODIFIED_APP_NAME}}${{ env.MODIFIED_WORKSPACE }}.azurecr.io/server:${{ github.sha }} ../IMOMaritimeSingleWindow/Server | |
- name: Deploy Backend Container App | |
uses: azure/container-apps-deploy-action@v1 | |
with: | |
acrName: cr${{env.MODIFIED_APP_NAME}}${{ env.MODIFIED_WORKSPACE }} | |
containerAppName: ca-${{env.APP_NAME}}-backend-${{ env.WORKSPACE }} | |
resourceGroup: rg-${{env.APP_NAME}}-${{ env.WORKSPACE }} | |
imageToDeploy: cr${{env.MODIFIED_APP_NAME}}${{ env.MODIFIED_WORKSPACE }}.azurecr.io/server:${{ github.sha }} | |
- name: Deploy Frontend Container App | |
uses: azure/container-apps-deploy-action@v1 | |
with: | |
acrName: cr${{env.MODIFIED_APP_NAME}}${{ env.MODIFIED_WORKSPACE }} | |
containerAppName: ca-${{env.APP_NAME}}-frontend-${{ env.WORKSPACE }} | |
resourceGroup: rg-${{env.APP_NAME}}-${{ env.WORKSPACE }} | |
imageToDeploy: cr${{env.MODIFIED_APP_NAME}}${{ env.MODIFIED_WORKSPACE }}.azurecr.io/client:${{ github.sha }} |