chainguard-dev / rules_apko

Bazel rules for apko
https://apko.dev
Apache License 2.0
23 stars 15 forks source link

Support apko configs that consist of multiple files. #64

Closed sfc-gh-mhazy closed 4 months ago

sfc-gh-mhazy commented 5 months ago

Overview

This PR is paving the way for image configurations that consist of multiple files. Currently an example of such configuration is any include usage, but in the future there will be more, for instance base image that is part of https://github.com/chainguard-dev/apko/issues/806.

Example

a.apko.yaml

contents
  repositories:
    - foo
   packages:
    - bar

b.apko.yaml

include: a.apko.yaml

env:
  FOO=BAR

c.apko.yaml

include: b.apko.yaml

env:
   X=Y

and finally

apko_image(
   config = "c.apko.yaml"
)

Details

RIght now the only file added to the build action in apko_image is the direct config. Therefore, the multi file config will fail to be evaluated by apko.

This PR introduces the apko_config rule that allows setting deps and ApkoConfigInfo provider to support transitive dependencies. We want to support including both source files and generated targets with the path referencing convention that both source and generated files are referenced as paths relative to workspace root.

Additionally I added dedicated apko_lock rule to decouple it from the one generated by apko_image. With the complex configs the restrictions in the latter were becoming problematic.

For the example above it would work as

BUILD

apko_config(
  name = "b",
  config = "b.apko.yaml",
  deps = [":a.apko.yaml"],
)

apko_config(
  name = "c",
  config = "c.apko.yaml",
  deps = [":b"],
)

apko_image(
   config = ":c"
)

c.apko.yaml

include: b

env:
   X=Y

The change is supposed to be fully backwards compatible - single file configs without ApkoConfigInfo providers are still supported.

Alternative considered

Move to the Bazel based apko configs apko_config, which may accept the parameters for every corresponding element of apko config.

How it works for example above

a.apko.yaml - remains as is

b.apko.yaml

env:
  FOO=BAR

and in BUILD

apko_config(
   name = "b"
   include = "a.apko.yaml"
   config = "b.apko.yaml"
)

c.apko.yaml

env:
   X=Y

and in BUILD

apko_config(
   name="c",
   include = ":b",
   config = "c.apko.yaml"
sfc-gh-ptabor commented 4 months ago

@sfc-gh-mhazy now the docs require regeneration after the spelling fixes.