-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Use environment variables in .bazelrc via string interpolation #10904
Comments
The official docs provide a workaround for this use case via |
This workaround isn't exactly covering the use-case (I have a similar need). Using a (Unless I'm missing some mechanism to combine data from different lines of the rcfiles.) |
@psigen Here was my workaround: I needed this feature specifically for a CircleCI setup (where I set environment variables in "Project Settings"), so what worked for me was creating a script #!/bin/bash
# Exit on error
set -e
echo "# Generated by generate_bazelrc.sh" > .bazelrc
echo "build --remote_cache=https://$BAZEL_CACHE_USER:$BAZEL_CACHE_PASSWORD@mybazelcache.example.com" >> .bazelrc and then running |
Thanks. My workaround is also running a script. But I'm using this for local development, so it's not as easy to make sure it's sourced when the environment is set up. |
I too would be interested in this. Specifically, I would like to set |
Is there any technical reason for not allowing env variables in the bazelrc files? |
+1 for this change, it would be cleaner than having to use some wrapper to basically to do the same thing via try-import |
The reason for not allowing it is that it is going to add complexity for little real gain. |
@aiuto For us this feature is rather important. Especially in our complex environment when we have several workspaces and several repositories. This feature will also simplify environment for many users as they no longer have to maintain a wrapper around bazel in order to achieve same functionality. Complexity of the proposed implementation we can discuss in the commit review. Implementation in #13266 is backwards compatible so it should be no negative impact on existing users. |
"Though a program be but three lines long, someday it will have to be maintained." I agree with @aiuto here; this looks like something that's easy to achieve with a wrapper script and thus provides little gain for the additional implementation complexity. Looking at #13266 , a number of issues come to mind:
All of these, are of course, fixable, but I see no reason to take on the job of maintaining this functionality. |
Perhaps I can walk through some of the issues I have had with using a wrapper script in these cases, to demonstrate a bit about why this is not something that's particularly easy to emulate with a wrapper script. There are a few primary use cases that I have for this functionality (others may have additional):
The "wrapper" approaches we can use to address these fall into two basic categories: Create a wrapper to generate a .bazelrc fileThis is the approach detailed in #10904 (comment) . We can run a pre-build step to manually generate some files in the bazel workspace root.
Create a wrapper around the bazel executable itselfAnother alternative to this is to create a wrapper that replaces the
I've spent about 20 hours so far wrapping, documenting, and debugging the various levels of wrapper described above, and in addition to the folks above in the thread there have been a few recent posts on the bazel Slack related to working around the same issues. I would be much happier directing that effort towards helping get this feature instead. I do agree that it needs a bit more formalization than the linked PR. |
@lberki Thank you for your feedback.
Could you also elaborate more on your point about "leak of environment variables"? Currently it's completely fine to write "bazel test --test_arg=${SSH_AUTH_KEY}" on the command line. What is the difference between this and moving this into bazelrc as you stated? I don't think that I understand what your mean. |
@lberki Ping! Any thoughts on the discussion/comments above? |
For me the big one is that several of our scripts call bazel several times and I want to pass --profile=/some/dir/XXX and get different files written to same dir. If I could get something to distinguish different runs without adding to all the different scripts that call bazel, it would help. |
I'm still not convinced that a wrapper to add to .bazelrc is an unreasonable workaround, especially in the context of a CI system. You always need a wrapper in the CI, if only to be a 3 line shell script that does |
@aiuto That's not necessarily true especially in light of @psigen's comment above outlining this disparate workspace setup. The crux of this issue is an argument of where the complexity of handling shell variables should live. Your argument is that the complexity for end-users to create a wrapper around bazel is trivial and therefore makes sense that this should not live in bazel core because the complexity it adds to the logic for parsing However I think there are several cases here which point to the contrary that creating & maintaining a bazel wrapper is more complex than it looks on the surface. Solving this problem in a scoped manner within bazel core is ideal because it's a clear win for the open-closed principle & helps minimize complexity across the bazel ecosystem at the cost of a relatively small maintenance burden (which can be reduced with sufficient test coverage). An alternative here might be to allow bazel to support some sort of preprocessor script for the |
The reason why this feels strange is that you want to put a shell variable parser in Bazel even though there is a perfectly good system made for parsing shell variables around Bazel: the shell itself. I think re-writing @psigen seems to agree that Bazelisk is a viable alternative for interactive builds. For CI, I don't think it's necessary: you presumably have to specify a binary to run on CI (as opposed to just |
Hi all, I just wanted to highlight this from my previous post:
The crux of the issue is the tremendous amount of re-writing involved because using a shell-script means that the existing mechanisms of composition (i.e. I don't want to do this. 😭 I don't like each team I am working with (at different companies) have their own almost-the-same-but-not-the-same mechanism for getting environment secrets into their bazel builds. I don't like debugging the same typos and edge cases in each environment. I don't like having to write documentation for how to use the script wrapper. I think the usage of environment variable interpolation for passing data is a relatively common use case, as I detailed in my previous post. If we look at similar systems (even relatively "hermetic" ones) we can see this particular escape hatch showing up for the same reasons:
|
I prefer for bazel to continue supporting / developing generally applicable hooks like I know we could have both, but given maintenance capacity on the project is finite, I can understand prioritising features and code that have higher power / effort ratio. For what it's worth I find myself using |
If the limiting factor is contributor bandwidth, does this mean that folks would be generally amenable to a feature PR adding the functionality? |
I can't speak for the core bazel team, but note that in general the initial PR adding a feature is just a small part of the capacity the addition of a feature requires to be properly implemented and maintained: ongoing maintenance of it and the added complexity on the parts of the code that interact with it are a bigger part of it. |
Exactly. Anyone can write a PR to add a feature and then go away. The Bazel team is then on hook to maintain it forever. |
Just as another data point: this feature would simplify quite few things for my team. I do understand and respect the perspective of the maintainers, however. Thanks all. |
I just want to give an update on this. One of our engineers has recently started evaluating all the issues related to .bazelrc and flag parsing to come up with a unified plan to address them. That will include:
Our criteria for deciding overall behavior will include:
I expect this effort will make some people happy that their favorite issue gets resolved while disappointing others, because it appears that there are issues filed asking for conflicting things. That's why a requirements doc tied to use case is an important part of this effort. It allows us to better evaluate current and future issues to determine priority and feasibility. Most of this to be done in Q1 2022, so stay tuned for updates early next year. |
any update? |
also |
@aiuto was this document created or shared with the community at any point? |
Whoops.... Yes. We built an extensive use case and requirements doc. But AFAIK, we forgot to share it out. @aranguyen If you have not done so, can you copy "Bazel Flag and rc File Possible Improvements" to a doc in bazel.build and share it with comment access to the world? |
Hello all, sorry for the delay, I was OOO for some time. Here is the link to the document https://docs.google.com/document/d/1l1qllOBSjj295pui_krJe-LQs2AICZmhZSROuruLsFU/edit?usp=sharing (Section Requested User Use Cases). Please feel free to add additional comments there to support the use case. |
Thanks @aranguyen : I read through the entire document, but I do not have permissions to make comments on the doc. Should I request access, or is there a different way to provide feedback? |
@psigen please check again if you could add comments on the doc directly now. Thanks! |
Use-case I'm facing: I cannot add:
This forces me to let each user to deal with the flag separately. |
Same issue as @ptabor mentioned. |
Use case I have:
IOW, I don't want to have a bunch of cache misses each time I switch git branches FWIW, I'm already using |
Another use case - Testcontainers uses a file called |
Description of the problem / feature request:
I want to use environment variables in my .bazelrc via string interpolation
Feature requests: what underlying problem are you trying to solve with this feature?
I'm running a remote Bazel cache secured with Basic Auth. I don't want to hardcode basic auth credentials into the
.bazelrc
checked into the repository.Example
.bazelrc
:I would rather do something like this:
What operating system are you running Bazel on?
macOS Catalina 10.15.3
What's the output of
bazel info release
?INFO: Invocation ID: 067b442a-efd2-431e-b39d-9ea6e2467bf3
release 2.0.0
Have you found anything relevant by searching the web?
Related issue comment: #4635 (comment)
The text was updated successfully, but these errors were encountered: