Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -258,30 +258,6 @@ use_repo(
"swiftpkg_swifterswift",
)

##########################
# Container images
oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
name = "distroless_base",
digest = "sha256:ccaef5ee2f1850270d453fdf700a5392534f8d1a8ca2acda391fbb6a06b81c86",
image = "gcr.io/distroless/base",
platforms = [
"linux/amd64",
"linux/arm64",
],
)
oci.pull(
name = "ubuntu",
digest = "sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab",
image = "ubuntu",
platforms = [
"linux/arm64/v8",
"linux/amd64",
],
tag = "latest",
)
use_repo(oci, "distroless_base", "distroless_base_linux_amd64", "distroless_base_linux_arm64", "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8")

#########################
# Support for Rust, see https://github.com/bazelbuild/rules_rust
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
Expand All @@ -298,3 +274,5 @@ crate.from_cargo(
manifests = ["//npm_packages/napi:Cargo.toml"],
)
use_repo(crate, "crate_index")

include("//tools:container_images.MODULE.bazel")
42 changes: 22 additions & 20 deletions oci_go_image/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
load("@aspect_bazel_lib//lib:testing.bzl", "assert_archive_contains")
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load", "oci_push")
load("@rules_img//img:image.bzl", "image_index", "image_manifest")
load("@rules_img//img:load.bzl", "image_load")
load("@rules_img//img:push.bzl", "image_push")
load("@tar.bzl", "mutate", "tar")

go_library(
Expand Down Expand Up @@ -41,26 +42,26 @@ assert_archive_contains(
expected = ["app"],
)

oci_image(
name = "image",
image_manifest(
name = "_image",
# This is defined by an oci.pull() call in /MODULE.bazel
base = "@distroless_base",
entrypoint = ["/app"],
# Link the resulting image back to the repository where the build is defined.
labels = {
"org.opencontainers.image.source": "https://github.com/aspect-build/bazel-examples",
},
tars = [":app_layer"],
layers = [":app_layer"],
)

# This is the target that should be released to the target platform
platform_transition_filegroup(
name = "transitioned_image",
srcs = [":image"],
target_platform = select({
"@platforms//cpu:arm64": "@rules_go//go/toolchain:linux_arm64",
"@platforms//cpu:x86_64": "@rules_go//go/toolchain:linux_amd64",
}),
image_index(
name = "image",
manifests = [":_image"],
platforms = [
"@rules_go//go/toolchain:linux_arm64",
"@rules_go//go/toolchain:linux_amd64",
],
)

# $ bazel run //oci_go_image:load
Expand All @@ -69,11 +70,11 @@ platform_transition_filegroup(
# - "Hello World",
# + "Hello Go",
# )
oci_load(
image_load(
name = "load",
# Use the image built for the target platform
image = ":transitioned_image",
repo_tags = ["gcr.io/example:latest"],
image = ":image",
tag = "gcr.io/example:latest",
)

container_structure_test(
Expand All @@ -87,12 +88,13 @@ container_structure_test(
],
)

oci_push(
image_push(
name = "push",
image = ":transitioned_image",
remote_tags = [
"latest",
image = ":image",
registry = "ttl.sh",
repository = "/aspect-build/oci_go_image_example",
tags = [
"24h",
"latest",
],
repository = "ttl.sh/aspect-build/oci_go_image_example",
)
19 changes: 19 additions & 0 deletions tools/container_images.MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Container images"""

bazel_dep(name = "rules_img", version = "0.2.4")

pull = use_repo_rule("@rules_img//img:pull.bzl", "pull")

pull(
name = "distroless_base",
digest = "sha256:ccaef5ee2f1850270d453fdf700a5392534f8d1a8ca2acda391fbb6a06b81c86",
registry = "gcr.io",
repository = "distroless/base",
)

pull(
name = "ubuntu",
digest = "sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab",
repository = "ubuntu",
tag = "latest",
)