|
1 | | -load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index", "oci_push") |
2 | | -load("@rules_pkg//pkg:tar.bzl", "pkg_tar") |
| 1 | +load("@rules_img//img:layer.bzl", "image_layer") |
| 2 | +load("@rules_img//img:image.bzl", "image_manifest", "image_index") |
| 3 | +load("@rules_img//img:push.bzl", "image_push") |
3 | 4 |
|
4 | 5 | def multiarch_go_image(name, binary): |
5 | 6 | """Create a container image with two variants of the given go_binary target. |
6 | 7 |
|
7 | 8 | Args: |
8 | | - name: resulting oci_image_index target |
| 9 | + name: resulting image_index target |
9 | 10 | binary: label of a go_binary target; it may be transitioned to another architecture |
10 | 11 | """ |
11 | 12 |
|
12 | 13 | tar_target = "_{}.tar".format(name) |
13 | 14 | image_target = "_{}.image".format(name) |
14 | 15 |
|
15 | | - pkg_tar( |
| 16 | + image_layer( |
16 | 17 | name = tar_target, |
17 | | - srcs = [binary], |
18 | | - include_runfiles = True, |
19 | | - package_dir = "app", |
20 | | - extension = "tar.gz", |
| 18 | + srcs = {"app/{}".format(native.package_relative_label(binary).name): binary}, |
21 | 19 | ) |
22 | 20 |
|
23 | | - oci_image( |
| 21 | + image_manifest( |
24 | 22 | name = image_target, |
25 | 23 | base = Label("@distroless_static"), |
26 | 24 | entrypoint = ["/app/{}".format(native.package_relative_label(binary).name)], |
27 | | - tars = [tar_target], |
| 25 | + layers = [tar_target], |
28 | 26 | # Don't build un-transitioned images, as the default target architecture might be unsupported |
29 | 27 | # For example when building on linux-i386. |
30 | 28 | tags = ["manual"], |
31 | 29 | ) |
32 | 30 |
|
33 | | - oci_image_index( |
| 31 | + image_index( |
34 | 32 | name = name, |
35 | | - images = [image_target], |
| 33 | + manifests = [image_target], |
36 | 34 | platforms = [ |
37 | | - "@rules_go//go/toolchain:linux_amd64", |
38 | | - "@rules_go//go/toolchain:linux_arm64", |
| 35 | + "//tools/platforms:linux_amd64", |
| 36 | + "//tools/platforms:linux_amd64_v3", |
| 37 | + "//tools/platforms:linux_arm64", |
39 | 38 | ], |
40 | 39 | visibility = ["//visibility:public"], |
41 | | - target_compatible_with = select({ |
42 | | - Label("@platforms//os:windows"): [Label("@platforms//:incompatible")], |
43 | | - "//conditions:default": [], |
44 | | - }), |
45 | 40 | ) |
46 | 41 |
|
47 | 42 | def container_push_official(name, image, component): |
48 | | - oci_push( |
| 43 | + image_push( |
49 | 44 | name = name, |
50 | 45 | image = image, |
51 | | - repository = "ghcr.io/buildbarn/" + component, |
52 | | - remote_tags = "@com_github_buildbarn_bb_storage//tools:stamped_tags", |
53 | | - target_compatible_with = select({ |
54 | | - Label("@platforms//os:windows"): [Label("@platforms//:incompatible")], |
55 | | - "//conditions:default": [], |
56 | | - }), |
| 46 | + registry = "ghcr.io", |
| 47 | + repository = "buildbarn/" + component, |
| 48 | + tag_file = "@com_github_buildbarn_bb_storage//tools:stamped_tags", |
57 | 49 | ) |
0 commit comments