-
Notifications
You must be signed in to change notification settings - Fork 0
300 lines (264 loc) · 9.87 KB
/
Copy pathcrac-train.yml
File metadata and controls
300 lines (264 loc) · 9.87 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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
name: CRaC Train
on:
workflow_call:
inputs:
service-matrix:
description: JSON matrix include list with service, context, dockerfile, optional db fields, port, and sidecars.
required: true
type: string
docker-target:
description: Dockerfile target that produces the CRaC training image.
required: false
type: string
default: train
checkpoint-path:
description: Path inside the training container where CRaC writes checkpoint files.
required: false
type: string
default: /opt/crac/checkpoint
expected-exit-codes:
description: Space-separated container exit codes accepted after training.
required: false
type: string
default: '0 137'
artifact-retention-days:
description: Retention period for checkpoint artifacts.
required: false
type: number
default: 7
postgres-image:
description: Postgres sidecar image.
required: false
type: string
default: postgres:17-alpine
valkey-image:
description: Valkey sidecar image.
required: false
type: string
default: valkey/valkey:7-alpine
rabbitmq-image:
description: RabbitMQ sidecar image.
required: false
type: string
default: rabbitmq:3-management-alpine
extra-docker-run-args:
description: Extra arguments appended to docker run before the image tag.
required: false
type: string
default: ''
secrets:
packages-token:
description: Token passed as docker build secret github_token.
required: false
permissions:
contents: read
packages: read
jobs:
train:
name: Train ${{ matrix.service }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(inputs.service-matrix) }}
steps:
- uses: actions/checkout@v7
- uses: docker/setup-buildx-action@v4
- name: Resolve requested sidecars
id: sidecars
env:
SIDECARS_JSON: ${{ toJSON(matrix.sidecars) }}
run: |
set -euo pipefail
python3 - <<'PY' >> "$GITHUB_OUTPUT"
import json
import os
import sys
allowed = {"postgres", "valkey", "rabbitmq"}
raw = os.environ.get("SIDECARS_JSON", "null")
if raw in {"", "null"}:
requested = ["postgres", "valkey", "rabbitmq"]
else:
value = json.loads(raw)
if isinstance(value, str):
requested = [part for part in value.replace(",", " ").split() if part]
elif isinstance(value, list):
requested = value
else:
print(f"::error::matrix.sidecars must be a string or list, got {type(value).__name__}", file=sys.stderr)
sys.exit(1)
normalized = [str(item).strip().lower() for item in requested if str(item).strip()]
if not normalized:
normalized = ["none"]
unknown = sorted(set(normalized) - allowed - {"none"})
if unknown:
print(f"::error::Unsupported CRaC sidecar(s): {', '.join(unknown)}", file=sys.stderr)
print("::error::Supported values are postgres, valkey, rabbitmq, and none.", file=sys.stderr)
sys.exit(1)
if "none" in normalized and len(set(normalized)) > 1:
print("::error::CRaC sidecar value 'none' cannot be combined with other sidecars.", file=sys.stderr)
sys.exit(1)
enabled = set() if "none" in normalized else set(normalized)
ordered = [name for name in ["postgres", "valkey", "rabbitmq"] if name in enabled]
print(f"postgres={str('postgres' in enabled).lower()}")
print(f"valkey={str('valkey' in enabled).lower()}")
print(f"rabbitmq={str('rabbitmq' in enabled).lower()}")
print(f"list={','.join(ordered) if ordered else 'none'}")
PY
- name: Start Postgres sidecar
if: steps.sidecars.outputs.postgres == 'true'
env:
POSTGRES_IMAGE: ${{ inputs.postgres-image }}
DB_NAME: ${{ matrix.db_name || matrix.service }}
DB_USER: ${{ matrix.db_user || 'postgres' }}
DB_PASSWORD: ${{ matrix.db_password || 'postgres' }}
run: |
set -euo pipefail
docker rm -f crac-postgres >/dev/null 2>&1 || true
docker run -d \
--name crac-postgres \
-e POSTGRES_DB="${DB_NAME}" \
-e POSTGRES_USER="${DB_USER}" \
-e POSTGRES_PASSWORD="${DB_PASSWORD}" \
-p 5432:5432 \
"${POSTGRES_IMAGE}"
for _ in $(seq 1 60); do
if docker exec crac-postgres pg_isready -U "${DB_USER}" -d "${DB_NAME}" >/dev/null 2>&1; then
exit 0
fi
sleep 2
done
docker logs crac-postgres || true
echo "::error::Postgres sidecar did not become healthy."
exit 1
- name: Start Valkey sidecar
if: steps.sidecars.outputs.valkey == 'true'
env:
VALKEY_IMAGE: ${{ inputs.valkey-image }}
run: |
set -euo pipefail
docker rm -f crac-valkey >/dev/null 2>&1 || true
docker run -d \
--name crac-valkey \
-p 6379:6379 \
"${VALKEY_IMAGE}"
for _ in $(seq 1 60); do
if docker exec crac-valkey valkey-cli ping >/dev/null 2>&1; then
exit 0
fi
sleep 2
done
docker logs crac-valkey || true
echo "::error::Valkey sidecar did not become healthy."
exit 1
- name: Start RabbitMQ sidecar
if: steps.sidecars.outputs.rabbitmq == 'true'
env:
RABBITMQ_IMAGE: ${{ inputs.rabbitmq-image }}
run: |
set -euo pipefail
docker rm -f crac-rabbitmq >/dev/null 2>&1 || true
docker run -d \
--name crac-rabbitmq \
-p 5672:5672 \
"${RABBITMQ_IMAGE}"
for _ in $(seq 1 60); do
if docker exec crac-rabbitmq rabbitmq-diagnostics -q ping >/dev/null 2>&1; then
exit 0
fi
sleep 2
done
docker logs crac-rabbitmq || true
echo "::error::RabbitMQ sidecar did not become healthy."
exit 1
- name: Build training image
uses: docker/build-push-action@v7
with:
context: ${{ matrix.context || '.' }}
file: ${{ matrix.dockerfile }}
target: ${{ inputs.docker-target }}
load: true
tags: ${{ matrix.service }}-crac-train:local
cache-from: type=gha,scope=${{ matrix.service }}-crac-train
cache-to: type=gha,mode=max,scope=${{ matrix.service }}-crac-train
secrets: |
github_token=${{ secrets.packages-token || secrets.GITHUB_TOKEN }}
github_actor=${{ github.actor }}
- name: Run training
env:
CHECKPOINT_PATH: ${{ inputs.checkpoint-path }}
POSTGRES_ENABLED: ${{ steps.sidecars.outputs.postgres }}
VALKEY_ENABLED: ${{ steps.sidecars.outputs.valkey }}
RABBITMQ_ENABLED: ${{ steps.sidecars.outputs.rabbitmq }}
DB_USER: ${{ matrix.db_user || 'postgres' }}
DB_PASSWORD: ${{ matrix.db_password || 'postgres' }}
SERVER_PORT: ${{ matrix.port || '' }}
EXPECTED_EXIT_CODES: ${{ inputs.expected-exit-codes }}
EXTRA_DOCKER_RUN_ARGS: ${{ inputs.extra-docker-run-args }}
run: |
set -euo pipefail
mkdir -p checkpoint
chmod 777 checkpoint
docker_env_args=()
if [ "$POSTGRES_ENABLED" = "true" ]; then
docker_env_args+=(
-e DB_HOST=localhost
-e DB_PORT=5432
-e DB_USER="${DB_USER}"
-e DB_PASSWORD="${DB_PASSWORD}"
)
fi
if [ "$VALKEY_ENABLED" = "true" ]; then
docker_env_args+=(
-e VALKEY_HOST=localhost
-e VALKEY_PORT=6379
)
fi
if [ "$RABBITMQ_ENABLED" = "true" ]; then
docker_env_args+=(
-e SPRING_RABBITMQ_HOST=localhost
-e SPRING_RABBITMQ_PORT=5672
-e SPRING_RABBITMQ_USERNAME=guest
-e SPRING_RABBITMQ_PASSWORD=guest
)
fi
if [ -n "$SERVER_PORT" ]; then
docker_env_args+=(-e SERVER_PORT="${SERVER_PORT}")
fi
extra_args=()
if [ -n "$EXTRA_DOCKER_RUN_ARGS" ]; then
read -r -a extra_args <<< "$EXTRA_DOCKER_RUN_ARGS"
fi
set +e
docker run --rm \
--privileged \
--network=host \
-v "$PWD/checkpoint:${CHECKPOINT_PATH}" \
"${docker_env_args[@]}" \
"${extra_args[@]}" \
${{ matrix.service }}-crac-train:local
exit_code=$?
set -e
echo "Container exit code: ${exit_code}"
find checkpoint -maxdepth 2 -type f -print
if [ -z "$(ls -A checkpoint 2>/dev/null)" ]; then
echo "::error::checkpoint directory is empty"
exit 1
fi
for expected in ${EXPECTED_EXIT_CODES}; do
if [ "$exit_code" = "$expected" ]; then
exit 0
fi
done
echo "::error::training container exited ${exit_code}; expected one of: ${EXPECTED_EXIT_CODES}"
exit "$exit_code"
- name: Stop sidecars
if: always()
run: |
docker rm -f crac-postgres crac-valkey crac-rabbitmq >/dev/null 2>&1 || true
- uses: actions/upload-artifact@v7
with:
name: ${{ matrix.service }}-checkpoint
path: checkpoint/
if-no-files-found: error
retention-days: ${{ inputs.artifact-retention-days }}