11load ("@aspect_bazel_lib//lib:testing.bzl" , "assert_archive_contains" )
2+ load ("@aspect_bazel_lib//lib:transitions.bzl" , "platform_transition_filegroup" )
23load ("@container_structure_test//:defs.bzl" , "container_structure_test" )
34load ("@rules_go//go:def.bzl" , "go_binary" , "go_library" , "go_test" )
4- load ("@rules_img//img:image.bzl" , "image_index" , "image_manifest" )
5- load ("@rules_img//img:load.bzl" , "image_load" )
6- load ("@rules_img//img:push.bzl" , "image_push" )
5+ load ("@rules_oci//oci:defs.bzl" , "oci_image" , "oci_load" , "oci_push" )
76load ("@tar.bzl" , "mutate" , "tar" )
87
98go_library (
@@ -42,26 +41,26 @@ assert_archive_contains(
4241 expected = ["app" ],
4342)
4443
45- image_manifest (
46- name = "_image " ,
44+ oci_image (
45+ name = "image " ,
4746 # This is defined by an oci.pull() call in /MODULE.bazel
4847 base = "@distroless_base" ,
4948 entrypoint = ["/app" ],
5049 # Link the resulting image back to the repository where the build is defined.
5150 labels = {
5251 "org.opencontainers.image.source" : "https://github.com/aspect-build/bazel-examples" ,
5352 },
54- layers = [":app_layer" ],
53+ tars = [":app_layer" ],
5554)
5655
5756# This is the target that should be released to the target platform
58- image_index (
59- name = "image " ,
60- manifests = [":_image " ],
61- platforms = [
62- "@rules_go//go/toolchain:linux_arm64" ,
63- "@rules_go//go/toolchain:linux_amd64" ,
64- ] ,
57+ platform_transition_filegroup (
58+ name = "transitioned_image " ,
59+ srcs = [":image " ],
60+ target_platform = select ({
61+ "@platforms//cpu:arm64" : "@ rules_go//go/toolchain:linux_arm64" ,
62+ "@platforms//cpu:x86_64" : "@ rules_go//go/toolchain:linux_amd64" ,
63+ }) ,
6564)
6665
6766# $ bazel run //oci_go_image:load
@@ -70,11 +69,11 @@ image_index(
7069# - "Hello World",
7170# + "Hello Go",
7271# )
73- image_load (
72+ oci_load (
7473 name = "load" ,
7574 # Use the image built for the target platform
76- image = ":image " ,
77- tag = "gcr.io/example:latest" ,
75+ image = ":transitioned_image " ,
76+ repo_tags = [ "gcr.io/example:latest" ] ,
7877)
7978
8079container_structure_test (
@@ -88,13 +87,12 @@ container_structure_test(
8887 ],
8988)
9089
91- image_push (
90+ oci_push (
9291 name = "push" ,
93- image = ":image" ,
94- registry = "ttl.sh" ,
95- repository = "/aspect-build/oci_go_image_example" ,
96- tags = [
97- "24h" ,
92+ image = ":transitioned_image" ,
93+ remote_tags = [
9894 "latest" ,
95+ "24h" ,
9996 ],
97+ repository = "ttl.sh/aspect-build/oci_go_image_example" ,
10098)
0 commit comments