8000 Config file input by wrobstory · Pull Request #8 · bazeltools/rules_minidock · GitHub
[go: up one dir, main page]

Skip to content

Config file input - #8

Merged
wrobstory merged 6 commits into
mainfrom
story-file-input
Oct 18, 2023
Merged

wrobstory merged 6 commits into
mainfrom
story-file-input

Conversation

@wrobstory
Copy link
Copy Markdown
Contributor

We'd like to do be able to capture things from the environment/at runtime and have them merged in to the metadata of our docker container. One way we can do this is what you see in the BUILD.bazel file change below: we could have our external_config_file grab the git commit, git branch, etc and then have that merged in (I will probably update this PR to do just that, but for now its a static file).

We will then pass that to the merger app, which will merge it alongside the various config that we layer into the composition.

I was quite torn on exactly where to specify this, but container_compose felt like the right place for now.

This will be WIP until I can merge the accompanying PR in rules_minidock_tools, which I will link in a moment.

@wrobstory
Copy link
Copy Markdown
Contributor Author

Here's the tools PR: bazeltools/rules_minidock_tools#278

Comment thread minidock/container_compose.bzl Outdated
"layers": attr.label_list(
providers = [ContainerInfo],
),
"external_config": attr.label(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we not want a label list here since we can already merge?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I honestly hadnt considered having more than one file, but we certainly can.

Comment thread scripts/ci_test.py
expected_labels = {
"label1": "foo",
"label2": "bar",
"external-config-label-1": "extlabel1",
Copy link
Copy Markdown
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

@wrobstory
wrobstory requested a review from johnynek October 18, 2023 19:57
@wrobstory
Copy link
Copy Markdown
Contributor Author

@johnynek alrighty: this is ready to go, it can take the genrule files and merge them properly.

@wrobstory wrobstory changed the title WIP: Config file input Config file input Oct 18, 2023
@johnynek johnynek left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minor rewrite to avoid depset to_list which bazel recommends avoiding as long as possible.

Comment thread minidock/container_assemble.bzl Outdated
inputs = [merger_config_file]
for target in composed_external_config.config:
external_config_files = target.files.to_list()
inputs = inputs + external_config_files
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you don't need to linearize here. add_all accepts depsets: https://bazel.build/rules/lib/builtins/Args#add_all

so instead:

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh intersting, i didnt know depset had an append, updating

@wrobstory
wrobstory requested a review from johnynek October 18, 2023 20:47
@johnynek johnynek left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚢

@wrobstory
wrobstory merged commit b7b51cd into main Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0