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

Config file input #8

merged 6 commits into from
Oct 18, 2023

Conversation

wrobstory
Copy link
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
Contributor Author

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

@@ -53,6 +54,10 @@ container_compose = rule(
"layers": attr.label_list(
providers = [ContainerInfo],
),
"external_config": attr.label(
Copy link
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
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.

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

@wrobstory
Copy link
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
Copy link
Contributor

@johnynek johnynek left a comment

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.

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

Copy link
Contributor

@johnynek johnynek left a comment

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
1 check passed
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.

2 participants