9191 with :
9292 creds : ${{ secrets.AZURE_CREDENTIALS }}
9393
94+ - name : Whitelist Runner IP
95+ uses : azure/CLI@v1
96+ with :
97+ inlineScript : |
98+ # 1. Get Runner IP
99+ RUNNER_IP=$(curl -s https://api.ipify.org)
100+ echo "Runner IP is $RUNNER_IP"
101+
102+ # 2. Get existing ranges
103+ EXISTING_RANGES=$(az aks show \
104+ --resource-group learningstepsRG \
105+ --name learningsteps-aks \
106+ --query "apiServerAccessProfile.authorizedIpRanges" \
107+ -o tsv | tr '\t' ',')
108+
109+ # 3. Add Runner IP to list
110+ if [ -z "$EXISTING_RANGES" ]; then
111+ NEW_RANGES="$RUNNER_IP/32"
112+ else
113+ NEW_RANGES="$EXISTING_RANGES,$RUNNER_IP/32"
114+ fi
115+
116+ # 4. Update AKS
117+ az aks update \
118+ --resource-group learningstepsRG \
119+ --name learningsteps-aks \
120+ --api-server-authorized-ip-ranges $NEW_RANGES
121+
122+ echo "Waiting 60s for Azure firewall propagation..."
123+ sleep 60
124+
94125 - name : Set AKS Context
95126 uses : azure/aks-set-context@v4
96127 with :
99130
100131 - name : Update AKS Deployment
101132 run : |
102- # 1. Apply all
133+ # 1. Apply all (manifests)
103134 kubectl apply -f kubernetes/
104135
105136 # 2. Update the image to the latest version built in the pipeline
@@ -113,4 +144,20 @@ jobs:
113144 run : |
114145 kubectl get pods -o wide
115146 kubectl describe deployment learningsteps-api
116- kubectl describe pods -l app=learningsteps-api
147+ kubectl describe pods -l app=learningsteps-api
148+
149+ - name : Cleanup Runner IP
150+ if : always()
151+ uses : azure/CLI@v1
152+ with :
153+ inlineScript : |
154+ RUNNER_IP=$(curl -s https://api.ipify.org)
155+ CURRENT_RANGES=$(az aks show -g learningstepsRG -n learningsteps-aks --query "apiServerAccessProfile.authorizedIpRanges" -o tsv | tr '\t' ',')
156+
157+ # Remove only the runner's IP from the string
158+ CLEANED_RANGES=$(echo $CURRENT_RANGES | sed "s|$RUNNER_IP/32||g" | sed 's/,,/,/g' | sed 's/^,//;s/,$//')
159+
160+ az aks update \
161+ --resource-group learningstepsRG \
162+ --name learningsteps-aks \
163+ --api-server-authorized-ip-ranges "$CLEANED_RANGES"
0 commit comments