-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (69 loc) · 2.88 KB
/
containerapp-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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 }}:${{ github.event.release.tag_name }} -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 }}:${{ github.event.release.tag_name }} \
--set-env-vars DiscordBot__Token=secretref:discordbot-token
- name: logout
run: >
az logout