-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (121 loc) · 4.02 KB
/
apis-deployment.yaml
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
135
136
137
138
139
140
141
142
143
144
145
name: APIs deployment
on:
push:
branches:
- main
- dev
paths:
- 'apis/**'
- '.github/workflows/apis-deployment.yaml'
workflow_dispatch:
env:
RG: contoso-${{ github.ref_name }}-rg
APIM_SERVICE: contoso-${{ github.ref_name }}-apim
SA: contoso${{ github.ref_name }}apimsa
jobs:
upload-api-descriptors:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Create container for API resources
uses: azure/CLI@v1
with:
inlineScript: |
for api in `ls apis`
do
az storage container create --name $api --account-name $SA --public-access blob -g $RG
done
- name: Upload files for each API
uses: azure/CLI@v1
with:
inlineScript: |
for api in `ls apis`
do
for file in `ls apis/$api | egrep "openapi|policies"`
do
az storage blob upload --overwrite --container-name $api --account-name $SA --file apis/$api/$file
done
done
generate-arm-templates:
runs-on: ubuntu-latest
needs: upload-api-descriptors
steps:
- uses: actions/checkout@v2
- name: Generate apiconfig with variables
shell: bash
run: |
for api in `ls apis`
do
cat apis/$api/apiconfig.yaml | \
API_NAME=$api \
APIM_SERVICE=$APIM_SERVICE \
SA=$SA \
envsubst > apis/$api/apiconfig_resolved.yaml
done
- name: Generate templates for API
uses: addnab/docker-run-action@v3
with:
image: sancheski/arm-api-creator:0.0.1
options: -v ${{ github.workspace }}/apis:/app/apis
run: |
for api in `ls /app/apis`
do
dotnet ArmTemplates.dll create --configFile /app/apis/$api/apiconfig_resolved.yaml
done
- uses: actions/upload-artifact@v3
with:
name: apis
path: ${{ github.workspace }}/apis
provision-apis:
runs-on: ubuntu-latest
needs: generate-arm-templates
steps:
- uses: actions/download-artifact@v3
with:
name: apis
path: apis
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Provision API
uses: azure/CLI@v1
with:
inlineScript: |
for api in `ls apis`
do
az deployment group create --resource-group $RG --template-file apis/$api/generatedtemplates/$api.api.template.json --parameters @apis/$api/generatedtemplates/$api-parameters.json
done
delete-apis:
runs-on: ubuntu-latest
needs: provision-apis
steps:
- uses: actions/checkout@v2
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Delete API
uses: azure/CLI@v1
with:
inlineScript: |
ls apis > mustremain.list
echo "Must remain in APIM"
cat mustremain.list
echo ""
az apim api list --service-name $APIM_SERVICE --resource-group $RG \
-o tsv --query "[].{name:name}" > currentinapim.list
echo "Currently in APIM"
cat currentinapim.list
for apiToRemove in `diff mustremain.list currentinapim.list \
| grep -v "+++" | grep -v "\-\-\-" | grep -v "@@" \
| grep + | awk -F+ '{print $2}'`
do
echo "Deleting API $apiToRemove... not present in git anymore"
az apim api delete -n $APIM_SERVICE -g $RG --api-id $apiToRemove -y
az storage container delete --name $apiToRemove --account-name $SA
done