rules.md

May 13, 2025 ยท View on GitHub

Public API re-exports

apko_config

load("@rules_apko//apko:defs.bzl", "apko_config")

apko_config(name, deps, config)

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsList of all dependencies of the config. Transitive dependencies are included based on ApkoConfigInfo provider.List of labelsoptional[]
configConfig of the image. Either in source directory or generated by Bazel.

When referencing other files in the config yaml file use paths relative to your Bazel workspace root. For example, if you want to reference source file foo/bar/baz use foo/bar/baz. If you want to reference output file of foo/bar:rule and rule's output file is rule.out, reference it as foo/bar/rule.out.
LabeloptionalNone

apko_show_config

load("@rules_apko//apko:defs.bzl", "apko_show_config")

apko_show_config(name, config)

Wrapper around apko show-config command to generate expanded config as bazel build action.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
configLabel to the apko.yaml file. For more advanced use-cases (multi-file configuration), use target providing ApkoConfigInfo (e.g. output of apko_config rule).Labelrequired

ApkoConfigInfo

load("@rules_apko//apko:defs.bzl", "ApkoConfigInfo")

ApkoConfigInfo(files)

Information about apko config. May be used when generating apko config file instead of using hardcoded ones.

When referencing other files in the config yaml file use paths relative to your Bazel workspace root. For example, if you want to reference source file foo/bar/baz use foo/bar/baz. If you want to reference output file of foo/bar:rule and rule's output file is rule.out, reference it as foo/bar/rule.out.

FIELDS

NameDescription
filesdepset of files that will be needed for building. All of them will be added to the execution of apko commands when built with Bazel.

apko_bazelrc

load("@rules_apko//apko:defs.bzl", "apko_bazelrc")

apko_bazelrc(name, repositories, **kwargs)

Helper macro for generating .bazelrc and range.sh files to allow for partial package fetches.

See initial setup documentation for more information.

PARAMETERS

NameDescriptionDefault Value
namename of the target"apko_bazelrc"
repositorieslist of repositories to generate .bazelrc for["dl-cdn.alpinelinux.org", "packages.wolfi.dev"]
kwargspassed to expanding targets. only well known attributes such as tags testonly ought to be present.none

apko_image

load("@rules_apko//apko:defs.bzl", "apko_image")

apko_image(name, contents, config, tag, output, architecture, args, **kwargs)

Build OCI images from APK packages directly without Dockerfile

This rule creates images using the 'apko.yaml' configuration file and relies on cache contents generated by translate_lock to be fast.

apko_image(
    name = "example",
    config = "apko.yaml",
    contents = "@example_lock//:contents",
    tag = "example:latest",
)

The label @example_lock//:contents is generated by the translate_lock extension, which consumes an 'apko.lock.json' file. For more details, refer to the documentation.

An example demonstrating usage with rules_oci

apko_image(
    name = "alpine_base",
    config = "apko.yaml",
    contents = "@alpine_base_lock//:contents",
    tag = "alpine_base:latest",
)

oci_image(
    name = "app",
    base = ":alpine_base"
)

For more examples checkout the examples directory.

PARAMETERS

NameDescriptionDefault Value
nameof the target for the generated image.none
contentsLabel to the contents repository generated by translate_lock. See apko-cache documentation.none
configLabel to the apko.yaml file. For more advanced use-cases (multi-file configuration), use target providing ApkoConfigInfo (e.g. output of apko_config rule).none
tagtag to apply to the resulting docker tarball. only applicable when output is dockernone
output"oci" of "docker","oci"
architecturethe CPU architecture which this image should be built to run on. See https://github.com/chainguard-dev/apko/blob/main/docs/apko_file.md#archs-top-level-element"),None
argsadditional arguments to provide when running the apko build command.[]
kwargsother common arguments like: tags, visibility.none

apko_lock

load("@rules_apko//apko:defs.bzl", "apko_lock")

apko_lock(name, config, lockfile_name, **kwargs)

Generates executable rule for producing apko lock files.

When run, the rule will output the lockfile to the lockfile_name in the directory of the package where the rule is defined. That is, if you define apko_lock in foo/bar/BUILD.bazel with lockfile_name="baz.lock.json the rule will output the lock into foo/bar/baz.lock.json.

PARAMETERS

NameDescriptionDefault Value
namename of the rule,none
configlabel of the apko config. It can be either a source file or generated target. Additionally, if the target provides ApkoConfigInfo provider, the transitive dependencies listed in ApkoConfigInfo.files will be added to runfiles as well.none
lockfile_namename of the lockfilenone
kwargsthe rule inherits standard attributes, like: tags, visibility, and args.none