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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
|
# sbo-testbuild image builder — Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Build the three chained bash scripts that produce `sbo-testbuild:current` / `sbo-testbuild:15.0` docker images from NAS Slackware trees and push them to a LAN registry, consumed by `.extras/test-build`.
**Architecture:** Adapt the forge `slackware/docker-images` scripts (`bootstrap.sh`, `build-full-image.sh`) into `.extras/image-builder/`. Add a third `build-sbo-testbuild.sh` layer. Share config + helpers via `config` and `lib.sh`. Pure-logic helpers are unit-tested with an assert-based self-check; the docker chain is verified manually on the VM.
**Tech Stack:** bash, docker, slackpkg/installpkg (Slackware), `registry:2`.
**Reference:** design spec at `.extras/docs/specs/2026-07-13-image-builder-design.md`. Forge originals cloned at (scratchpad) `docker-images/scripts/` — re-clone with `git clone slackware_forge:slackware/docker-images.git` if gone.
---
## File Structure
```
.extras/image-builder/
├── config REGISTRY, MIRROR, VARIANTS, PKGDIR (sourced by all)
├── lib.sh _log/_warn/_err, fetch(), txz_hash(), require_mount()
├── bootstrap.sh base image FROM scratch (root; installpkg from NAS)
├── build-full-image.sh full image FROM base (slackpkg all series)
├── build-sbo-testbuild.sh testbuild image FROM full (installpkg sbopkg + tools)
├── test-image-builder.sh assert-based self-check for lib.sh logic
└── README VM-side setup checklist
```
Responsibilities:
- **config** — the only place hostnames/paths/variants live. No script hardcodes them.
- **lib.sh** — all shared, testable logic. Sourced by the three build scripts and by the test. No side effects at source time (only function defs + nothing else).
- **bootstrap/full/testbuild** — one image each, thin: guard, gate, generate Dockerfile, build, push.
- **test-image-builder.sh** — sources lib.sh, exercises fetch/txz_hash/require_mount with asserts. No docker.
---
## Task 1: config + lib.sh skeleton
**Files:**
- Create: `.extras/image-builder/config`
- Create: `.extras/image-builder/lib.sh`
- [ ] **Step 1: Write config**
Create `.extras/image-builder/config`:
```sh
# Shared configuration for the sbo-testbuild image builder.
# Sourced by bootstrap.sh, build-full-image.sh, build-sbo-testbuild.sh, tests.
REGISTRY="docker.noland.dnx:5000"
MIRROR="file:///mnt/nas"
VARIANTS=(current 15.0) # x86_64 only for now
PKGDIR="/opt/sbo-testbuild/pkgs" # sbopkg + sbo-maintainer-tools .txz
HASH_DIR="/var/cache/sbo-testbuild" # ChangeLog hashes for rebuild gating
```
- [ ] **Step 2: Write lib.sh with logging + require_mount**
Create `.extras/image-builder/lib.sh`:
```sh
# Shared helpers for the image builder. Source, do not execute.
# Sourcing must have no side effects beyond defining functions.
_log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] [${LOG_TAG:-image-builder}] $*"; }
_warn() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] [${LOG_TAG:-image-builder}] WARNING: $*" >&2; }
_err() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] [${LOG_TAG:-image-builder}] ERROR: $*" >&2; exit 1; }
# mirror_path MIRROR RELPATH
# Join a MIRROR (file:///... or http(s)://...) with a relative path.
mirror_path() {
local mirror="$1" rel="$2"
printf '%s/%s' "${mirror%/}" "${rel#/}"
}
# is_local_mirror MIRROR -> 0 if file:// or bare absolute path, else 1
is_local_mirror() {
case "$1" in
file://*) return 0 ;;
http://*|https://*) return 1 ;;
/*) return 0 ;;
*) return 1 ;;
esac
}
# strip_scheme URL -> filesystem path for a file:// or bare-local URL
strip_scheme() {
local u="$1"
case "$u" in
file://*) printf '%s' "${u#file://}" ;;
*) printf '%s' "$u" ;;
esac
}
# fetch SRC DEST
# Copy SRC (a full mirror URL) to DEST. Local mirror -> cp, http -> curl.
# Returns non-zero on failure; caller decides whether that is fatal.
fetch() {
local src="$1" dest="$2"
if is_local_mirror "$src"; then
local path; path="$(strip_scheme "$src")"
[[ -f "$path" ]] || return 1
cp "$path" "$dest"
else
curl -sSfL --connect-timeout 60 "$src" -o "$dest"
fi
}
# txz_hash DIR
# Stable hash of the set of .txz files in DIR (names + contents), order
# independent. Empty/absent dir -> empty string.
txz_hash() {
local dir="$1"
[[ -d "$dir" ]] || { printf ''; return 0; }
local files; files=$(find "$dir" -maxdepth 1 -name '*.txz' -type f | sort)
[[ -n "$files" ]] || { printf ''; return 0; }
# Hash sorted "name sha256" lines so reordering does not change output.
while IFS= read -r f; do
printf '%s %s\n' "$(basename "$f")" "$(sha256sum "$f" | cut -d' ' -f1)"
done <<< "$files" | sha256sum | cut -d' ' -f1
}
# require_mount VERSION
# Assert the NAS tree for VERSION is mounted (file:// mirror only).
# x86_64 tree dir is slackware64-${VERSION}.
require_mount() {
local version="$1"
is_local_mirror "$MIRROR" || return 0 # http mirror: nothing to check
local base; base="$(strip_scheme "$MIRROR")"
local dir="${base}/slackware64-${version}"
[[ -d "$dir" ]] || _err "NAS tree not mounted: ${dir}"
}
```
- [ ] **Step 3: Commit**
```bash
git add .extras/image-builder/config .extras/image-builder/lib.sh
git commit -m 'image-builder: config + lib.sh helpers'
```
---
## Task 2: lib.sh self-check
**Files:**
- Create: `.extras/image-builder/test-image-builder.sh`
- [ ] **Step 1: Write the test**
Create `.extras/image-builder/test-image-builder.sh`:
```sh
#!/bin/bash
# Assert-based self-check for lib.sh pure logic. No docker, no network.
# Run: bash .extras/image-builder/test-image-builder.sh
set -u
cd "$(dirname "$0")"
source ./lib.sh
pass=0 fail=0
check() { # DESC EXPECTED ACTUAL
if [[ "$2" == "$3" ]]; then pass=$((pass+1));
else fail=$((fail+1)); echo "FAIL: $1"; echo " expected: [$2]"; echo " actual: [$3]"; fi
}
check_rc() { # DESC EXPECTED_RC ACTUAL_RC
if [[ "$2" == "$3" ]]; then pass=$((pass+1));
else fail=$((fail+1)); echo "FAIL: $1 (rc expected $2 got $3)"; fi
}
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
# --- mirror_path ---
check "mirror_path trailing slash" \
"file:///mnt/nas/slackware64-current/PACKAGES.TXT" \
"$(mirror_path 'file:///mnt/nas/' 'slackware64-current/PACKAGES.TXT')"
check "mirror_path no trailing slash" \
"file:///mnt/nas/x/y" "$(mirror_path 'file:///mnt/nas' '/x/y')"
# --- is_local_mirror ---
is_local_mirror "file:///mnt/nas"; check_rc "is_local file://" 0 $?
is_local_mirror "/mnt/nas"; check_rc "is_local bare abs" 0 $?
is_local_mirror "https://x/y"; check_rc "is_local https" 1 $?
# --- strip_scheme ---
check "strip_scheme file://" "/mnt/nas" "$(strip_scheme 'file:///mnt/nas')"
check "strip_scheme bare" "/mnt/nas" "$(strip_scheme '/mnt/nas')"
# --- fetch: local file resolves ---
echo hello > "$tmp/src.txt"
fetch "file://$tmp/src.txt" "$tmp/dst.txt"; check_rc "fetch local ok" 0 $?
check "fetch local content" "hello" "$(cat "$tmp/dst.txt" 2>/dev/null)"
# --- fetch: missing local file errors ---
fetch "file://$tmp/nope.txt" "$tmp/x.txt"; check_rc "fetch local missing" 1 $?
# --- txz_hash: stable + content-sensitive ---
mkdir -p "$tmp/pkgs"
printf a > "$tmp/pkgs/sbopkg-1.txz"
printf b > "$tmp/pkgs/tools-1.txz"
h1="$(txz_hash "$tmp/pkgs")"
h2="$(txz_hash "$tmp/pkgs")"
check "txz_hash stable" "$h1" "$h2"
printf c > "$tmp/pkgs/tools-1.txz" # change content
h3="$(txz_hash "$tmp/pkgs")"
check_rc "txz_hash changes on content" 0 "$([[ "$h1" != "$h3" ]] && echo 0 || echo 1)"
check "txz_hash empty dir" "" "$(txz_hash "$tmp/empty-nope")"
# --- require_mount: missing mount errors (subshell to catch _err exit) ---
MIRROR="file://$tmp/no-such-root"
( require_mount current ) 2>/dev/null; check_rc "require_mount missing" 1 $?
mkdir -p "$tmp/mnt/slackware64-current"
MIRROR="file://$tmp/mnt"
( require_mount current ) 2>/dev/null; check_rc "require_mount present" 0 $?
MIRROR="https://example/x"
( require_mount current ) 2>/dev/null; check_rc "require_mount http skips" 0 $?
echo "----"
echo "PASS: $pass FAIL: $fail"
[[ "$fail" -eq 0 ]]
```
- [ ] **Step 2: Run — expect PASS**
Run: `bash .extras/image-builder/test-image-builder.sh`
Expected: final line `PASS: N FAIL: 0`, exit 0.
If any FAIL, fix `lib.sh` (the test encodes the intended behavior).
- [ ] **Step 3: Commit**
```bash
git add .extras/image-builder/test-image-builder.sh
git commit -m 'image-builder: lib.sh self-check'
```
---
## Task 3: bootstrap.sh (base image)
**Files:**
- Create: `.extras/image-builder/bootstrap.sh`
- Reference: forge `docker-images/scripts/bootstrap.sh`
This is the forge `bootstrap.sh` adapted: source `config`+`lib.sh`, drop i586,
`file://` fetch via `fetch()`, LAN registry, `sbo-base` name, mount guard.
- [ ] **Step 1: Write bootstrap.sh**
Create `.extras/image-builder/bootstrap.sh`. Start from the forge original and apply exactly these changes; everything else (the `download_pkgtxt`, `find_package`, rootfs configuration, cleanup, Dockerfile-from-scratch blocks) is copied verbatim from the forge script:
1. Header block:
```sh
#!/bin/bash
# bootstrap.sh — build the sbo-base:{ver} image FROM scratch from NAS trees.
# Run as root (installpkg). Adapted from forge slackware/docker-images.
set -euo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
source "${HERE}/config"
LOG_TAG=bootstrap
source "${HERE}/lib.sh"
REGISTRY_IMAGE="${REGISTRY}/sbo-base"
[[ "${EUID}" -eq 0 ]] || _err "run as root."
mkdir -p "${HASH_DIR}"
```
2. Argument parsing: keep `--force` and `--version` only; **remove `--arch`**
(x86_64 fixed). Variant list comes from config:
```sh
FORCE=false
OPT_VERSION=""
while [[ $# -gt 0 ]]; do
case "$1" in
--version) OPT_VERSION="$2"; shift 2 ;;
--force) FORCE=true; shift ;;
*) _err "unknown argument: $1" ;;
esac
done
if [[ -n "${OPT_VERSION}" ]]; then
BUILD_VARIANTS=("${OPT_VERSION}")
else
BUILD_VARIANTS=("${VARIANTS[@]}")
fi
```
3. Copy the forge `PACKAGES=( ... )` array verbatim (lines 80–187 of the forge
original — the full base package list).
4. Replace `changelog_changed`: read ChangeLog via `fetch` from the NAS,
x86_64-only repo key:
```sh
# changelog_changed VERSION -> 0 if changed (or --force), else 1
changelog_changed() {
local version="$1"
local repo_key="slackware64-${version}"
local hash_file="${HASH_DIR}/${repo_key}.sha256"
local url; url="$(mirror_path "${MIRROR}" "${repo_key}/ChangeLog.txt")"
local tmp; tmp="$(mktemp)"
if ! fetch "${url}" "${tmp}"; then
rm -f "${tmp}"
_warn "${repo_key}: cannot read ChangeLog (${url}); skipping."
return 1
fi
local live; live=$(sha256sum "${tmp}" | cut -d' ' -f1); rm -f "${tmp}"
if [[ "${FORCE}" == "true" ]]; then
echo "${live}" > "${hash_file}"; return 0
fi
local stored=""; [[ -f "${hash_file}" ]] && stored=$(cat "${hash_file}")
if [[ "${live}" == "${stored}" ]]; then
_log "${repo_key}: ChangeLog unchanged; skipping."; return 1
fi
_log "${repo_key}: ChangeLog changed."; echo "${live}" > "${hash_file}"; return 0
}
```
5. Copy `download_pkgtxt` and `find_package` verbatim from the forge original,
but change the two `curl -sfL ... "${URL}" -o "${DEST}"` download lines in
`download_pkgtxt` to `fetch "${URL}" "${DEST}"` (drops the http assumption).
6. `build_variant`: take `VERSION` only (no ARCH). Set:
```sh
build_variant() {
local VERSION="$1"
require_mount "${VERSION}"
local REPO_KEY="slackware64-${VERSION}"
local PKG_PATH; PKG_PATH="$(mirror_path "${MIRROR}" "${REPO_KEY}")"
local TAG="${REGISTRY_IMAGE}:${VERSION}"
local SLACKPKG_MIRROR="https://slackware.nl/slackware/slackware64-${VERSION}/"
...
}
```
The `SLACKPKG_MIRROR` written into the image stays an https slackware.nl URL
(it is used later by slackpkg inside the container, which has internet; the
NAS `file://` mount only feeds the host-side build). Keep the rest of the
forge `build_variant` body verbatim, except:
- the package **download loop** uses `fetch "${URL}" "${PKGCACHE}/${FILENAME}"`
instead of `curl`.
- the final `docker build ... && docker push` targets `${TAG}` as above.
7. Main loop over `BUILD_VARIANTS`, one arg:
```sh
for VERSION in "${BUILD_VARIANTS[@]}"; do
if changelog_changed "${VERSION}"; then
build_variant "${VERSION}"
fi
done
```
- [ ] **Step 2: Syntax check**
Run: `bash -n .extras/image-builder/bootstrap.sh`
Expected: no output, exit 0.
- [ ] **Step 3: shellcheck (if available)**
Run: `shellcheck -x .extras/image-builder/bootstrap.sh || true`
Expected: no errors (warnings about unreachable `_err` exit are fine). If shellcheck absent, skip.
- [ ] **Step 4: Commit**
```bash
git add .extras/image-builder/bootstrap.sh
git commit -m 'image-builder: bootstrap.sh base image from NAS'
```
---
## Task 4: build-full-image.sh
**Files:**
- Create: `.extras/image-builder/build-full-image.sh`
- Reference: forge `docker-images/scripts/build-full-image.sh`
Forge `build-full-image.sh` adapted: source config+lib, drop i586, LAN
registry, `sbo-base`→`sbo-full` names.
- [ ] **Step 1: Write build-full-image.sh**
Create `.extras/image-builder/build-full-image.sh`. From the forge original, apply exactly:
1. Header:
```sh
#!/bin/bash
# build-full-image.sh — sbo-full:{ver} FROM sbo-base:{ver}, all series.
# Adapted from forge slackware/docker-images. No root needed.
set -euo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
source "${HERE}/config"
LOG_TAG=full
source "${HERE}/lib.sh"
BASE_IMAGE="${REGISTRY}/sbo-base"
FULL_IMAGE="${REGISTRY}/sbo-full"
DIGEST_LABEL="sbo.full.base-digest"
```
2. Arg parsing: `--force` and `--version` only (no `--arch`), variant list from
config — identical shape to bootstrap Task 3 Step 1.2, but `BUILD_VARIANTS`.
3. `derive_tags VERSION`:
```sh
derive_tags() {
local VERSION="$1"
BASE_TAG="${BASE_IMAGE}:${VERSION}"
FULL_TAG="${FULL_IMAGE}:${VERSION}"
}
```
4. Keep `needs_rebuild` verbatim from the forge original (it already takes
BASE_TAG/FULL_TAG args and uses `_log`/`_warn`/`FORCE`).
5. `build_variant VERSION`: drop the ARCH/ARCH_SUFFIX lines; call
`derive_tags "${VERSION}"`. Keep the forge Dockerfile heredoc **verbatim**
(the `slackpkg update` + all-series install + cleanup + labels). Only the
`LABEL org.opencontainers.image.title/description` strings lose the
`(${ARCH})` suffix; leave them or hardcode `(x86_64)`.
6. Main loop over `BUILD_VARIANTS`:
```sh
for VERSION in "${BUILD_VARIANTS[@]}"; do
build_variant "${VERSION}"
done
```
- [ ] **Step 2: Syntax check**
Run: `bash -n .extras/image-builder/build-full-image.sh`
Expected: exit 0.
- [ ] **Step 3: shellcheck (if available)**
Run: `shellcheck -x .extras/image-builder/build-full-image.sh || true`
- [ ] **Step 4: Commit**
```bash
git add .extras/image-builder/build-full-image.sh
git commit -m 'image-builder: build-full-image.sh'
```
---
## Task 5: build-sbo-testbuild.sh
**Files:**
- Create: `.extras/image-builder/build-sbo-testbuild.sh`
New script (no forge equivalent). FROM sbo-full, installpkg the two .txz,
gate on full digest AND .txz-set hash.
- [ ] **Step 1: Write build-sbo-testbuild.sh**
Create `.extras/image-builder/build-sbo-testbuild.sh`:
```sh
#!/bin/bash
# build-sbo-testbuild.sh — sbo-testbuild:{ver} FROM sbo-full:{ver}.
# Adds sbopkg + sbo-maintainer-tools from prebuilt .txz in PKGDIR.
# Rebuilds when the full image OR the .txz set changes.
set -euo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
source "${HERE}/config"
LOG_TAG=testbuild
source "${HERE}/lib.sh"
FULL_IMAGE="${REGISTRY}/sbo-full"
TB_IMAGE="${REGISTRY}/sbo-testbuild"
DIGEST_LABEL="sbo.testbuild.full-digest"
PKGS_LABEL="sbo.testbuild.pkgs-hash"
FORCE=false
OPT_VERSION=""
while [[ $# -gt 0 ]]; do
case "$1" in
--version) OPT_VERSION="$2"; shift 2 ;;
--force) FORCE=true; shift ;;
*) _err "unknown argument: $1" ;;
esac
done
if [[ -n "${OPT_VERSION}" ]]; then
BUILD_VARIANTS=("${OPT_VERSION}")
else
BUILD_VARIANTS=("${VARIANTS[@]}")
fi
# Verify the required .txz are present before doing anything.
require_pkgs() {
[[ -d "${PKGDIR}" ]] || _err "PKGDIR missing: ${PKGDIR}"
compgen -G "${PKGDIR}/sbopkg-*.txz" >/dev/null \
|| _err "no sbopkg-*.txz in ${PKGDIR}"
compgen -G "${PKGDIR}/sbo-maintainer-tools-*.txz" >/dev/null \
|| _err "no sbo-maintainer-tools-*.txz in ${PKGDIR}"
}
# needs_rebuild FULL_TAG TB_TAG PKGS_HASH -> 0 if rebuild needed
needs_rebuild() {
local full_tag="$1" tb_tag="$2" pkgs_hash="$3"
[[ "${FORCE}" == "true" ]] && { _log " --force."; return 0; }
local full_digest
full_digest=$(docker inspect --format '{{index .RepoDigests 0}}' \
"${full_tag}" 2>/dev/null || echo "")
[[ -n "${full_digest}" ]] || { _warn " no full digest; rebuilding."; return 0; }
local rec_digest rec_pkgs
rec_digest=$(docker inspect \
--format "{{index .Config.Labels \"${DIGEST_LABEL}\"}}" \
"${tb_tag}" 2>/dev/null || echo "")
rec_pkgs=$(docker inspect \
--format "{{index .Config.Labels \"${PKGS_LABEL}\"}}" \
"${tb_tag}" 2>/dev/null || echo "")
if [[ "${full_digest}" == "${rec_digest}" && "${pkgs_hash}" == "${rec_pkgs}" ]]; then
_log " full image and .txz set unchanged; skipping."
return 1
fi
_log " full image or .txz set changed; rebuilding."
return 0
}
build_variant() {
local VERSION="$1"
local FULL_TAG="${FULL_IMAGE}:${VERSION}"
local TB_TAG="${TB_IMAGE}:${VERSION}"
_log "=== ${TB_TAG} ==="
_log " Pulling ${FULL_TAG}..."
docker pull "${FULL_TAG}"
local PKGS_HASH; PKGS_HASH="$(txz_hash "${PKGDIR}")"
if ! needs_rebuild "${FULL_TAG}" "${TB_TAG}" "${PKGS_HASH}"; then
return 0
fi
local FULL_DIGEST
FULL_DIGEST=$(docker inspect --format '{{index .RepoDigests 0}}' "${FULL_TAG}")
local WORKDIR; WORKDIR="$(mktemp -d /tmp/sbo-testbuild.XXXXXX)"
trap "rm -rf '${WORKDIR}'" RETURN
mkdir -p "${WORKDIR}/pkgs"
cp "${PKGDIR}"/sbopkg-*.txz "${PKGDIR}"/sbo-maintainer-tools-*.txz "${WORKDIR}/pkgs/"
cat > "${WORKDIR}/Dockerfile" <<DOCKERFILE
FROM ${FULL_TAG}
LABEL maintainer="danix <danix@danix.xyz>"
COPY pkgs/*.txz /tmp/pkgs/
RUN installpkg /tmp/pkgs/*.txz && rm -rf /tmp/pkgs
RUN /sbin/ldconfig
LABEL org.opencontainers.image.created="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
LABEL org.opencontainers.image.title="SBo test-build env ${VERSION} (x86_64)"
LABEL org.opencontainers.image.description="Slackware ${VERSION} full + sbopkg + sbo-maintainer-tools"
LABEL slackware.version="${VERSION}"
LABEL ${DIGEST_LABEL}="${FULL_DIGEST}"
LABEL ${PKGS_LABEL}="${PKGS_HASH}"
CMD ["/bin/bash"]
DOCKERFILE
local BUILD_FLAGS=()
[[ "${FORCE}" == "true" ]] && BUILD_FLAGS+=(--no-cache)
_log " Building ${TB_TAG}..."
docker build "${BUILD_FLAGS[@]}" -t "${TB_TAG}" "${WORKDIR}"
_log " Pushing ${TB_TAG}..."
docker push "${TB_TAG}"
_log "=== Done: ${TB_TAG} ==="
}
require_pkgs
for VERSION in "${BUILD_VARIANTS[@]}"; do
build_variant "${VERSION}"
done
```
- [ ] **Step 2: Syntax check**
Run: `bash -n .extras/image-builder/build-sbo-testbuild.sh`
Expected: exit 0.
- [ ] **Step 3: shellcheck (if available)**
Run: `shellcheck -x .extras/image-builder/build-sbo-testbuild.sh || true`
- [ ] **Step 4: Commit**
```bash
git add .extras/image-builder/build-sbo-testbuild.sh
git commit -m 'image-builder: build-sbo-testbuild.sh'
```
---
## Task 6: per-variant isolation
The spec requires one variant failing not to block the other, non-zero exit at
the end. Add this to all three scripts' main loops.
**Files:**
- Modify: `.extras/image-builder/bootstrap.sh` (main loop)
- Modify: `.extras/image-builder/build-full-image.sh` (main loop)
- Modify: `.extras/image-builder/build-sbo-testbuild.sh` (main loop)
- [ ] **Step 1: Wrap each main loop**
In each script, replace the plain `for VERSION ...` main loop with an
isolation wrapper. For **bootstrap.sh** (which also has the changelog gate):
```sh
rc=0
for VERSION in "${BUILD_VARIANTS[@]}"; do
if changelog_changed "${VERSION}"; then
if ! ( build_variant "${VERSION}" ); then
_warn "variant ${VERSION} failed; continuing."
rc=1
fi
fi
done
exit "${rc}"
```
For **build-full-image.sh** and **build-sbo-testbuild.sh** (no changelog gate):
```sh
rc=0
for VERSION in "${BUILD_VARIANTS[@]}"; do
if ! ( build_variant "${VERSION}" ); then
_warn "variant ${VERSION} failed; continuing."
rc=1
fi
done
exit "${rc}"
```
Note: `build_variant` runs in a subshell `( )` so a `set -e` abort inside it
(or an `_err` exit) is contained and the loop proceeds to the next variant.
For build-sbo-testbuild.sh keep the `require_pkgs` call **before** the loop
(a missing .txz is fatal for all variants, not per-variant).
- [ ] **Step 2: Syntax check all three**
Run: `for f in bootstrap build-full-image build-sbo-testbuild; do bash -n .extras/image-builder/$f.sh; done`
Expected: exit 0, no output.
- [ ] **Step 3: Re-run lib self-check (unaffected, sanity)**
Run: `bash .extras/image-builder/test-image-builder.sh`
Expected: `FAIL: 0`.
- [ ] **Step 4: Commit**
```bash
git add .extras/image-builder/bootstrap.sh .extras/image-builder/build-full-image.sh .extras/image-builder/build-sbo-testbuild.sh
git commit -m 'image-builder: per-variant isolation, non-zero exit on failure'
```
---
## Task 7: README
**Files:**
- Create: `.extras/image-builder/README`
- [ ] **Step 1: Write README**
Create `.extras/image-builder/README` with the VM-side setup, verbatim:
```
sbo-testbuild image builder
===========================
Builds the docker images that .extras/test-build consumes:
docker.noland.dnx:5000/sbo-testbuild:current
docker.noland.dnx:5000/sbo-testbuild:15.0
Three scripts, chained (see .extras/docs/specs/2026-07-13-image-builder-design.md):
bootstrap.sh sbo-base:{ver} FROM scratch, base pkgs from NAS
build-full-image.sh sbo-full:{ver} FROM base, all series
build-sbo-testbuild.sh sbo-testbuild:{ver} FROM full, + sbopkg + tools
All settings live in ./config.
VM setup (docker.noland.dnx, Slackware x86_64, 4 vCPU / 4 GB / 80 GB)
--------------------------------------------------------------------
1. Install docker; enable the daemon.
2. NFS-mount the two NAS trees read-only, named to match:
/mnt/nas/slackware64-current -> -current mirror tree
/mnt/nas/slackware64-15.0 -> 15.0 mirror tree
Each is a full mirror (PACKAGES.TXT, ChangeLog.txt, slackware64/, patches/,
extra/). Root must be able to read them (bootstrap runs installpkg as root).
3. Run a LAN registry:
docker run -d --restart=always -p 5000:5000 \
-v /opt/registry/data:/var/lib/registry --name registry registry:2
4. Mark the registry insecure (plain HTTP) on the VM AND every pulling client
(this dev box, the buildsystem VM). In /etc/docker/daemon.json:
{ "insecure-registries": ["docker.noland.dnx:5000"] }
then restart docker.
5. Drop the two prebuilt packages (built once, re-drop on upstream bumps):
/opt/sbo-testbuild/pkgs/sbopkg-*.txz
/opt/sbo-testbuild/pkgs/sbo-maintainer-tools-*.txz
6. Install the nightly cron (root):
0 4 * * * /path/to/.extras/image-builder/bootstrap.sh >> /var/log/sbo-testbuild.log 2>&1
15 4 * * * /path/to/.extras/image-builder/build-full-image.sh >> /var/log/sbo-testbuild.log 2>&1
30 4 * * * /path/to/.extras/image-builder/build-sbo-testbuild.sh >> /var/log/sbo-testbuild.log 2>&1
7. Ensure docker.noland.dnx resolves on the LAN (static IP or DNS).
Manual first run
----------------
./bootstrap.sh --version current --force
./build-full-image.sh --version current --force
./build-sbo-testbuild.sh --version current --force
Then confirm:
docker pull docker.noland.dnx:5000/sbo-testbuild:current
docker run --rm docker.noland.dnx:5000/sbo-testbuild:current sbopkg -V
Flags: --force (rebuild unconditionally), --version <current|15.0> (one variant).
Tests
-----
bash test-image-builder.sh # pure-logic self-check, no docker
```
- [ ] **Step 2: Commit**
```bash
git add .extras/image-builder/README
git commit -m 'image-builder: README with VM setup checklist'
```
---
## Task 8: executable bits + final check
**Files:**
- Modify (mode): the four `.sh` scripts
- [ ] **Step 1: chmod +x the scripts**
```bash
chmod +x .extras/image-builder/bootstrap.sh \
.extras/image-builder/build-full-image.sh \
.extras/image-builder/build-sbo-testbuild.sh \
.extras/image-builder/test-image-builder.sh
```
- [ ] **Step 2: Run the self-check once more**
Run: `bash .extras/image-builder/test-image-builder.sh`
Expected: `PASS: N FAIL: 0`, exit 0.
- [ ] **Step 3: Syntax-check all four**
Run: `for f in .extras/image-builder/*.sh; do bash -n "$f" || echo "SYNTAX FAIL: $f"; done`
Expected: no `SYNTAX FAIL` lines.
- [ ] **Step 4: Commit**
```bash
git add .extras/image-builder
git commit -m 'image-builder: mark scripts executable'
```
---
## Deferred (not in this plan)
- **Real end-to-end chain** on the VM (bootstrap→full→testbuild producing a
pushed `sbo-testbuild:current`): the user runs it once the VM/registry/mounts
exist, and reports back. Mirrors `.extras/test-build` Task 10.
- **`installed_in_base`** in `.extras/test-build`: now unblockable (query the
built image's package db) but tracked separately in the project memory
`test-build-image-builder-todo`.
- **i586** variants.
- **Registry auth/TLS** (LAN plain HTTP for now).
```
|