-
Notifications
You must be signed in to change notification settings - Fork 53
114 lines (100 loc) · 3.24 KB
/
build_image_callable.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
#
# Copyright (c) Microsoft Corporation
# Licensed under the MIT License.
#
name : build_image_callable
on:
workflow_call:
inputs:
resource_group:
description: 'Name of the azhop resource group to build in - Need to already exists'
required: true
type: string
secrets:
ARM_SUBSCRIPTION_ID:
required: true
ARM_TENANT_ID:
required: true
env:
TF_CLI_ARGS: '-no-color'
TF_CLI_ARGS_destroy: '-auto-approve -refresh=false'
TF_CLI_ARGS_apply: '-auto-approve'
AZHOP_CONFIGURATION: '.github/workflows/configs/integration.yml'
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
AZHOP_STATE_CONTAINER: environments
AZHOP_STATE_ACCOUNT: azhopstates
ANSIBLE_VERBOSITY: 2 # From 0 to 4 based on the level of logs needed in Ansible
defaults:
run:
shell: bash
jobs:
set_image_list:
name: set_image_list
runs-on: self-hosted
permissions:
contents: read
container:
image: azhop.azurecr.io/hpcrover:latest
credentials:
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
options: --user 0
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Login azure
run: |
source /miniconda/bin/activate
az login -i
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=${{ inputs.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
needs: [set_image_list]
strategy:
matrix:
packer_file: ${{ fromJson(needs.set_image_list.outputs.matrix) }}
container:
image: azhop.azurecr.io/hpcrover:latest
credentials:
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
options: --user 0
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Login azure
run: |
source miniconda/bin/activate
az login -i
az account set -s ${{ env.ARM_SUBSCRIPTION_ID }}
- name: Build Images
run: |
source /miniconda/bin/activate
RESOURCE_GROUP=${{ inputs.resource_group }}
./azhop_state.sh download ${{ env.AZHOP_STATE_ACCOUNT }} ${{ env.AZHOP_STATE_CONTAINER }} $RESOURCE_GROUP
cd packer
./build_image.sh -i ${{matrix.packer_file}}.json