Repository navigation
182 lines (174 loc) · 6.22 KB
/
Copy pathbuilder.yml
File metadata and controls
182 lines (174 loc) · 6.22 KB
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
name: Chaotic Builder
on:
workflow_dispatch:
inputs:
builders:
description: "Number of parallel builders, empty for auto-scale to queue (1-20)"
required: false
default: "4"
type: string
runtime:
description: "Builder runtime per shard, e.g. 340m (<350m, leaves time for retrigger)"
required: false
default: "340m"
type: string
manager_url:
description: "Manager base URL e.g. https://builds.garudalinux.org — enables queue-aware retrigger"
required: false
default: "https://builds.garudalinux.org"
type: string
builder_class:
description: "BUILDER_CLASS filter"
required: false
default: "6"
type: string
workflow_call:
inputs:
builders:
required: false
default: 4
type: number
runtime:
required: false
default: "340m"
type: string
manager_url:
required: false
default: "https://builds.garudalinux.org"
type: string
builder_class:
required: false
default: "6"
type: string
secrets:
REDIS_PASSWORD:
required: true
DEPLOY_KEY:
required: true
REDIS_SSH_HOST:
required: true
REDIS_SSH_PORT:
required: false
REDIS_SSH_USER:
required: false
REDIS_PORT:
required: false
REDIS_HOST:
required: false
DATABASE_HOST:
required: false
DATABASE_PORT:
required: false
DATABASE_USER:
required: false
MANAGER_API_TOKEN:
required: false
permissions:
contents: read
actions: write
concurrency:
group: chaotic-builder
cancel-in-progress: false
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
shards: ${{ steps.check.outputs.shards || steps.mk.outputs.shards }}
env:
MANAGER_URL: ${{ inputs.manager_url || 'https://builds.garudalinux.org' }}
steps:
- id: check
run: |
url="${MANAGER_URL%/}/api/queue/stats"
if resp=$(curl -sf --max-time 10 "$url" 2>/dev/null); then
waiting=$(echo "$resp" | jq -r '.waiting.count // 0' 2>/dev/null || echo 0)
active=$(echo "$resp" | jq -r '.active.count // 0' 2>/dev/null || echo 0)
total=$((waiting + active))
if [ "$total" -eq 0 ]; then
echo "Queue empty at start — no builders needed"
echo 'shards=[]' >> "$GITHUB_OUTPUT"
exit 0
fi
# default builders = routable waiting for this BUILDER_CLASS (capped 20), unless workflow_dispatch overrides
raw="${{ inputs.builders }}"
my_class="${{ inputs.builder_class }}"
if { [ -z "$raw" ] || [ "$raw" = "4" ] || [ "$raw" = "0" ] || [ "$raw" = "6" ]; } && [ "$waiting" -gt 0 ]; then
if echo "$my_class" | grep -qE '^[0-9]+$'; then
routable=$(echo "$resp" | jq --argjson my "$my_class" '[.waiting.packages[] | select(.build_class|type=="number" and . <= $my)] | length' 2>/dev/null || echo 0)
else
routable="$waiting"
fi
if [ "$routable" -eq 0 ]; then
echo "No routable jobs for class $my_class — no builders needed"
echo 'shards=[]' >> "$GITHUB_OUTPUT"
exit 0
fi
n="$routable"
if [ "$n" -gt 20 ]; then n=20; fi
if [ "$n" -lt 1 ]; then n=1; fi
shards=$(seq 1 "$n" | jq -R . | jq -s -c 'map(tonumber)')
echo "Queue routable=$routable (waiting=$waiting) for class $my_class → shards=$shards"
echo "shards=$shards" >> "$GITHUB_OUTPUT"
exit 0
fi
fi
- id: mk
if: steps.check.outputs.shards == ''
run: |
raw="${{ inputs.builders }}"
n=$(echo "$raw" | tr -d -c '0-9')
if [ -z "$n" ]; then n=4; fi
if [ "$n" -gt 20 ]; then n=20; fi
if [ "$n" -lt 1 ]; then n=1; fi
shards=$(seq 1 "$n" | jq -R . | jq -s -c 'map(tonumber)')
echo "shards=$shards"
echo "shards=$shards" >> "$GITHUB_OUTPUT"
builder:
if: needs.matrix.outputs.shards != '[]' && needs.matrix.outputs.shards != ''
needs: matrix
runs-on: ubuntu-latest
timeout-minutes: 350
strategy:
fail-fast: false
matrix:
shard: ${{ fromJSON(needs.matrix.outputs.shards) }}
container:
image: registry.gitlab.com/garuda-linux/tools/chaotic-manager/manager:latest
options: --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /tmp/shared:/shared
env:
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}
REDIS_SSH_HOST: ${{ secrets.REDIS_SSH_HOST || 'aerialis.garudalinux.org' }}
REDIS_SSH_PORT: ${{ secrets.REDIS_SSH_PORT || '270' }}
REDIS_SSH_USER: ${{ secrets.REDIS_SSH_USER || 'package-deployer' }}
REDIS_PORT: ${{ secrets.REDIS_PORT || '6379' }}
REDIS_HOST: ${{ secrets.REDIS_HOST || '127.0.0.1' }}
DATABASE_HOST: ${{ secrets.DATABASE_HOST }}
DATABASE_PORT: ${{ secrets.DATABASE_PORT || '210' }}
DATABASE_USER: ${{ secrets.DATABASE_USER || 'package-deployer' }}
BUILDER_HOSTNAME: gh-${{ matrix.shard }}
BUILDER_CLASS: ${{ inputs.builder_class }}
BUILDER_TIMEOUT: "3600"
BUILDER_EXIT_AFTER_BUILD: "true"
BUILDER_BUILD_DIR_HOST: /tmp/shared/build
SHARED_PATH: /tmp/shared
BUILDER_RUNTIME: ${{ inputs.runtime || '340m' }}
MANAGER_URL: ${{ inputs.manager_url || 'https://builds.garudalinux.org' }}
steps:
- name: Checkout builder scripts
uses: actions/checkout@v7
with:
sparse-checkout: scripts/run-builder.sh
sparse-checkout-cone-mode: false
fetch-depth: 1
- name: Prepare SSH key
run: |
if [ -z "${DEPLOY_KEY:-}" ]; then echo "DEPLOY_KEY secret missing" >&2; exit 1; fi
echo "$DEPLOY_KEY" > /app/sshkey
echo "$DEPLOY_KEY" > "$PWD/sshkey"
chmod 400 /app/sshkey "$PWD/sshkey"
mkdir -p ~/.ssh
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
- name: Run builder
run: bash scripts/run-builder.sh
timeout-minutes: 345