Skip to content

Commit afddec4

Browse files
Copilotaurelianware
andcommitted
Migrate API docs from Azure Static Web Apps to Azure Container Apps (nginx)
Co-authored-by: aurelianware <194855645+aurelianware@users.noreply.github.com>
1 parent 7a1f04c commit afddec4

File tree

4 files changed

+98
-38
lines changed

4 files changed

+98
-38
lines changed

.github/workflows/deploy-api-docs.yml

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,77 @@ on:
66
paths:
77
- 'src/api-docs/**'
88
- 'api/openapi/**'
9+
- 'containers/api-docs/**'
910
- '.github/workflows/deploy-api-docs.yml'
1011
workflow_dispatch:
1112

1213
permissions:
14+
id-token: write
1315
contents: read
1416

17+
env:
18+
IMAGE_NAME: api-docs
19+
ACA_NAME: api-docs
20+
ACA_ENV: cho-aca-env
21+
RESOURCE_GROUP: rg-cloudhealthoffice-prod
22+
1523
jobs:
1624
deploy:
17-
name: Deploy Swagger UI to Azure Static Web Apps
25+
name: Build & Deploy API Docs to Azure Container Apps
1826
runs-on: ubuntu-latest
1927

2028
steps:
2129
- name: Checkout code
2230
uses: actions/checkout@v4
2331

24-
- name: Copy OpenAPI specs into site
32+
- name: Azure login via OIDC
33+
uses: azure/login@v2
34+
with:
35+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
36+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
37+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
38+
39+
- name: Log in to Azure Container Registry
40+
run: az acr login --name ${{ vars.ACR_NAME }}
41+
42+
- name: Build and push Docker image
2543
run: |
26-
cp api/openapi/*.yaml src/api-docs/specs/
44+
IMAGE_TAG="${{ vars.ACR_LOGIN_SERVER }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
45+
IMAGE_LATEST="${{ vars.ACR_LOGIN_SERVER }}/${{ env.IMAGE_NAME }}:latest"
46+
docker build -f containers/api-docs/Dockerfile . -t "${IMAGE_TAG}" -t "${IMAGE_LATEST}"
47+
docker push "${IMAGE_TAG}"
48+
docker push "${IMAGE_LATEST}"
49+
50+
- name: Deploy to Azure Container Apps
51+
run: |
52+
IMAGE_TAG="${{ vars.ACR_LOGIN_SERVER }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
53+
az containerapp create \
54+
--name "${{ env.ACA_NAME }}" \
55+
--resource-group "${{ env.RESOURCE_GROUP }}" \
56+
--environment "${{ env.ACA_ENV }}" \
57+
--image "${IMAGE_TAG}" \
58+
--ingress external \
59+
--target-port 80 \
60+
--min-replicas 1 \
61+
--max-replicas 3 \
62+
--cpu 0.25 \
63+
--memory 0.5Gi \
64+
--registry-server "${{ vars.ACR_LOGIN_SERVER }}" 2>/dev/null || \
65+
az containerapp update \
66+
--name "${{ env.ACA_NAME }}" \
67+
--resource-group "${{ env.RESOURCE_GROUP }}" \
68+
--image "${IMAGE_TAG}"
69+
70+
- name: Verify health endpoint
71+
run: |
72+
echo "Waiting for container app to start..."
73+
sleep 30
74+
FQDN=$(az containerapp show \
75+
--name "${{ env.ACA_NAME }}" \
76+
--resource-group "${{ env.RESOURCE_GROUP }}" \
77+
--query "properties.configuration.ingress.fqdn" -o tsv)
78+
echo "Container App FQDN: ${FQDN}"
79+
curl -sf "https://${FQDN}/" -o /dev/null && \
80+
echo "✅ API Docs is healthy" || \
81+
echo "⚠️ Health check failed — container may still be warming up"
2782
28-
- name: Deploy to Azure Static Web Apps
29-
uses: Azure/static-web-apps-deploy@v1
30-
with:
31-
azure_static_web_apps_api_token: ${{ secrets.API_DOCS_SWA_TOKEN }}
32-
repo_token: ${{ secrets.GITHUB_TOKEN }}
33-
action: "upload"
34-
app_location: "src/api-docs"
35-
output_location: ""
36-
skip_app_build: true

containers/api-docs/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM nginx:1.27-alpine
2+
3+
# Add YAML MIME type (not included in nginx defaults)
4+
RUN sed -i 's|text/plain\s*txt;|text/plain txt;\n text/yaml yaml yml;|' /etc/nginx/mime.types
5+
6+
# Custom nginx configuration
7+
COPY containers/api-docs/nginx.conf /etc/nginx/conf.d/default.conf
8+
9+
# Swagger UI HTML
10+
COPY src/api-docs/index.html /usr/share/nginx/html/index.html
11+
12+
# OpenAPI YAML specs
13+
COPY api/openapi/ /usr/share/nginx/html/specs/
14+
15+
EXPOSE 80

containers/api-docs/nginx.conf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
root /usr/share/nginx/html;
5+
index index.html;
6+
7+
# Security headers
8+
add_header X-Frame-Options "DENY" always;
9+
add_header X-Content-Type-Options "nosniff" always;
10+
add_header Access-Control-Allow-Origin "https://portal.cloudhealthoffice.com" always;
11+
12+
# Redirect /fhir/r4 paths to the Swagger UI patient-access spec
13+
location = /fhir/r4 {
14+
return 302 /?spec=patient-access;
15+
}
16+
17+
location /fhir/r4/ {
18+
return 302 /?spec=patient-access;
19+
}
20+
21+
# Serve static files; fall back to index.html for client-side routing
22+
location / {
23+
try_files $uri $uri/ /index.html;
24+
}
25+
}

src/api-docs/staticwebapp.config.json

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)