1+ ---
2+ # Dev Workflow – build image and deploy to Azure Function App (Development environment).
3+ #
4+ # Required secrets (Settings → Environments → Development → Environment secrets):
5+ # - REGISTRY_DOMAIN – Azure Container Registry login server (e.g. myregistry.azurecr.io)
6+ # - REGISTRY_USERNAME – ACR username
7+ # - REGISTRY_PASSWORD – ACR password
8+ # - REGISTRY_REPO – Repository name in ACR for this app
9+ # - TDEI_CORE_AZURE_CREDS – Azure service principal JSON (for az login)
10+ #
11+ # Required variables (Settings → Environments → Development → Environment variables):
12+ # - FUNCTION_APP_NAME – Azure Function App name to deploy to
13+ # - RESOURCE_GROUP – Azure resource group containing the Function App
14+ #
15+ # Optional variables (defaults used if not set):
16+ # - RESTART_APP – Set to 'true' or 'false'; default 'true'
17+ # - APP_SETTINGS_JSON – JSON object of extra app settings to apply; default '{}'
18+ #
19+ # ######## Dev Workflow ########
20+ on :
21+ pull_request :
22+ branches : [dev]
23+ types :
24+ - closed
25+ workflow_dispatch :
26+
27+ permissions :
28+ id-token : write
29+ contents : read
30+
31+ jobs :
32+ Build :
33+ environment : Development
34+ runs-on : ubuntu-latest
35+ if : github.event.pull_request.merged == true
36+ steps :
37+ - uses : actions/checkout@v2
38+ - uses : azure/docker-login@v1
39+ with :
40+ login-server : ${{ secrets.REGISTRY_DOMAIN }}
41+ username : ${{ secrets.REGISTRY_USERNAME }}
42+ password : ${{ secrets.REGISTRY_PASSWORD }}
43+ - name : Publish image to Azure Registry
44+ run : |
45+ docker build -t ${{ secrets.REGISTRY_DOMAIN }}/${{ secrets.REGISTRY_REPO }}:${{ github.sha }} -t ${{ secrets.REGISTRY_DOMAIN }}/${{ secrets.REGISTRY_REPO }}:${{ github.ref_name == 'main' && 'prod' || github.ref_name }}${{ github.ref_name != 'main' && '-latest' || 'latest' }} .
46+ docker push ${{ secrets.REGISTRY_DOMAIN }}/${{ secrets.REGISTRY_REPO }} --all-tags
47+ deploy :
48+ environment : Development
49+ runs-on : ubuntu-latest
50+ needs : [Build]
51+ permissions :
52+ contents : read
53+ steps :
54+ - uses : actions/checkout@v4
55+
56+ - name : Login to Azure
57+ uses : azure/login@v2.0.0
58+ with :
59+ creds : ${{ secrets.TDEI_CORE_AZURE_CREDS }}
60+
61+ - name : Resolve deploy config from environment
62+ id : deploy_config
63+ run : |
64+ echo "function_app_name=${{ vars.FUNCTION_APP_NAME }}" >> "$GITHUB_OUTPUT"
65+ echo "resource_group=${{ vars.RESOURCE_GROUP }}" >> "$GITHUB_OUTPUT"
66+ echo "aci_image=${{ secrets.REGISTRY_DOMAIN }}/${{ secrets.REGISTRY_REPO }}:${{ github.sha }}" >> "$GITHUB_OUTPUT"
67+ echo "restart_app=${{ vars.RESTART_APP || 'true' }}" >> "$GITHUB_OUTPUT"
68+
69+ - name : Log target environment
70+ shell : bash
71+ run : |
72+ echo "Deploying to:"
73+ echo " Function App: ${{ steps.deploy_config.outputs.function_app_name }}"
74+ echo " Resource Group: ${{ steps.deploy_config.outputs.resource_group }}"
75+ echo " ACI_IMAGE: ${{ steps.deploy_config.outputs.aci_image }}"
76+
77+ - name : Update app settings (ACI_IMAGE + extras)
78+ shell : bash
79+ run : |
80+ python - <<'PY'
81+ import json
82+ import os
83+ app_settings = os.environ.get("APP_SETTINGS_JSON", "{}")
84+ data = json.loads(app_settings) if app_settings else {}
85+ data["ACI_IMAGE"] = os.environ["ACI_IMAGE"]
86+ with open("/tmp/appsettings.txt", "w", encoding="utf-8") as handle:
87+ for key, value in data.items():
88+ handle.write(f"{key}={value}\n")
89+ PY
90+ echo "Updating only provided settings (no clearing of others)."
91+ az functionapp config appsettings set \
92+ --name "${{ steps.deploy_config.outputs.function_app_name }}" \
93+ --resource-group "${{ steps.deploy_config.outputs.resource_group }}" \
94+ --settings $(cat /tmp/appsettings.txt | tr '\n' ' ')
95+ env :
96+ ACI_IMAGE : ${{ steps.deploy_config.outputs.aci_image }}
97+ APP_SETTINGS_JSON : ${{ vars.APP_SETTINGS_JSON || '{}' }}
98+
99+ - name : Restart function app
100+ if : ${{ steps.deploy_config.outputs.restart_app == 'true' }}
101+ shell : bash
102+ run : |
103+ az functionapp restart \
104+ --name "${{ steps.deploy_config.outputs.function_app_name }}" \
105+ --resource-group "${{ steps.deploy_config.outputs.resource_group }}"
0 commit comments