Skip to content

fix: generate apko_image .lock target for root-package and lock-less configs - #429

Open
officialasishkumar wants to merge 1 commit into
chainguard-dev:mainfrom
officialasishkumar:fix-apko-image-lock-target
Open

officialasishkumar wants to merge 1 commit into
chainguard-dev:mainfrom
officialasishkumar:fix-apko-image-lock-target

Conversation

@officialasishkumar

Copy link
Copy Markdown

Fixes #428.

The apko_image macro adds a companion <name>.lock target when its config is a .yaml file in the same package. That code broke in two layouts:

  • No lock file next to the config (Bazel 8+): the check used native.glob([lock_json_name]) without allow_empty. Bazel 8 turned on --incompatible_disallow_empty_glob by default, so the package failed to load when the lock was in another package or had another name. It now passes allow_empty = True, as the .resolved.json glob below it already did, and the .lock target is just not generated.
  • Config in the root package: the output was "{package}/{lock}", which turns into --output=/apko.lock.json when the package is "", so bazel run //:<image>.lock wrote to the filesystem root. Both .lock and .resolve now use paths.join, the same fix Update apko_lock.bzl #163 made in apko_lock.

The README now says when the .lock target exists and points to apko_lock for other layouts.

Tests

Both new tests are in e2e/smoke, and both fail on main:

  • //lock_in_other_package:test builds an apko_image whose config is a copy of //:apko.yaml and has no adjacent lock file. It uses @example_lock//:contents, which comes from //:apko.lock.json. On main the package fails to load with Error in glob: glob pattern 'apko.lock.json' didn't match anything.
  • //:lock_target_output_test runs genquery on //:lock.lock and checks that it writes to "--output=apko.lock.json". On main the query shows "--output=/apko.lock.json", and the test fails.

Validation

  • With the fix applied, bazel run //:lock.lock in e2e/smoke ran apko lock ./apko.yaml '--output=apko.lock.json' and updated e2e/smoke/apko.lock.json in the workspace.
  • bazel test //... in e2e/smoke passes on Bazel 9.1.0, 8.3.0 and 7.6.1 (6/6), and the CI aquery check still finds no no-remote-exec. Without the apko_image.bzl change, the glob error and the failing lock_target_output_test both come back.
  • In the root module, //apko/tests, //docs (unchanged), //examples/simple and //examples/wolfi-base pass, and //.github/workflows:buildifier.check is clean.

Note: Alpine has removed musl-1.2.5-r11, which the checked-in e2e/smoke and examples/lock lock files pin. With a cold repository cache those repos 404 on main too, which is why the 7.6.1, e2e/smoke lane fails there. For the local runs above I relocked the two e2e lock files on my machine and did not commit them. I left relocking out of this PR because #418 already touches those files.

…configs

The apko_image macro adds a companion `<name>.lock` target (and the
deprecated `<name>.resolve`) when the config is a `.yaml` file in the
same package. That code broke in two layouts:

1. It checked for `<config>.lock.json` with `native.glob([...])` and no
   `allow_empty`. Bazel 8 turned `--incompatible_disallow_empty_glob` on
   by default, so any package whose apko_image config has no lock file
   next to it (for example, when the lock lives in another package or
   has another name) failed to load with "glob pattern 'apko.lock.json'
   didn't match anything". The `.resolved.json` glob next to it already
   had `allow_empty = True`. The lock glob now has it too, so the
   companion target is just skipped.

2. The output path was built as "{package}/{lock}". In the root package
   that gives `--output=/apko.lock.json`, so `bazel run //:<image>.lock`
   wrote to the filesystem root rather than the workspace root, where
   apko_run starts apko. This is the bug fixed for apko_lock in chainguard-dev#163. Both
   targets now use paths.join, which keeps the path workspace-relative.

Tests (e2e/smoke):
- lock_in_other_package/ builds an apko_image whose config has no
  adjacent lock file and uses //:apko.lock.json. Without the fix, the
  package fails to load on Bazel 8+.
- lock_target_output_test runs genquery on //:lock.lock and checks that
  the lock is written to "apko.lock.json". Without the fix it sees
  "/apko.lock.json" and fails.

The README now says when the `.lock` target exists and points to
apko_lock for other layouts.

Fixes chainguard-dev#428
Rodrigo-Munoz-Salas added a commit that referenced this pull request Nov 30, 2026
## What

Regenerates the four lock files that pin Alpine `musl-1.2.5-r11`, which
`dl-cdn.alpinelinux.org` no longer serves:

- `e2e/smoke/apko.lock.json`
- `e2e/smoke/multifile_config/apko.generated.lock.json`
- `e2e/smoke/multifile_config/base_config.apko.lock.json`
- `examples/lock/apko.lock.json`

They now pin `musl-1.2.5-r12`. The toolchain's apko (v1.4.6) also
records each keyring's content in the lock, so that appears in the diff
too.

## Why

Since 2026-11-09, every build that fetches these locks fails with a 404
on `musl-1.2.5-r11.apk`. That keeps CI red on main and on every open
pull request, including the apko bump in #407, and blocks the weekly
release. The BCR presubmit runs `e2e/smoke //...`, so it would fail the
same way for any release that ships these locks (#408).

## How

- `examples/lock/apko.lock.json` and `apko.generated.lock.json` come
from their lock targets, `bazel run //examples/lock:lock.lock` and
`bazel run //multifile_config:lock_from_generated_config` in
`e2e/smoke`.
- `e2e/smoke/apko.lock.json` and `base_config.apko.lock.json` come from
the same apko binary, run with `apko lock` from the repository root so
each keeps its original `config.name`. The root-package lock target
(`//:lock.lock` in `e2e/smoke`) writes to `/apko.lock.json` and fails,
which #429 fixes.

## Testing

- `bazel test //...` in `e2e/smoke`: 4 of 4 pass.
- `bazel test //...` at the repository root: 6 of 6 pass, including
`//examples/lock:test`.
- No lock file in the repository pins `musl-1.2.5-r11` any more.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apko_image's generated .lock target breaks loading on Bazel 8+ without an adjacent lock file, and writes to / for root-package configs

1 participant