Skip to content

Commit

Permalink
feat: support oci-layout output (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn authored Sep 15, 2023
1 parent 1ff3dd8 commit dbbbdc0
Show file tree
Hide file tree
Showing 10 changed files with 1,965 additions and 54 deletions.
8 changes: 8 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "aspect_bazel_lib", version = "1.34.5")

bazel_dep(name = "container_structure_test", version = "1.15.0", dev_dependency = True)
bazel_dep(name = "rules_pkg", version = "0.7.0", dev_dependency = True)
bazel_dep(name = "rules_oci", version = "1.3.3", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.29.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.1", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "6.1.0", dev_dependency = True)
Expand All @@ -34,5 +37,10 @@ apk.translate_lock(
name = "examples_wolfi_base",
lock = "//examples/wolfi-base:apko.lock.json",
)
apk.translate_lock(
name = "examples_oci",
lock = "//examples/oci:apko.lock.json",
)
use_repo(apk, "examples_lock")
use_repo(apk, "examples_wolfi_base")
use_repo(apk, "examples_oci")
1,373 changes: 1,325 additions & 48 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion apko/private/apko_image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@ _ATTRS = {
"packages": attr.label(),
"tag": attr.string(mandatory = True),
"config": attr.label(allow_single_file = True, mandatory = True),
"output": attr.string(default = "oci", values = ["oci", "docker"]),
"args": attr.string_list(),
}

def _impl(ctx):
apko_info = ctx.toolchains["@rules_apko//apko:toolchain_type"].apko_info

cache_name = "cache_{}".format(ctx.label.name)

output = ctx.actions.declare_file("{}.tar".format(ctx.label.name))
if ctx.attr.output == "oci":
output = ctx.actions.declare_directory(ctx.label.name)
else:
output = ctx.actions.declare_file("{}.tar".format(ctx.label.name))

args = ctx.actions.args()
args.add("build")
args.add(ctx.file.config.path)
args.add(ctx.attr.tag)
args.add(output.path)

args.add("--vcs=false")

args.add_all(ctx.attr.args)

args.add("--cache-dir={}/{}/{}".format(ctx.bin_dir.path, ctx.label.package, cache_name))
args.add("--offline")

Expand Down
4 changes: 3 additions & 1 deletion docs/rules.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions examples/oci/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
load("@rules_apko//apko:defs.bzl", "apko_image")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("@container_structure_test//:defs.bzl", "container_structure_test")

# An example demonstrating how to use apko_image with rules_oci
# See MODULE.bazel for how apko.lock.json is translated to @examples_oci//:contents
apko_image(
name = "wolfi-base",
args = select({
"@platforms//cpu:arm64": [
"--arch",
"aarch64",
],
"@platforms//cpu:x86_64": [
"--arch",
"x86_64",
],
}),
config = "apko.yaml",
packages = "@examples_oci//:contents",
tag = "wolfi:latest",
)

pkg_tar(
name = "layer",
srcs = ["say_hello.sh"],
)

oci_image(
name = "image",
base = ":wolfi-base",
cmd = ["/say_hello.sh"],
tars = [
":layer",
],
)

oci_tarball(
name = "tarball",
image = ":image",
repo_tags = ["apko_oci:latest"],
)

container_structure_test(
name = "test",
configs = ["test.yaml"],
image = ":image",
)
Loading

0 comments on commit dbbbdc0

Please sign in to comment.