Skip to content

Build and deploy .NET application to container app discordbotabordelv2-app-20230528 #31

Build and deploy .NET application to container app discordbotabordelv2-app-20230528

Build and deploy .NET application to container app discordbotabordelv2-app-20230528 #31

Workflow file for this run

name: Build and deploy .NET application to container app discordbotabordelv2-app-20230528
on:
release:
types: [published]
workflow_dispatch:
permissions:
id-token: write
contents: read
env:
DOCKER_FILE_PATH: ./Discord.BotABordelV2/Dockerfile
PROJECT_NAME_FOR_DOCKER: discordbotabordelv2
jobs:
build:
runs-on: ubuntu-latest
environment: PROD
steps:
- name: Checkout to the branch
uses: actions/checkout@v3
- name: "Login via Azure CLI"
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID}}
tenant-id: ${{ secrets.AZURE_TENANT_ID}}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID}}
- name: Build and push container image to registry
uses: azure/CLI@v1
with:
inlineScript: >
az acr build -t ${{ vars.CONTAINER_REGISTRY_LOGIN_SERVER }}/${{ env.PROJECT_NAME_FOR_DOCKER }}:2.1.1 -t ${{ vars.CONTAINER_REGISTRY_LOGIN_SERVER }}/${{ env.PROJECT_NAME_FOR_DOCKER }}:latest --registry ${{ vars.CONTAINER_REGISTRY_LOGIN_SERVER }} --file ${{ env.DOCKER_FILE_PATH }} .
deploy:
runs-on: ubuntu-latest
needs: build
environment: PROD
steps:
- name: Azure Login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID}}
tenant-id: ${{ secrets.AZURE_TENANT_ID}}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID}}
- name: Set up container secrets
uses: azure/CLI@v1
with:
inlineScript: >
az keyvault secret set \
--vault-name ${{ vars.KEYVAULT_NAME }} \
--name discordbot-token \
--value ${{ secrets.DISCORD_BOT_TOKEN }}
az containerapp secret set \
--name ${{ vars.CONTAINER_APP_NAME }} \
--resource-group ${{ vars.CONTAINER_APP_RESOURCE_GROUP_NAME }} \
--secrets discordbot-token=keyvaultref:${{ vars.KEYVAULT_URI }}secrets/discordbot-token,identityref:${{ vars.MANAGED_ID }}
- name: Deploy to container app
uses: azure/CLI@v1
with:
inlineScript: >
az containerapp registry set \
--name ${{ vars.CONTAINER_APP_NAME }} \
--resource-group ${{ vars.CONTAINER_APP_RESOURCE_GROUP_NAME }} \
--server ${{ vars.CONTAINER_REGISTRY_LOGIN_SERVER }} \
--identity ${{ vars.MANAGED_ID }}
az containerapp update \
--name ${{ vars.CONTAINER_APP_NAME }} \
--resource-group ${{ vars.CONTAINER_APP_RESOURCE_GROUP_NAME }} \
--image ${{ vars.CONTAINER_REGISTRY_LOGIN_SERVER }}/${{ env.PROJECT_NAME_FOR_DOCKER }}:2.1.1 \
--set-env-vars DiscordBot__Token=secretref:discordbot-token \
- name: logout
run: >
az logout