-
Notifications
You must be signed in to change notification settings - Fork 53
241 lines (208 loc) · 7.68 KB
/
marketplace_image.yml
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#
# Copyright (c) Microsoft Corporation
# Licensed under the MIT License.
#
name : marketplace_image
# Allow only a single instance of this workflow to run at a time
concurrency: ${{ github.workflow }}
on:
pull_request:
types: [ closed ]
branches:
- main
paths:
- 'packer/**'
workflow_dispatch:
inputs:
publish:
description: 'Publish images on the marketplace'
required: false
default: 'false' # use it with ${{ github.event.inputs.publish }}
env:
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
AZHOP_STATE_CONTAINER: environments
AZHOP_STATE_ACCOUNT: azhopstates
RESOURCE_GROUP: azhop_build_images
defaults:
run:
shell: bash
jobs:
set_image_list:
name: set_image_list
runs-on: ubuntu-latest
permissions:
contents: read
container:
image: azhop.azurecr.io/hpcrover:latest
credentials:
username: ${{ env.ARM_CLIENT_ID }}
password: ${{ env.ARM_CLIENT_SECRET }}
options: --user 0
steps:
- uses: actions/checkout@v4
- name: Login azure
run: |
source /miniconda/bin/activate
az login --service-principal -u '${{ env.ARM_CLIENT_ID }}' -p '${{ env.ARM_CLIENT_SECRET }}' --tenant '${{ env.ARM_TENANT_ID }}'
az account set -s ${{ env.ARM_SUBSCRIPTION_ID }}
- name: list all images to be built
id: set-image-matrix
run: |
source /miniconda/bin/activate
RESOURCE_GROUP=${{ env.RESOURCE_GROUP }}
rg_exists=$(az group exists -n $RESOURCE_GROUP)
if [ "$rg_exists" = "true" ]; then
./azhop_state.sh download ${{ env.AZHOP_STATE_ACCOUNT }} ${{ env.AZHOP_STATE_CONTAINER }} $RESOURCE_GROUP
else
echo "Resource group $RESOURCE_GROUP does not exist"
exit 1
fi
# Build the list of images from the config file
images=$(yq eval ".images[].name" config.yml | jq -cRn '[inputs]')
echo "matrix=$images" >> $GITHUB_OUTPUT
# save the list into the outputs
outputs:
matrix: ${{ steps.set-image-matrix.outputs.matrix }}
build_image:
name: build_image
runs-on: self-hosted
permissions:
contents: read
continue-on-error: true
needs: [set_image_list]
strategy:
fail-fast: false
matrix:
images: ${{ fromJson(needs.set_image_list.outputs.matrix) }}
container:
image: azhop.azurecr.io/hpcrover:latest
credentials:
username: ${{ env.ARM_CLIENT_ID }}
password: ${{ env.ARM_CLIENT_SECRET }}
options: --user 0
steps:
- uses: actions/checkout@v4
- name: Login azure
run: |
source /miniconda/bin/activate
az login --service-principal -u '${{ env.ARM_CLIENT_ID }}' -p '${{ env.ARM_CLIENT_SECRET }}' --tenant '${{ env.ARM_TENANT_ID }}'
az account set -s ${{ env.ARM_SUBSCRIPTION_ID }}
- name: Build Images
run: |
source /miniconda/bin/activate
RESOURCE_GROUP=${{ env.RESOURCE_GROUP }}
./azhop_state.sh download ${{ env.AZHOP_STATE_ACCOUNT }} ${{ env.AZHOP_STATE_CONTAINER }} $RESOURCE_GROUP
cd packer
./build_image.sh -i ${{matrix.images}}.json -k
copy_disk:
name: copy_disk
runs-on: ubuntu-latest
permissions:
contents: read
continue-on-error: true
if: inputs.publish == 'true'
needs: [set_image_list, build_image]
strategy:
fail-fast: false
matrix:
images: ${{ fromJson(needs.set_image_list.outputs.matrix) }}
container:
image: azhop.azurecr.io/hpcrover:latest
credentials:
username: ${{ env.ARM_CLIENT_ID }}
password: ${{ env.ARM_CLIENT_SECRET }}
options: --user 0
steps:
- uses: actions/checkout@v4
- name: Login azure
run: |
source /miniconda/bin/activate
az login --service-principal -u '${{ env.ARM_CLIENT_ID }}' -p '${{ env.ARM_CLIENT_SECRET }}' --tenant '${{ env.ARM_TENANT_ID }}'
az account set -s ${{ env.ARM_SUBSCRIPTION_ID }}
- name: Copy Disk
run: |
source /miniconda/bin/activate
set -e
RESOURCE_GROUP=${{ env.RESOURCE_GROUP }}
ANSIBLE_VARIABLES=./playbooks/group_vars/all.yml
CONFIG_FILE=config.yml
image_name=${{matrix.images}}
./azhop_state.sh download ${{ env.AZHOP_STATE_ACCOUNT }} ${{ env.AZHOP_STATE_CONTAINER }} $RESOURCE_GROUP
key_vault_name=$(yq eval ".key_vault" $ANSIBLE_VARIABLES)
echo "key_vault_name=$key_vault_name"
eval_str=".images[] | select(.name == "\"$image_name"\") | .offer"
offer=$(yq eval "$eval_str" $CONFIG_FILE)
eval_str=".images[] | select(.name == "\"$image_name"\") | .publisher"
publisher=$(yq eval "$eval_str" $CONFIG_FILE)
eval_str=".images[] | select(.name == "\"$image_name"\") | .sku"
sku=$(yq eval "$eval_str" $CONFIG_FILE)
echo "offer=$offer"
echo "publisher=$publisher"
echo "sku=$sku"
cd ./marketplace
./copyosdisk.sh ${offer}-${sku} $RESOURCE_GROUP
put_offer:
name: put_offer
runs-on: ubuntu-latest
permissions:
contents: read
continue-on-error: true
if: inputs.publish == 'true'
needs: [set_image_list, copy_disk]
strategy:
max-parallel: 1
fail-fast: false
matrix:
images: ${{ fromJson(needs.set_image_list.outputs.matrix) }}
container:
image: azhop.azurecr.io/hpcrover:latest
credentials:
username: ${{ env.ARM_CLIENT_ID }}
password: ${{ env.ARM_CLIENT_SECRET }}
options: --user 0
steps:
- uses: actions/checkout@v4
- name: Login azure
run: |
source /miniconda/bin/activate
az login --service-principal -u '${{ env.ARM_CLIENT_ID }}' -p '${{ env.ARM_CLIENT_SECRET }}' --tenant '${{ env.ARM_TENANT_ID }}'
az account set -s ${{ env.ARM_SUBSCRIPTION_ID }}
- name: Push Offer Update
run: |
source /miniconda/bin/activate
set -e
RESOURCE_GROUP=${{ env.RESOURCE_GROUP }}
ANSIBLE_VARIABLES=./playbooks/group_vars/all.yml
CONFIG_FILE=config.yml
image_name=${{matrix.images}}
./azhop_state.sh download ${{ env.AZHOP_STATE_ACCOUNT }} ${{ env.AZHOP_STATE_CONTAINER }} $RESOURCE_GROUP
key_vault_name=$(yq eval ".key_vault" $ANSIBLE_VARIABLES)
echo "key_vault_name=$key_vault_name"
eval_str=".images[] | select(.name == "\"$image_name"\") | .offer"
offer=$(yq eval "$eval_str" $CONFIG_FILE)
eval_str=".images[] | select(.name == "\"$image_name"\") | .publisher"
publisher=$(yq eval "$eval_str" $CONFIG_FILE)
eval_str=".images[] | select(.name == "\"$image_name"\") | .sku"
sku=$(yq eval "$eval_str" $CONFIG_FILE)
echo "offer=$offer"
echo "publisher=$publisher"
echo "sku=$sku"
cd ./marketplace
. auth.sh $key_vault_name
echo "authenticate_legacy"
authenticate_legacy
echo "get_offer_by_id"
get_offer_by_id $publisher $offer > $image_name.json
ls -alt
cat $image_name.json
echo "build_offer_file"
rm -f $image_name-final.json
./build_offer_file.sh $offer $sku
if [ -e $image_name-final.json ]; then
echo "New version added, push the new offer"
put_offer $publisher $offer $image_name-final.json
get_offer_by_id $publisher $offer
fi