forked from CSCfi/Kielipankki-donatespeech-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (109 loc) · 4.58 KB
/
Copy pathdeploy-dev.yml
File metadata and controls
134 lines (109 loc) · 4.58 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Deploy to Dev Environment
on:
push:
branches:
- main
paths:
- "recorder-backend/**"
- ".github/workflows/deploy-dev.yml"
# Allow manual trigger
workflow_dispatch:
permissions:
id-token: write # Required for OIDC authentication
contents: read
env:
WORKING_DIRECTORY: recorder-backend
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.WORKING_DIRECTORY }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
- name: Install uv
run: pip install uv
- name: Install dependencies
run: uv sync
- name: Run tests
run: uv run pytest tests/ -v
deploy:
name: Deploy to Dev Container App
runs-on: ubuntu-latest
needs: test
defaults:
run:
working-directory: ${{ env.WORKING_DIRECTORY }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get short SHA
id: vars
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Azure Login via OIDC
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Login to Azure Container Registry
run: |
az acr login --name ${{ secrets.DEV_ACR_NAME }}
- name: Build and push Docker image
env:
ACR_NAME: ${{ secrets.DEV_ACR_NAME }}
SHORT_SHA: ${{ steps.vars.outputs.short_sha }}
run: |
IMAGE_NAME="${ACR_NAME}.azurecr.io/recorder-backend"
docker build -t ${IMAGE_NAME}:dev-${SHORT_SHA} \
-t ${IMAGE_NAME}:dev-latest \
.
docker push ${IMAGE_NAME}:dev-${SHORT_SHA}
docker push ${IMAGE_NAME}:dev-latest
echo "Pushed images:"
echo " - ${IMAGE_NAME}:dev-${SHORT_SHA}"
echo " - ${IMAGE_NAME}:dev-latest"
- name: Deploy to Container App
id: deploy
env:
ACR_NAME: ${{ secrets.DEV_ACR_NAME }}
SHORT_SHA: ${{ steps.vars.outputs.short_sha }}
RESOURCE_GROUP: ${{ secrets.DEV_RESOURCE_GROUP }}
CONTAINER_APP: ${{ secrets.DEV_CONTAINER_APP }}
run: |
IMAGE_NAME="${ACR_NAME}.azurecr.io/recorder-backend:dev-${SHORT_SHA}"
az containerapp update \
--name ${CONTAINER_APP} \
--resource-group ${RESOURCE_GROUP} \
--image ${IMAGE_NAME} \
--revision-suffix ${SHORT_SHA}
# Get the app URL
APP_URL=$(az containerapp show \
--name ${CONTAINER_APP} \
--resource-group ${RESOURCE_GROUP} \
--query properties.configuration.ingress.fqdn \
--output tsv)
echo "url=https://${APP_URL}" >> $GITHUB_OUTPUT
echo "Deployed to: https://${APP_URL}"
- name: Deployment Summary
env:
APP_URL: ${{ steps.deploy.outputs.url }}
SHORT_SHA: ${{ steps.vars.outputs.short_sha }}
run: |
echo "## Deployment Successful! :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Environment:** Development" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** \`${SHORT_SHA}\`" >> $GITHUB_STEP_SUMMARY
echo "**Image:** \`${{ secrets.DEV_ACR_NAME }}.azurecr.io/recorder-backend:dev-${SHORT_SHA}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### :link: Links" >> $GITHUB_STEP_SUMMARY
echo "- **App URL:** ${APP_URL}" >> $GITHUB_STEP_SUMMARY
echo "- **API Docs:** ${APP_URL}/docs" >> $GITHUB_STEP_SUMMARY
echo "- **Health Check:** ${APP_URL}/" >> $GITHUB_STEP_SUMMARY