Update deploy.yml #51
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/**/*' | |
- '.github/workflows/deploy.yml' | |
env: | |
CONTAINER_REGISTRY: "ghcr.io" | |
permissions: | |
id-token: write | |
contents: read | |
packages: write | |
jobs: | |
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}} | |
# Build a custom base image with needed Linux dependencies preinstalled | |
- name: Build Custom Image and push to GitHub packages | |
working-directory: '.dockerbuilds/baseimage' | |
id: build-and-publish | |
run: | | |
# 1. concatenate a full name using the run number as the tag | |
fullimagename="ghcr.io/lancemccarthy/aspirebase:${{github.run_number}}" | |
# 2. Build and push container | |
docker build -t $fullimagename -f Dockerfile . | |
docker push $fullimagename | |
# 3. output the image name for use in other job | |
echo "baseimage=$fullimagename" >> "$GITHUB_OUTPUT" | |
deploy_app: | |
needs: [update_base_image] | |
runs-on: ubuntu-latest | |
env: | |
ASPIRE_ENVIRONMENT: "aspire2b" | |
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}} | |
AZURE_CREDS_PROVIDER: "github" | |
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 credentials | |
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: | | |
echo "Confirming BASE_IMAGE... " | |
echo ${{env.BASE_IMAGE}} | |
dotnet publish "${{env.PROJECT_PATH}}" /t:PublishContainer -p ContainerBaseImage="${{env.BASE_IMAGE}}" -p ContainerRepository="${{env.API_SERVICE_REPOSITORY}}" -p ContainerImageTag="${{env.RUN_NUM}}" -p ContainerRegistry="${{env.CONTAINER_REGISTRY}}" | |
env: | |
PROJECT_PATH: 'DevCraftAspire.ApiService/DevCraftAspire.ApiService.csproj' | |
BASE_IMAGE: ${{needs.update_base_image.outputs.baseimage}} | |
API_SERVICE_REPOSITORY: "lancemccarthy/aspireapiservice" | |
RUN_NUM: ${{github.run_number}} | |
- name: Install azd | |
uses: Azure/[email protected] | |
- name: Log into Azure with GitHub Federated Credentials (OpenID) | |
shell: pwsh | |
run: azd auth login --client-id "${{env.AZURE_CLIENT_ID}}" --tenant-id "${{env.AZURE_TENANT_ID}}" --federated-credential-provider "${{env.AZURE_CREDS_PROVIDER}}" | |
- name: Provision Infrastructure | |
shell: pwsh | |
run: azd provision --no-prompt --environment "${{env.ASPIRE_ENVIRONMENT}}" | |
- name: Deploy Application | |
shell: pwsh | |
run: azd deploy --no-prompt --environment "${{env.ASPIRE_ENVIRONMENT}}" |