Skip to content

Commit e0b56e0

Browse files
authored
Add Support for linux arm64 images (#1074)
1 parent 7bdc998 commit e0b56e0

File tree

10 files changed

+206
-91
lines changed

10 files changed

+206
-91
lines changed

BUILD.bazel

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# gazelle:proto disable_global
33
# gazelle:exclude docs/generated/reference/generate/json_swagger
44

5-
load("@io_bazel_rules_docker//container:container.bzl", "container_push")
5+
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
6+
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
67

78
# export WORKSPACE so workspace_binary rules can be used outside the root
89
exports_files([
@@ -14,16 +15,23 @@ exports_files([
1415

1516
# TODO
1617
load("@bazel_gazelle//:def.bzl", "gazelle")
18+
load("@rules_oci//oci:defs.bzl", "oci_push")
1719

1820
gazelle(name = "gazelle")
1921

20-
container_push(
22+
expand_template(
23+
name = "tags",
24+
stamp_substitutions = {
25+
"APP_VERSION": "{{STABLE_DOCKER_TAG}}",
26+
},
27+
template = ["APP_VERSION"],
28+
)
29+
30+
oci_push(
2131
name = "push_operator_image",
22-
format = "Docker",
23-
image = "//cmd/cockroach-operator:operator_image",
24-
registry = "{STABLE_DOCKER_REGISTRY}",
25-
repository = "{STABLE_IMAGE_REPOSITORY}",
26-
tag = "{STABLE_DOCKER_TAG}",
32+
image = "//cmd/cockroach-operator:index",
33+
remote_tags = ":tags",
34+
repository = "${DOCKER_REGISTRY}/${DOCKER_IMAGE_REPOSITORY}",
2735
)
2836

2937
filegroup(

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ release/image:
330330
DOCKER_REGISTRY=$(DOCKER_REGISTRY) \
331331
DOCKER_IMAGE_REPOSITORY=$(DOCKER_IMAGE_REPOSITORY) \
332332
APP_VERSION=$(APP_VERSION) \
333-
bazel run --stamp --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 \
333+
bazel run --stamp \
334334
//:push_operator_image
335335

336336
#

WORKSPACE

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,40 +64,53 @@ gazelle_dependencies()
6464
# gazelle:repository_macro hack/build/repos.bzl%_go_dependencies
6565
go_dependencies()
6666

67-
######################################
68-
# Load rules_docker and dependencies #
69-
######################################
67+
################################
68+
# begin rules_oci dependencies #
69+
################################
7070
http_archive(
71-
name = "io_bazel_rules_docker",
72-
sha256 = "92779d3445e7bdc79b961030b996cb0c91820ade7ffa7edca69273f404b085d5",
73-
strip_prefix = "rules_docker-0.20.0",
74-
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.20.0/rules_docker-v0.20.0.tar.gz"],
71+
name = "aspect_bazel_lib",
72+
sha256 = "d0529773764ac61184eb3ad3c687fb835df5bee01afedf07f0cf1a45515c96bc",
73+
strip_prefix = "bazel-lib-1.42.3",
74+
url = "https://storage.googleapis.com/public-bazel-artifacts/bazel/bazel-lib-v1.42.3.tar.gz",
7575
)
7676

77-
load(
78-
"@io_bazel_rules_docker//repositories:repositories.bzl",
79-
container_repositories = "repositories",
77+
http_archive(
78+
name = "rules_oci",
79+
sha256 = "21a7d14f6ddfcb8ca7c5fc9ffa667c937ce4622c7d2b3e17aea1ffbc90c96bed",
80+
strip_prefix = "rules_oci-1.4.0",
81+
url = "https://storage.googleapis.com/public-bazel-artifacts/bazel/rules_oci-v1.4.0.tar.gz",
8082
)
8183

82-
container_repositories()
84+
load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies")
85+
load("@rules_oci//oci:pull.bzl", "oci_pull")
8386

84-
load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")
87+
rules_oci_dependencies()
8588

86-
container_deps()
89+
# TODO: This will pull from an upstream location: specifically it will download
90+
# `crane` from https://github.com/google/go-containerregistry/... Before this is
91+
# used in CI or anything production-ready, this should be mirrored. rules_oci
92+
# doesn't support this mirroring yet so we'd have to submit a patch.
93+
load("@rules_oci//oci:repositories.bzl", "LATEST_CRANE_VERSION", "oci_register_toolchains")
8794

88-
load(
89-
"@io_bazel_rules_docker//container:container.bzl",
90-
"container_pull",
91-
)
92-
load(
93-
"@io_bazel_rules_docker//go:image.bzl",
94-
_go_image_repos = "repositories",
95+
oci_register_toolchains(
96+
name = "oci",
97+
crane_version = LATEST_CRANE_VERSION,
9598
)
9699

97-
_go_image_repos()
100+
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")
98101

99-
container_pull(
102+
aspect_bazel_lib_dependencies()
103+
104+
##############################
105+
# end rules_oci dependencies #
106+
##############################
107+
108+
oci_pull(
100109
name = "redhat_ubi_minimal",
110+
platforms = [
111+
"linux/amd64",
112+
"linux/arm64",
113+
],
101114
registry = "registry.access.redhat.com",
102115
repository = "ubi8/ubi-minimal",
103116
tag = "latest",

cmd/cockroach-operator/BUILD.bazel

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
load("@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")
43
load("@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

724
go_library(
825
name = "go_default_library",
@@ -31,8 +48,20 @@ go_library(
3148
)
3249

3350
go_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

87108
pkg_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

117127
filegroup(
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
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
load("@rules_pkg//:pkg.bzl", "pkg_tar")
2+
3+
genrule(
4+
name = "fetch_linux_amd64_crdb_container",
5+
srcs = ["@crdb_linux_amd64//:file"],
6+
outs = ["cockroach"],
7+
cmd = "cp $(SRCS) $@",
8+
visibility = ["//visibility:public"],
9+
)
10+
11+
pkg_tar(
12+
name = "cockroach-linux-amd64-tar",
13+
srcs = [":fetch_linux_amd64_crdb_container"],
14+
mode = "0755",
15+
package_dir = "/usr/local/bin",
16+
visibility = ["//visibility:public"],
17+
)
18+
19+
filegroup(
20+
name = "package-srcs",
21+
srcs = glob(["**"]),
22+
tags = ["automanaged"],
23+
visibility = ["//visibility:private"],
24+
)
25+
26+
filegroup(
27+
name = "all-srcs",
28+
srcs = [":package-srcs"],
29+
tags = ["automanaged"],
30+
visibility = ["//visibility:public"],
31+
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
load("@rules_pkg//:pkg.bzl", "pkg_tar")
2+
3+
genrule(
4+
name = "fetch_linux_arm64_crdb_container",
5+
srcs = ["@crdb_linux_arm64//:file"],
6+
outs = ["cockroach"],
7+
cmd = "cp $(SRCS) $@",
8+
visibility = ["//visibility:public"],
9+
)
10+
11+
pkg_tar(
12+
name = "cockroach-linux-arm64-tar",
13+
srcs = [":fetch_linux_arm64_crdb_container"],
14+
mode = "0755",
15+
package_dir = "/usr/local/bin",
16+
visibility = ["//visibility:public"],
17+
)
18+
19+
filegroup(
20+
name = "package-srcs",
21+
srcs = glob(["**"]),
22+
tags = ["automanaged"],
23+
visibility = ["//visibility:private"],
24+
)
25+
26+
filegroup(
27+
name = "all-srcs",
28+
srcs = [":package-srcs"],
29+
tags = ["automanaged"],
30+
visibility = ["//visibility:public"],
31+
)

config/manager/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ spec:
3333
- name: cockroach-operator
3434
image: cockroachdb/cockroach-operator:latest
3535
imagePullPolicy: IfNotPresent
36+
command:
37+
- ./cockroach-operator
3638
args:
3739
- -zap-log-level
3840
- info

hack/bin/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ genrule(
233233
srcs = select({
234234
":m1": ["@crdb_darwin//:file"],
235235
":darwin": ["@crdb_darwin//:file"],
236-
":k8": ["@crdb_linux//:file"],
236+
":k8": ["@crdb_linux_amd64//:file"],
237237
}),
238238
outs = ["cockroach"],
239239
cmd = "cp $(SRCS) $@",

0 commit comments

Comments
 (0)