refactor: move custom images into lib/azk-image.sh #80

Merged
claudiomaradonna merged 2 commits from refactor/custom-image-lib into master 2026-11-21 16:42:56 +01:00
Collaborator

Why

The launcher bin/azkaban had grown past 2000 lines, a third of which is
the custom image subsystem: the approval of workspace Dockerfiles, tag
selection, base refresh, and the reuse and build of the per-workspace
images. Nothing else in the dispatcher reads that code's internals, and
it moves as one piece, so keeping it in the dispatcher mixed two
concerns in one file. The subsystem now lives in its own trusted
runtime library beside the host library, and the dispatcher keeps only
its call site.

This is a behavior-preserving refactor: what a launch shows, the engine
it invokes, the exit codes it returns, the approval records it writes,
and the images it builds stay exactly as before.

What changed

  • The ten custom-image functions move verbatim from bin/azkaban into
    the new lib/azk-image.sh (441 lines, byte-identical block), with a
    header stating its trusted-runtime status, in the style of
    lib/azk-host.sh. The _azk_ prefix and the shared helpers in
    bin/azkaban (_azk_die, _azk_find_runtime_file, and friends)
    stay where they are.
  • bin/azkaban locates the file with
    _azk_find_runtime_file lib azk-image.sh 'image library' and sources
    it inside _azk_main right after the host library, because the moved
    functions read and set that function's locals. The loader is the same
    fail-closed, symlink-rejecting, runtime-directory-anchored one the
    host library uses, so the new file is only ever loaded as trusted
    runtime code.
  • The test plumbing follows the new file: make_installed_runtime
    copies it, assert_published checks it among the published runtime
    files, and test_dispatch.sh gains the missing and symlinked
    image-library cases on the host-library pattern.
  • AGENTS.md and the trusted-code paragraph of docs/development.md
    now describe lib/ as holding the host-tool shims, the engine
    probes, and the custom image subsystem.

install.sh needs no change: it already stages lib/ whole and
syntax-checks and chmods it through lib/*.sh globs.

How to verify

From a fresh checkout of this branch (refactor/custom-image-lib,
tip 01e9109; base master at aaf5ddb); no prerequisites beyond a
Bash with ShellCheck available, as docs/development.md describes:

  • The new loader diagnostics are pinned by two new dispatcher tests:
    make test TESTS=dispatch runs 13 tests with 0 failures, including
    test_missing_runtime_owned_image_library_is_rejected and
    test_symlinked_runtime_owned_image_library_is_rejected, which
    delete or symlink the installed lib/azk-image.sh and require the
    launch to abort with the matching diagnostic and no Podman
    invocation. On the base, with only this branch's test_dispatch.sh
    copied over, both fail with unexpectedly succeeded, because the
    dispatcher there never looks for the file.
  • The behavior the extraction preserves is guarded by the suites that
    already pin it: make test TESTS=custom_image_approval (9),
    custom_image_naming (3), custom_image_failures (5),
    custom_image_shared (11), and auto_pull (9) all pass with the
    same counts on base and tip.
  • The installer publishes the new file:
    make test TESTS=install_publication passes 5/5 on the tip; on the
    base, with the branch's tests/helpers.sh and
    tests/integration/install_helpers.sh copied over, the tests that
    reach the new entry fail only on
    the release lib/azk-image.sh differs from the source, because the
    file does not exist there.

Checks already run on the tip: make lint && .agents/hooks/shellcheck.sh repo && make test exits 0, with 330 tests and 0 failures (the base
runs 328; the difference is the two new dispatch tests). The networked
release gate make test-e2e was not run: it needs real rootless Podman
and stays outside verification; nothing the change touches reaches the
container build, so its result is expected to be unchanged.

Considerations

  • The moved functions read _azk_main's locals, so the library must be
    sourced inside that function rather than at the top of the
    dispatcher; the two new dispatch tests pin that loading contract from
    the outside.
  • The one finding reviewed and already settled: the documentation
    commit's subject was 54 characters against the 50-character rule and
    was amended to 46 before this pull request.
## Why The launcher `bin/azkaban` had grown past 2000 lines, a third of which is the custom image subsystem: the approval of workspace Dockerfiles, tag selection, base refresh, and the reuse and build of the per-workspace images. Nothing else in the dispatcher reads that code's internals, and it moves as one piece, so keeping it in the dispatcher mixed two concerns in one file. The subsystem now lives in its own trusted runtime library beside the host library, and the dispatcher keeps only its call site. This is a behavior-preserving refactor: what a launch shows, the engine it invokes, the exit codes it returns, the approval records it writes, and the images it builds stay exactly as before. ## What changed - The ten custom-image functions move verbatim from `bin/azkaban` into the new `lib/azk-image.sh` (441 lines, byte-identical block), with a header stating its trusted-runtime status, in the style of `lib/azk-host.sh`. The `_azk_` prefix and the shared helpers in `bin/azkaban` (`_azk_die`, `_azk_find_runtime_file`, and friends) stay where they are. - `bin/azkaban` locates the file with `_azk_find_runtime_file lib azk-image.sh 'image library'` and sources it inside `_azk_main` right after the host library, because the moved functions read and set that function's locals. The loader is the same fail-closed, symlink-rejecting, runtime-directory-anchored one the host library uses, so the new file is only ever loaded as trusted runtime code. - The test plumbing follows the new file: `make_installed_runtime` copies it, `assert_published` checks it among the published runtime files, and `test_dispatch.sh` gains the missing and symlinked image-library cases on the host-library pattern. - `AGENTS.md` and the trusted-code paragraph of `docs/development.md` now describe `lib/` as holding the host-tool shims, the engine probes, and the custom image subsystem. `install.sh` needs no change: it already stages `lib/` whole and syntax-checks and chmods it through `lib/*.sh` globs. ## How to verify From a fresh checkout of this branch (`refactor/custom-image-lib`, tip `01e9109`; base `master` at `aaf5ddb`); no prerequisites beyond a Bash with ShellCheck available, as `docs/development.md` describes: - The new loader diagnostics are pinned by two new dispatcher tests: `make test TESTS=dispatch` runs 13 tests with 0 failures, including `test_missing_runtime_owned_image_library_is_rejected` and `test_symlinked_runtime_owned_image_library_is_rejected`, which delete or symlink the installed `lib/azk-image.sh` and require the launch to abort with the matching diagnostic and no Podman invocation. On the base, with only this branch's `test_dispatch.sh` copied over, both fail with `unexpectedly succeeded`, because the dispatcher there never looks for the file. - The behavior the extraction preserves is guarded by the suites that already pin it: `make test TESTS=custom_image_approval` (9), `custom_image_naming` (3), `custom_image_failures` (5), `custom_image_shared` (11), and `auto_pull` (9) all pass with the same counts on base and tip. - The installer publishes the new file: `make test TESTS=install_publication` passes 5/5 on the tip; on the base, with the branch's `tests/helpers.sh` and `tests/integration/install_helpers.sh` copied over, the tests that reach the new entry fail only on `the release lib/azk-image.sh differs from the source`, because the file does not exist there. Checks already run on the tip: `make lint && .agents/hooks/shellcheck.sh repo && make test` exits 0, with 330 tests and 0 failures (the base runs 328; the difference is the two new dispatch tests). The networked release gate `make test-e2e` was not run: it needs real rootless Podman and stays outside verification; nothing the change touches reaches the container build, so its result is expected to be unchanged. ## Considerations - The moved functions read `_azk_main`'s locals, so the library must be sourced inside that function rather than at the top of the dispatcher; the two new dispatch tests pin that loading contract from the outside. - The one finding reviewed and already settled: the documentation commit's subject was 54 characters against the 50-character rule and was amended to 46 before this pull request.
Extract the ten custom image functions from the dispatcher into a
trusted library of their own under lib/, sourced inside _azk_main
right after the host library, so image-feature changes no longer
touch the launcher core.  The functions move byte for byte, keep the
_azk_ prefix, and read _azk_main's locals as before; the shared
helpers stay in bin/azkaban.

Test plumbing follows the code: make_installed_runtime copies the new
file, assert_published lists it among the published runtime files,
and test_dispatch.sh gains the missing and symlinked image-library
cases as regression tests of the new not-found diagnostics.
install.sh needs no change: it already stages lib/ whole.
The dispatcher now stages lib/azk-image.sh beside lib/azk-host.sh, so
the component map and the trusted-code paragraph of the developer guide
name lib/ as holding the host-tool shims, the engine probes, and the
custom image subsystem.
claudiomaradonna deleted branch refactor/custom-image-lib 2026-11-21 16:43:02 +01:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
claudiomaradonna/azkaban!80
No description provided.