diff --git a/MODULE.bazel b/MODULE.bazel index d7ffb69f..daf5434d 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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") @@ -298,3 +274,5 @@ crate.from_cargo( manifests = ["//npm_packages/napi:Cargo.toml"], ) use_repo(crate, "crate_index") + +include("//tools:container_images.MODULE.bazel") diff --git a/oci_go_image/BUILD.bazel b/oci_go_image/BUILD.bazel index 43bedd28..2fce46ca 100644 --- a/oci_go_image/BUILD.bazel +++ b/oci_go_image/BUILD.bazel @@ -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( @@ -41,8 +42,8 @@ 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"], @@ -50,17 +51,17 @@ oci_image( 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 @@ -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( @@ -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", ) diff --git a/tools/container_images.MODULE.bazel b/tools/container_images.MODULE.bazel new file mode 100644 index 00000000..e64da39e --- /dev/null +++ b/tools/container_images.MODULE.bazel @@ -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", +)