Deploy to Azure #30
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: "Deploy to Azure" | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- release | |
paths: | |
- 'DevCraftAspire.ApiService/**/*' | |
- 'DevCraftAspire.AppHost/**/*' | |
- 'DevCraftAspire.ServiceDefaults/**/*' | |
- 'DevCraftAspire.Web/**/*' | |
env: | |
CONTAINER_REGISTRY: "ghcr.io" | |
BASE_IMAGE: "ghcr.io/lancemccarthy/aspirebase:8.0" | |
APP_IMAGE_NAME: lancemccarthy/aspireapiservice | |
APP_IMAGE_TAG: "8.0" | |
permissions: | |
id-token: write | |
contents: read | |
packages: write | |
jobs: | |
# Build a custom base image with needed Linux dependencies preinstalled | |
update_base_image: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Login to ghcr.io | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{env.CONTAINER_REGISTRY}} | |
username: ${{github.actor}} | |
password: ${{secrets.GITHUB_TOKEN}} | |
- name: Build Custom Image and push to GitHub packages | |
working-directory: '.dockerbuilds/baseimage' | |
run: | | |
docker build -t ${{ env.BASE_IMAGE }} -f Dockerfile . | |
docker push ${{ env.BASE_IMAGE }} | |
# - name: Set up QEMU | |
# uses: docker/setup-qemu-action@v3 | |
# - name: Set up Docker Buildx | |
# uses: docker/setup-buildx-action@v3 | |
# - name: Build Custom Image and push to GitHub packages | |
# uses: docker/build-push-action@v5 | |
# with: | |
# context: '.dockerbuilds/baseimage' | |
# platforms: linux/arm64,linux/amd64 | |
# push: true | |
# tags: | | |
# "${{env.BASE_IMAGE}}" | |
deploy_app: | |
needs: [update_base_image] | |
runs-on: ubuntu-latest | |
env: | |
NUGET_CONF_PATH: './nuget.config' | |
AZURE_CLIENT_ID: ${{vars.AZURE_CLIENT_ID}} | |
AZURE_TENANT_ID: ${{vars.AZURE_TENANT_ID}} | |
AZURE_SUBSCRIPTION_ID: ${{vars.AZURE_SUBSCRIPTION_ID}} | |
AZURE_ENV_NAME: ${{vars.AZURE_ENV_NAME}} | |
AZURE_LOCATION: ${{vars.AZURE_LOCATION}} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install .NET Aspire workload | |
run: dotnet workload install aspire --ignore-failed-sources | |
- name: Login to ghcr.io | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{env.CONTAINER_REGISTRY}} | |
username: ${{github.actor}} | |
password: ${{secrets.GITHUB_TOKEN}} | |
- name: Update NuGet Package Sources | |
run: dotnet nuget update source "TelerikServer" -s "https://nuget.telerik.com/v3/index.json" -u 'api-key' -p ${{secrets.TELERIK_NUGET_KEY}} --store-password-in-clear-text | |
- name: Build container with custom base | |
run: | | |
dotnet publish 'DevCraftAspire.ApiService/DevCraftAspire.ApiService.csproj' /t:PublishContainer \ | |
-p ContainerBaseImage="${{env.BASE_IMAGE}}" \ | |
-p ContainerRepository="${{env.APP_IMAGE_NAME}}" \ | |
-p ContainerImageTag="${{env.APP_IMAGE_TAG}}" \ | |
-p ContainerRegistry="${{env.CONTAINER_REGISTRY}}" | |
- name: Install azd | |
uses: Azure/[email protected] | |
- name: Log into Azure with GitHub Federated Credentials (OpenID) | |
run: azd auth login --client-id "${{env.AZURE_CLIENT_ID}}" --tenant-id "${{env.AZURE_TENANT_ID}}" --federated-credential-provider "github" | |
shell: pwsh | |
- name: Provision Infrastructure | |
run: azd provision --no-prompt --environment "aspire2b" | |
- name: Deploy Application | |
run: azd deploy --no-prompt --environment "aspire2b" |