bazel: build both cli variants as part of devbuild

This commit is contained in:
Malte Poll 2023-05-30 09:05:36 +02:00 committed by Malte Poll
parent c62e54831b
commit 26bc653d0e
8 changed files with 77 additions and 5 deletions

View File

@ -29,6 +29,9 @@ test --//bazel/settings:tpm_simulator
# set registry flag alias
build --flag_alias=container_prefix=//bazel/settings:container_prefix
# set cli edition flag alias
build --flag_alias=cli_edition=//bazel/settings:cli_edition
# build only what is needed for tests
test --build_tests_only

View File

@ -1,21 +1,28 @@
load("//bazel/sh:def.bzl", "sh_template")
load(":def.bzl", "cli_edition")
sh_template(
name = "devbuild",
data = [
":devbuild_cli_edition",
"//bazel/release:container_sums",
"//bootstrapper/cmd/bootstrapper:bootstrapper_linux_amd64",
"//cli:cli_oss_host",
"//cli:cli_edition_host",
"//debugd/cmd/cdbg:cdbg_host",
"//upgrade-agent/cmd:upgrade_agent_linux_amd64",
],
substitutions = {
"@@BOOTSTRAPPER@@": "$(rootpath //bootstrapper/cmd/bootstrapper:bootstrapper_linux_amd64)",
"@@CDBG@@": "$(rootpath //debugd/cmd/cdbg:cdbg_host)",
"@@CLI@@": "$(rootpath //cli:cli_oss_host)",
"@@CLI@@": "$(rootpath //cli:cli_edition_host)",
"@@CONTAINER_SUMS@@": "$(rootpath //bazel/release:container_sums)",
"@@EDITION@@": "$(rootpath :devbuild_cli_edition)",
"@@UPGRADE_AGENT@@": "$(rootpath //upgrade-agent/cmd:upgrade_agent_linux_amd64)",
},
template = "prepare_developer_workspace.sh.in",
visibility = ["//visibility:public"],
)
cli_edition(
name = "devbuild_cli_edition",
)

21
bazel/devbuild/def.bzl Normal file
View File

@ -0,0 +1,21 @@
"""Bazel rules for devbuild"""
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
def _cli_edition_impl(ctx):
cli_edition = ctx.attr._cli_edition[BuildSettingInfo].value
if cli_edition == None or cli_edition == "":
fail("--cli_edition is not set in .bazeloverwriterc")
if cli_edition not in ["oss", "enterprise"]:
fail("--cli_edition must be 'oss' or 'enterprise' in .bazeloverwriterc")
output = ctx.actions.declare_file(ctx.label.name + ".txt")
ctx.actions.write(output = output, content = cli_edition)
return [DefaultInfo(files = depset([output]))]
cli_edition = rule(
implementation = _cli_edition_impl,
attrs = {
"_cli_edition": attr.label(default = Label("//bazel/settings:cli_edition")),
},
)

View File

@ -24,6 +24,7 @@ cdbg=$(realpath @@CDBG@@)
stat "${cdbg}" >> /dev/null
container_sums=$(realpath @@CONTAINER_SUMS@@)
stat "${container_sums}" >> /dev/null
edition=$(cat @@EDITION@@)
cd "${BUILD_WORKING_DIRECTORY}"
@ -51,8 +52,10 @@ else
workdir="$1"
fi
echo "Using ${edition} cli edition"
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${bootstrapper}")" "${workdir}/bootstrapper"
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${upgrade_agent}")" "${workdir}/upgrade-agent"
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${cli}")" "${workdir}/constellation"
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${cdbg}")" "${workdir}/cdbg"
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${container_sums}")" "${workdir}/container_sums.sha256"
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${cli}")" "${workdir}/constellation"

View File

@ -80,8 +80,8 @@ multirun(
multirun(
name = "build_and_push",
commands = [
"//bazel/devbuild:devbuild",
"//bazel/release:push",
"//bazel/devbuild:devbuild",
],
visibility = ["//visibility:public"],
)

View File

@ -41,6 +41,31 @@ string_flag(
visibility = ["//visibility:public"],
)
string_flag(
name = "cli_edition",
build_setting_default = "",
values = [
"",
"enterprise",
"oss",
],
visibility = ["//visibility:public"],
)
config_setting(
name = "cli_edition_enterprise",
flag_values = {
":cli_edition": "enterprise",
},
)
config_setting(
name = "cli_edition_oss",
flag_values = {
":cli_edition": "oss",
},
)
bool_flag(
name = "select_never",
build_setting_default = False,

View File

@ -57,3 +57,15 @@ go_binary(
"enterprise",
]
]
alias(
name = "cli_edition_host",
actual = select(
{
"//bazel/settings:cli_edition_enterprise": ":cli_enterprise_host",
"//bazel/settings:cli_edition_oss": ":cli_oss_host",
"//conditions:default": ":cli_oss_host",
},
),
visibility = ["//visibility:public"],
)

View File

@ -46,13 +46,14 @@ cd build
# and symlink them into the current directory
# also push the built container images
# After the first run, set the pushed imaged to public.
bazel run //:devbuild --container_prefix=ghcr.io/USERNAME/constellation
bazel run //:devbuild --cli_edition=oss --container_prefix=ghcr.io/USERNAME/constellation
./constellation ...
```
Overwrite the default container_prefix in the `.bazeloverwriterc` in the root of the workspace:
```bazel
# cat .bazeloverwriterc
build --cli_edition=oss
build --container_prefix=ghcr.io/USERNAME/constellation
```