Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config file input #8

Merged
merged 6 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions minidock/container_assemble.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@com_github_bazeltools_rules_minidock//minidock:providers.bzl", "ContainerInfo", "ManifestResult", "AssembledData", "container_info_struct")
load("@com_github_bazeltools_rules_minidock//minidock:providers.bzl", "ContainerInfo", "ManifestResult", "AssembledData", "ExternalContainerConfig", "container_info_struct")


launcher_template = """
Expand Down Expand Up @@ -31,6 +31,7 @@ def __container_assemble_impl(ctx):

composed = ctx.attr.composed[ContainerInfo]
composed_transitive_deps = composed.dependencies
composed_external_config = ctx.attr.composed[ExternalContainerConfig]

merger_config_output = ctx.actions.declare_file("%s_merger_config.json" % ctx.attr.name)
merger_manifest_output = ctx.actions.declare_file("%s_merger_manifest.json" % ctx.attr.name)
Expand All @@ -47,7 +48,13 @@ def __container_assemble_impl(ctx):
merger_args.add("--upload-metadata-path").add(merger_upload_metadata_output.path)
merger_args.add("--config-path").add(merger_config_output.path)

merger_input = depset([merger_config_file], transitive = [composed_transitive_deps])
transdepsets = [composed_transitive_deps]
for target in composed_external_config.config:
external_config_files = target.files
transdepsets.append(external_config_files)
merger_args.add("--external-config-path").add_all(external_config_files)

merger_input = depset([merger_config_file], transitive = transdepsets)
ctx.actions.run(
inputs = merger_input,
outputs = [merger_config_output, merger_manifest_output, merger_upload_metadata_output, merger_manifest_sha256_output],
Expand Down
8 changes: 7 additions & 1 deletion minidock/container_compose.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@com_github_bazeltools_rules_minidock//minidock:providers.bzl", "ContainerInfo")
load("@com_github_bazeltools_rules_minidock//minidock:providers.bzl", "ContainerInfo", "ExternalContainerConfig")


def __copy_provider_with(current, parent):
Expand Down Expand Up @@ -41,6 +41,7 @@ def __container_compose_impl(
base_info = ctx.attr.base[ContainerInfo] if ctx.attr.base != None else None
return [
__align_parents(base_info, layers),
ExternalContainerConfig(config = ctx.attr.external_config)
]

container_compose = rule(
Expand All @@ -53,6 +54,11 @@ container_compose = rule(
"layers": attr.label_list(
providers = [ContainerInfo],
),
"external_config": attr.label_list(
doc = "External config file to be merged with this composition",
mandatory = False,
allow_files = True
)
},
implementation = __container_compose_impl,
)
6 changes: 3 additions & 3 deletions minidock/container_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __container_config__impl(ctx):
Env = __expand_env(ctx, ctx.attr.env),
User = user,
WorkingDir = workdir,
Labels = ctx.attr.labels
Labels = ctx.attr.labels,
),
)

Expand Down Expand Up @@ -89,9 +89,9 @@ container_config = rule(
default = "rules_minidock_is_unset",
),
"labels": attr.string_dict(
doc = """Config labels. Will merge with parent labels: does *not replace all labels in parent dict.""",
doc = """Config labels. Will take precedence over any labels in labels_file""",
mandatory = False,
)
)
},
implementation = __container_config__impl,
)
6 changes: 6 additions & 0 deletions minidock/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ ContainerInfo = provider(fields = [
"config",
])

ExternalContainerConfig = provider(fields = [
# A target to an external config file that we can merge with
# all other config layers
"config"
])

def container_info_struct(container_info):
# Building a struct of both our rule-provided info and the parent info
# to pass to the merger app
Expand Down
30 changes: 15 additions & 15 deletions minidock/remote_tools/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,63 @@ def load_tools():
if "rules_minidock__merge_app_linux_x86_64" not in excludes:
load_tool(
name = "rules_minidock__merge_app_linux_x86_64",
sha256 = "9ae88eb012f6ddcdeef87e1bf0d2d050fac78e9007c78b3433d0ec44f0f20c4a",
sha256 = "a2f11bb0e135271a1d41a8812a2532e0ea8868d40ac89d00ac4e58b953b11e52",
packaged = False,
binary_path = "merge-app-linux-x86_64",
urls = ["https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.56/merge-app-linux-x86_64"],
urls = ["https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.61/merge-app-linux-x86_64"],
)

if "rules_minidock__merge_app_macos_x86_64" not in excludes:
load_tool(
name = "rules_minidock__merge_app_macos_x86_64",
sha256 = "2ebb3e2d31686399b61c188d3519ad7cb762fcbcb42f6037e65cfa10f1e55578",
sha256 = "1591fc03b647b6d399e26250dd30115463a44215a1e343a067b0c75f8404287b",
packaged = False,
binary_path = "merge-app-macos-x86_64",
urls = ["https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.56/merge-app-macos-x86_64"],
urls = ["https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.61/merge-app-macos-x86_64"],
)

if "rules_minidock__merge_app_macos_aarch64" not in excludes:
load_tool(
name = "rules_minidock__merge_app_macos_aarch64",
sha256 = "cf4ac984193348aa927ef567e18987e9fdceca04097d9386364b2537f20aa0bc",
sha256 = "4f3aa6d5984b138cd7af5811c346d53351d3ca02e8364d9072378965efb6240e",
packaged = False,
binary_path = "merge-app-macos-aarch64",
urls = ["https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.56/merge-app-macos-aarch64"],
urls = ["https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.61/merge-app-macos-aarch64"],
)

if "rules_minidock__pusher_app_linux_x86_64" not in excludes:
load_tool(
name = "rules_minidock__pusher_app_linux_x86_64",
sha256 = "5406a376c263cf135ab1a7b7821eee935cb7d8d9374ebf45beb6dee39bc4cb7c",
sha256 = "1c83cb1c84239cbaddf58bac1b43ae83546c8cf5ec51a3a9aae9e4e3bcd3b538",
packaged = False,
binary_path = "pusher-app-linux-x86_64",
urls = ["https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.56/pusher-app-linux-x86_64"],
urls = ["https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.61/pusher-app-linux-x86_64"],
)

if "rules_minidock__pusher_app_macos_x86_64" not in excludes:
load_tool(
name = "rules_minidock__pusher_app_macos_x86_64",
sha256 = "f109170cf9b486b8abbc8c1d581973d1c65ae5eb47ccaef2732f2d87f78be4b2",
sha256 = "d83b047bcbb47238a02897350f4f3ee24020f30cf70b0db7c226922d36d00b18",
packaged = False,
binary_path = "pusher-app-macos-x86_64",
urls = ["https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.56/pusher-app-macos-x86_64"],
urls = ["https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.61/pusher-app-macos-x86_64"],
)

if "rules_minidock__pusher_app_macos_aarch64" not in excludes:
load_tool(
name = "rules_minidock__pusher_app_macos_aarch64",
sha256 = "077b894ae88997010bc228cf0d6a86388ccb1772f3edfda9062c8071b1d0b6c4",
sha256 = "33298b9299acba15e90667b806305a52de6146614124c790ef7def9305ff5c5c",
packaged = False,
binary_path = "pusher-app-macos-aarch64",
urls = ["https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.56/pusher-app-macos-aarch64"],
urls = ["https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.61/pusher-app-macos-aarch64"],
)
if "rules_minidock__puller_app" not in excludes:
repo_rule_load_tool(
name="rules_minidock__puller_app",
platform_to_sha_pairs = {
"linux__x86_64": ["c9b1c867a481f40c3078fef4eacc27f11150cf383feb6b038a1f2bd832ab5f6a", "https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.56/puller-app-linux-x86_64"],
"macos__x86_64": ["09b6ae3d3b9375de67784d2fe127bdcaf4f4af10b3ee7258bc01f8d5cb462a55", "https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.56/puller-app-macos-x86_64"],
"macos__aarch64": ["d65f6d8c556bc5840aac7b2fb8152d2cc6a3ae28381cc3309cff671684bd63f4", "https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.56/puller-app-macos-aarch64"],
"linux__x86_64": ["a6d338d9df9b9c087421152387cc5be19431f6dcff5b4d476ab2aace762bb067", "https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.61/puller-app-linux-x86_64"],
"macos__x86_64": ["bd52783111fe6c22647d2b5dddb680e7f46d08338dc96867fcceee54864131cb", "https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.61/puller-app-macos-x86_64"],
"macos__aarch64": ["5cc25b21a749d5384b6c374b4f9a02ce26cee2ea8aa349f948e5d4ff645b47cd", "https://github.com/bazeltools/rules_minidock_tools/releases/download/v0.0.61/puller-app-macos-aarch64"],
}
)
# RUST_BINARIES_AUTO_GEN_REPLACE_SECTION_END
10 changes: 9 additions & 1 deletion scripts/ci_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@
env = data["config"]["Env"]

expected_cmd = ["/usr/bin/my_app"]
expected_labels = {"label1": "foo", "label2": "bar"}
expected_labels = {
"label1": "foo",
"label2": "bar",
"external-config-label-1": "extlabel1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This verifies that our external configs are getting merged properly

"external-config-label-2": "extlabel2",
"external-config-label-3": "extlabel3",
"external-config-label-4": "extlabel4"
}
expected_user = "nfbasic"

assert(cmd == expected_cmd)
Expand All @@ -31,6 +38,7 @@
assert(len(env) > 2)
assert("ENV1=FOO" in env)
assert("ENV2=BAR" in env)
assert("EXTERNALENV1=extenv1" in env)

subprocess.run(["bazel", "clean", "--expunge"], check=True)
subprocess.run(["bazel", "build", "..."], check=True)
Expand Down
36 changes: 35 additions & 1 deletion tests/simple_flow/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,39 @@ load(
"@com_github_bazeltools_rules_minidock//minidock:container_config.bzl",
"container_config",
)
genrule(
name = "external_config_file",
outs = ["ConfigFile.json"],
cmd = """
cat << EOF > $@
{
"Env": [
"EXTERNALENV1=extenv1"
],
"Labels": {
"label1": "this-will-get-overwritten-by-the-config-below",
"external-config-label-1": "extlabel1",
"external-config-label-2": "extlabel2"
}
}
EOF""",
stamp = 1,
)

genrule(
name = "external_config_file_2",
outs = ["ConfigFile2.json"],
cmd = """
cat << EOF > $@
{
"Labels": {
"external-config-label-3": "extlabel3",
"external-config-label-4": "extlabel4"
}
}
EOF""",
stamp = 1,
)

container_data(
name = "file_a_data",
Expand Down Expand Up @@ -53,8 +86,9 @@ container_compose(
":file_a_data",
":file_b_data",
":user_and_app",
":labels_and_env"
":labels_and_env",
],
external_config = [":external_config_file", ":external_config_file_2"]
)

container_assemble(
Expand Down