MuzakBot / Create container images #72
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
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow | |
name: MuzakBot / Create container image | |
on: | |
push: | |
tags: | |
- "v*.*.*" | |
workflow_dispatch: | |
permissions: | |
packages: write | |
contents: read | |
jobs: | |
create-container-image: | |
name: Create container image | |
runs-on: ubuntu-latest | |
outputs: | |
image: ${{ steps.output_image.outputs.image }} | |
steps: | |
- name: "Checkout GitHub Action" | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup .NET SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
global-json-file: global.json | |
- name: Install .NET tools | |
run: dotnet tool restore | |
- name: Update project files with gitversion | |
run: dotnet tool run dotnet-gitversion /updateprojectfiles | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log into container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Generate Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/${{ github.actor }}/MuzakBot | |
tags: | | |
type=ref,event=tag | |
type=ref,event=branch | |
type=sha | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
- name: Build and push Docker image | |
id: image_build | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./ | |
file: ./Dockerfile.MuzakBot | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
"GITHUB_USER=${{ github.actor }}" | |
"GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" | |
- name: Set output image | |
id: output_image | |
shell: pwsh | |
run: | | |
$repoOwner = "${{ github.repository_owner }}".ToLower() | |
$imageDigest = "${{ steps.image_build.outputs.digest }}" | |
"image=ghcr.io/$($repoOwner)/muzakbot@$($imageDigest)" >> $env:GITHUB_OUTPUT | |
deploy-to-azure: | |
name: Deploy to Azure | |
runs-on: ubuntu-latest | |
needs: create-container-image | |
environment: Production | |
permissions: | |
id-token: write | |
steps: | |
- name: Log into Azure | |
uses: azure/login@v2 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Deploy to Azure Container Apps | |
uses: azure/container-apps-deploy-action@v2 | |
with: | |
containerAppName: ${{ secrets.AZURE_CONTAINER_APP_NAME }} | |
resourceGroup: ${{ secrets.AZURE_CONTAINER_RESOURCE_GROUP_NAME }} | |
imageToDeploy: ${{ needs.create-container-image.outputs.image }} |