1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
"""
Macros for cmd.
"""
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index", "oci_push")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
_x_defs = {
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd.Version": "{STABLE_BUILD_GIT_TAG}",
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd.Commit": "{STABLE_BUILD_GIT_COMMIT}",
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd.BuildTime": "{BUILD_TIME}",
}
# This can be overridden using command line flags. See https://docs.aspect.build/rules/rules_oci/docs/push.
_agentk_repo = "registry.gitlab.com/gitlab-org/cluster-integration/gitlab-agent"
def define_command_targets(name, binary_embed, arm_targets = True, arm64_targets = True):
go_binary(
name = name,
embed = binary_embed,
visibility = ["//visibility:public"],
x_defs = _x_defs,
)
go_binary(
name = "%s_race" % name,
embed = binary_embed,
race = "on",
tags = ["manual"],
visibility = ["//visibility:public"],
x_defs = _x_defs,
)
images = []
debug_images = []
images.append(binary_and_image(
name = name,
arch = "amd64",
debug = False,
race = "off",
binary_embed = binary_embed,
))
debug_images.append(binary_and_image(
name = name,
arch = "amd64",
debug = True,
race = "on",
binary_embed = binary_embed,
))
if arm_targets:
images.append(binary_and_image(
name = name,
arch = "arm",
debug = False,
race = "off",
binary_embed = binary_embed,
))
debug_images.append(binary_and_image(
name = name,
arch = "arm",
debug = True,
race = "off",
binary_embed = binary_embed,
))
if arm64_targets:
images.append(binary_and_image(
name = name,
arch = "arm64",
debug = False,
race = "off",
binary_embed = binary_embed,
))
debug_images.append(binary_and_image(
name = name,
arch = "arm64",
debug = True,
race = "off",
binary_embed = binary_embed,
))
oci_image_index(
name = "%s_index" % name,
images = images,
visibility = ["//visibility:public"],
tags = ["manual"],
)
oci_image_index(
name = "%s_index_debug" % name,
images = debug_images,
visibility = ["//visibility:public"],
tags = ["manual"],
)
oci_push(
name = "push",
image = ":%s_index" % name,
repository = _agentk_repo,
tags = ["manual"],
)
oci_push(
name = "push_debug",
image = ":%s_index_debug" % name,
repository = _agentk_repo,
tags = ["manual"],
)
def binary_and_image(name, arch, debug, race, binary_embed):
if debug:
binary_name = "%s_linux_%s_debug" % (name, arch)
base = "@distroless_base_debug_nonroot_linux_%s" % arch
else:
binary_name = "%s_linux_%s" % (name, arch)
base = "@distroless_static_nonroot_linux_%s" % arch
go_binary(
name = binary_name,
embed = binary_embed,
goarch = arch,
goos = "linux",
race = race,
tags = ["manual"],
visibility = ["//visibility:public"],
x_defs = _x_defs,
)
tar_name = "%s_tar" % binary_name
pkg_tar(
name = tar_name,
srcs = [":" + binary_name],
tags = ["manual"],
)
oci_image_name = "%s_image" % binary_name
oci_image(
name = oci_image_name,
base = base,
tars = [":" + tar_name],
tags = ["manual"],
visibility = ["//visibility:public"],
entrypoint = ["/" + binary_name],
)
return ":" + oci_image_name
|