Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Fix "bundle init" when run from Databricks #1744
Fix "bundle init" when run from Databricks #1744
Changes from 12 commits
662234f
8d78809
6585a75
62b2451
08b6b10
90d6490
e51037f
02745de
4c9bf79
694413b
4cd9b17
84d1bbf
6bf59ff
49c6ed6
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for a common lib function. I'd expect this to also check for the existence of /Workspace though to avoid false positives. There may be all kinds of reasons why customers set the env var locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to test for
/Workspace
as it makes the code using it harder to testThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, testing is a pain :( We can leave it out, but then we should at least emit a debug log message whenever there's a match. There will be false positives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing is not an issue as long as you don't inline these expectations.
You can store a bool on the context that stores whether or not we're running on DBR (see
bundle/context.go
for inspiration). In tests, you mark it as always true or always false depending on what you want to test. For the real CLI run, you run a routine that performs the actual detection and stores it in the context.For the check itself, it can look at
/proc/mounts
for the workspace fuse mount, it can check for/.fuse-mounts
, it can check for/databricks
, and I'm sure there are a couple other stable ways to determine this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented this approach in #1889.
Besides the environment variable, it also checks for the presence of a
/databricks
directory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need the value to be non-empty, then you don't need to check if it exists (the OK).
You can use
_
for unused variables, or useenv.Get
directly:cli/libs/env/context.go
Lines 51 to 56 in a4ba0bb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use
env.Set
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference? I see
t.Setenv
used in tests. If I change it toenv.Set
then my tests break.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
env.Set
it adds the variable to the context and passes it along in the context.If it broke then either 1) you weren't capturing the returned
ctx
, or 2) the function doesn't useenv.Get
to access the environment variables.