-
Notifications
You must be signed in to change notification settings - Fork 59
137 lines (123 loc) · 4.53 KB
/
preset-image-build.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
name: Build and Push Preset Models
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
on:
pull_request:
branches:
- main
paths:
- 'presets/models/inference/**'
- 'presets/models/supported_models.yaml'
push:
branches:
- main
paths:
- 'presets/models/inference/**'
- 'presets/models/supported_models.yaml'
workflow_dispatch:
inputs:
image_tag_name:
description: 'Image Tag'
required: true
permissions:
id-token: write
contents: read
env:
VERSION: 0.0.1
jobs:
determine-models:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.determine_models.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
# This script should output a JSON array of model names
- name: Determine Affected Models
id: determine_models
run: |
PR_BRANCH=${{ github.head_ref }} \
python3 .github/workflows/kind-cluster/determine_models.py
- name: Print Determined Models
run: |
echo "Output from determine_models: ${{ steps.determine_models.outputs.matrix }}"
build-models:
needs: determine-models
runs-on: [self-hosted, 'username:runner-2', 'username:runner-3']
strategy:
fail-fast: false
matrix:
model: ${{fromJson(needs.determine-models.outputs.matrix)}}
max-parallel: 3
outputs:
image_tag: ${{ steps.set_tag.outputs.image_tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Check Available Disk Space
run: df -h
- name: Set Image Tag
id: set_tag
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.image_tag_name }}" ]]; then
echo "Using workflow dispatch to set image tag"
echo "image_tag=${{ github.event.inputs.image_tag_name }}" >> $GITHUB_OUTPUT
else
echo "Setting image tag based on version set"
echo "image_tag=${{ env.VERSION }}" >> $GITHUB_OUTPUT
fi
- name: Print Image Tag
run: |
echo "image_tag for this job: ${{ steps.set_tag.outputs.image_tag }}"
- name: 'Get ACR Info'
id: acr_info
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.image_tag_name }}" ]]; then
ACR_NAME="${{ secrets.ACR_AMR_USERNAME }}"
ACR_USERNAME=${{ secrets.ACR_AMR_USERNAME }}
ACR_PASSWORD=${{ secrets.ACR_AMR_PASSWORD }}
else
ACR_NAME="${{ secrets.ACR_AMRT_USERNAME }}"
ACR_USERNAME=${{ secrets.ACR_AMRT_USERNAME }}
ACR_PASSWORD=${{ secrets.ACR_AMRT_PASSWORD }}
fi
echo "ACR_NAME=$ACR_NAME" >> $GITHUB_OUTPUT
echo "ACR_USERNAME=$ACR_USERNAME" >> $GITHUB_OUTPUT
echo "ACR_PASSWORD=$ACR_PASSWORD" >> $GITHUB_OUTPUT
- name: Launch Python Script to Kickoff Build Jobs
id: launch_script
run: |
IMAGE_TAG=${{ steps.set_tag.outputs.image_tag }} \
PR_BRANCH=${{ github.head_ref }} \
ACR_NAME=${{ steps.acr_info.outputs.ACR_NAME }} \
ACR_USERNAME=${{ steps.acr_info.outputs.ACR_USERNAME }} \
ACR_PASSWORD=${{ steps.acr_info.outputs.ACR_PASSWORD }} \
MODEL_NAME=${{ matrix.model.name }} \
MODEL_TYPE=${{matrix.model.type}} \
MODEL_VERSION=${{ matrix.model.version }} \
MODEL_RUNTIME=${{ matrix.model.runtime }} \
MODEL_TAG=${{ matrix.model.tag }} \
python3 .github/workflows/kind-cluster/main.py
# Check the exit status of the Python script
- name: Check Python Script Status
if: ${{ always() }}
run: |
if [ "${{ steps.launch_script.outcome }}" != "success" ]; then
echo "Python script failed to execute successfully."
exit 1 # Fail the job
else
echo "Python script executed successfully."
fi
# Cleanup Resources
- name: Cleanup
if: ${{ always() }}
run: |
kubectl get job --no-headers -o custom-columns=":metadata.name" | grep "^docker-build-job" | xargs -r kubectl delete job
kubectl get pods --no-headers -o custom-columns=":metadata.name" | grep "^docker-build-job" | xargs -r kubectl delete pod