Skip to content

Commit f4acba5

Browse files
alexeaglegregmagolan
authored andcommitted
chore: try rules_img
1 parent 21ad93c commit f4acba5

File tree

3 files changed

+43
-44
lines changed

3 files changed

+43
-44
lines changed

MODULE.bazel

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -258,30 +258,6 @@ use_repo(
258258
"swiftpkg_swifterswift",
259259
)
260260

261-
##########################
262-
# Container images
263-
oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
264-
oci.pull(
265-
name = "distroless_base",
266-
digest = "sha256:ccaef5ee2f1850270d453fdf700a5392534f8d1a8ca2acda391fbb6a06b81c86",
267-
image = "gcr.io/distroless/base",
268-
platforms = [
269-
"linux/amd64",
270-
"linux/arm64",
271-
],
272-
)
273-
oci.pull(
274-
name = "ubuntu",
275-
digest = "sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab",
276-
image = "ubuntu",
277-
platforms = [
278-
"linux/arm64/v8",
279-
"linux/amd64",
280-
],
281-
tag = "latest",
282-
)
283-
use_repo(oci, "distroless_base", "distroless_base_linux_amd64", "distroless_base_linux_arm64", "ubuntu", "ubuntu_linux_amd64", "ubuntu_linux_arm64_v8")
284-
285261
#########################
286262
# Support for Rust, see https://github.com/bazelbuild/rules_rust
287263
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
@@ -298,3 +274,5 @@ crate.from_cargo(
298274
manifests = ["//npm_packages/napi:Cargo.toml"],
299275
)
300276
use_repo(crate, "crate_index")
277+
278+
include("//tools:container_images.MODULE.bazel")

oci_go_image/BUILD.bazel

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
load("@aspect_bazel_lib//lib:testing.bzl", "assert_archive_contains")
2-
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
32
load("@container_structure_test//:defs.bzl", "container_structure_test")
43
load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
5-
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load", "oci_push")
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")
67
load("@tar.bzl", "mutate", "tar")
78

89
go_library(
@@ -41,26 +42,26 @@ assert_archive_contains(
4142
expected = ["app"],
4243
)
4344

44-
oci_image(
45-
name = "image",
45+
image_manifest(
46+
name = "_image",
4647
# This is defined by an oci.pull() call in /MODULE.bazel
4748
base = "@distroless_base",
4849
entrypoint = ["/app"],
4950
# Link the resulting image back to the repository where the build is defined.
5051
labels = {
5152
"org.opencontainers.image.source": "https://github.com/aspect-build/bazel-examples",
5253
},
53-
tars = [":app_layer"],
54+
layers = [":app_layer"],
5455
)
5556

5657
# This is the target that should be released to the target platform
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-
}),
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+
],
6465
)
6566

6667
# $ bazel run //oci_go_image:load
@@ -69,11 +70,11 @@ platform_transition_filegroup(
6970
# - "Hello World",
7071
# + "Hello Go",
7172
# )
72-
oci_load(
73+
image_load(
7374
name = "load",
7475
# Use the image built for the target platform
75-
image = ":transitioned_image",
76-
repo_tags = ["gcr.io/example:latest"],
76+
image = ":image",
77+
tag = "gcr.io/example:latest",
7778
)
7879

7980
container_structure_test(
@@ -87,12 +88,13 @@ container_structure_test(
8788
],
8889
)
8990

90-
oci_push(
91+
image_push(
9192
name = "push",
92-
image = ":transitioned_image",
93-
remote_tags = [
94-
"latest",
93+
image = ":image",
94+
registry = "ttl.sh",
95+
repository = "/aspect-build/oci_go_image_example",
96+
tags = [
9597
"24h",
98+
"latest",
9699
],
97-
repository = "ttl.sh/aspect-build/oci_go_image_example",
98100
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Container images"""
2+
3+
bazel_dep(name = "rules_img", version = "0.2.4")
4+
5+
pull = use_repo_rule("@rules_img//img:pull.bzl", "pull")
6+
7+
pull(
8+
name = "distroless_base",
9+
digest = "sha256:ccaef5ee2f1850270d453fdf700a5392534f8d1a8ca2acda391fbb6a06b81c86",
10+
registry = "gcr.io",
11+
repository = "distroless/base",
12+
)
13+
14+
pull(
15+
name = "ubuntu",
16+
digest = "sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab",
17+
repository = "ubuntu",
18+
tag = "latest",
19+
)

0 commit comments

Comments
 (0)