11load ("@io_bazel_rules_go//go:def.bzl" , "go_binary" , "go_library" )
2- load ("@io_bazel_rules_docker//container:container.bzl" , "container_image" )
3- load ("@io_bazel_rules_docker//go:image.bzl" , "go_image" )
2+ load ("@rules_oci//oci:defs.bzl" , "oci_image" , "oci_image_index" )
43load ("@rules_pkg//:pkg.bzl" , "pkg_tar" )
5- load ("@io_bazel_rules_docker//docker/util:run.bzl" , "container_run_and_commit_layer" )
4+ load ("@aspect_bazel_lib//lib:expand_template.bzl" , "expand_template" )
5+
6+ expand_template (
7+ name = "labels" ,
8+ out = "labels.txt" ,
9+ stamp_substitutions = {
10+ "APP_VERSION" : "{{STABLE_DOCKER_TAG}}" ,
11+ "NUMBER_COMMITS_ON_BRANCH" : "{{NUMBER_COMMITS_ON_BRANCH}}" ,
12+ },
13+ template = [
14+ "name=CockroachDB Operator" ,
15+ "vendor=Cockroach Labs" ,
16+ "release=NUMBER_COMMITS_ON_BRANCH" ,
17+ "version=APP_VERSION" ,
18+ "summary=CockroachDB is a distributed SQL database" ,
19+ "description=CockroachDB is a PostgreSQL wire-compatible distributed SQL database" ,
20+ "maintainer=Cockroach Labs" ,
21+ ],
22+ )
623
724go_library (
825 name = "go_default_library" ,
@@ -31,8 +48,20 @@ go_library(
3148)
3249
3350go_binary (
34- name = "cockroach-operator" ,
51+ name = "cockroach-operator-linux-amd64" ,
52+ out = "cockroach-operator" ,
3553 embed = [":go_default_library" ],
54+ goarch = "amd64" ,
55+ goos = "linux" ,
56+ visibility = ["//visibility:public" ],
57+ )
58+
59+ go_binary (
60+ name = "cockroach-operator-linux-arm64" ,
61+ out = "cockroach-operator" ,
62+ embed = [":go_default_library" ],
63+ goarch = "arm64" ,
64+ goos = "linux" ,
3665 visibility = ["//visibility:public" ],
3766)
3867
@@ -43,67 +72,48 @@ pkg_tar(
4372 package_dir = "/licenses" ,
4473)
4574
46- container_run_and_commit_layer (
47- name = "ubi_update" ,
48- commands = [
49- "microdnf install yum" ,
50- "yum -v -y update --all" ,
51- "microdnf clean all && rm -rf /var/cache/yum" ,
75+ oci_image_index (
76+ name = "index" ,
77+ images = [
78+ ":cockroach_image_linux_amd64" ,
79+ ":cockroach_image_linux_arm64" ,
5280 ],
53- image = "@redhat_ubi_minimal//image" ,
81+ visibility = [ "//visibility:public" ] ,
5482)
5583
56- container_image (
57- name = "ubi_base_image" ,
58- architecture = "amd64" ,
84+ oci_image (
85+ name = "cockroach_image_linux_amd64" ,
5986 # References container_pull from WORKSPACE
60- base = "@redhat_ubi_minimal//image" ,
61- labels = {
62- "name" : "CockroachDB Operator" ,
63- "vendor" : "Cockroach Labs" ,
64- "release" : "{NUMBER_COMMITS_ON_BRANCH}" ,
65- "version" : "{STABLE_DOCKER_TAG}" ,
66- "summary" : "CockroachDB is a distributed SQL database" ,
67- "description" : "CockroachDB is a PostgreSQL wire-compatible distributed SQL database" ,
68- },
69- layers = [
70- ":ubi_update" ,
71- ],
72- stamp = True ,
87+ base = "@redhat_ubi_minimal_linux_amd64" ,
88+ labels = ":labels" ,
7389 tars = [
7490 ":licenses" ,
91+ "//cmd/cockroach-operator/linux-amd64:cockroach-linux-amd64-tar" ,
92+ ":operator_image_linux_amd64" ,
7593 ],
7694)
7795
78- # fetch_crdb downloads the cockroach binary
79- genrule (
80- name = "fetch_crdb_container" ,
81- srcs = ["@crdb_linux//:file" ],
82- outs = ["cockroach" ],
83- cmd = "cp $(SRCS) $@" ,
84- visibility = ["//visibility:public" ],
96+ oci_image (
97+ name = "cockroach_image_linux_arm64" ,
98+ # References container_pull from WORKSPACE
99+ base = "@redhat_ubi_minimal_linux_arm64" ,
100+ labels = ":labels" ,
101+ tars = [
102+ ":licenses" ,
103+ "//cmd/cockroach-operator/linux-arm64:cockroach-linux-arm64-tar" ,
104+ ":operator_image_linux_arm64" ,
105+ ],
85106)
86107
87108pkg_tar (
88- name = "cockroach-tar" ,
89- srcs = [":fetch_crdb_container" ],
90- mode = "0755" ,
91- package_dir = "/usr/local/bin" ,
92- )
93-
94- # include cockroach in an image
95- container_image (
96- name = "cockroach_image" ,
97- base = ":ubi_base_image" ,
98- tars = [
99- ":cockroach-tar" ,
100- ],
109+ name = "operator_image_linux_amd64" ,
110+ srcs = [":cockroach-operator-linux-amd64" ],
111+ visibility = ["//visibility:public" ],
101112)
102113
103- go_image (
104- name = "operator_image" ,
105- base = ":cockroach_image" , # include the cr binary
106- binary = ":cockroach-operator" ,
114+ pkg_tar (
115+ name = "operator_image_linux_arm64" ,
116+ srcs = [":cockroach-operator-linux-arm64" ],
107117 visibility = ["//visibility:public" ],
108118)
109119
@@ -116,7 +126,11 @@ filegroup(
116126
117127filegroup (
118128 name = "all-srcs" ,
119- srcs = [":package-srcs" ],
129+ srcs = [
130+ ":package-srcs" ,
131+ "//cmd/cockroach-operator/linux-amd64:all-srcs" ,
132+ "//cmd/cockroach-operator/linux-arm64:all-srcs" ,
133+ ],
120134 tags = ["automanaged" ],
121135 visibility = ["//visibility:public" ],
122136)
0 commit comments