-
Notifications
You must be signed in to change notification settings - Fork 112
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
move chef -v to golang #2062
move chef -v to golang #2062
Conversation
👷 Deploy Preview for chef-workstation processing. 🔨 Explore the source changes: a80f130 🔍 Inspect the deploy log: https://app.netlify.com/sites/chef-workstation/deploys/611cebafbe381100087a6cb4 |
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 think it would make sense to move the implementation here as well. Moving the flag itself but still invoking chef-cli won't get the improvements that are requested in the original issue.
An implementation written for this PR won't be invalidated by #1465, though it may need to be updated a bit
"path" | ||
"io/ioutil" | ||
"encoding/json" | ||
"github.com/mnogu/go-dig" |
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 looks helpful, but I'm concerned because it looks like it was created over the course of 1-2 days and has not received any attention since then.
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 think I saw some talk around defining a nested struct to unmarshal into. While we can't do that for the gem version manifest, is it possible to do it for the workstation versoin manifest? Or is the structure of that file problematic, eg there's no array of definitions under software
, but rather a bunch of named json objects there?
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 think we can unmarshall gem manifest since it seems structured,
eg-
"wmi-lite": [
"1.0.5"
],
"xmlrpc": [
"0.3.0"
],
but the structure of the file version manifest under software is a bunch of JSON object so two different structures were there in both file.
So I made it into interface which made it easier for me.
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 looks helpful, but I'm concerned because it looks like it was created over the course of 1-2 days and has not received any attention since then.
are we talking about this "github.com/mnogu/go-dig"
??, I think code was pretty straight. i could have written same for it saved time and space for me.
edited -Hm, Seems its failing in buildkite. i will write it manually
if omnibusInstall() == true { | ||
showVersionViaVersionManifest() | ||
} else { | ||
// todo "5.1,0 is coming from #{ChefCLI::VERSION} in ruby, need to figure out how to do 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.
I think we can eliminate the branch that does not come from an omnibus install, or consider it an error. This wrapper is only supported in an omnibus install.
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.
Okay, i will raise error.
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.
pushed changes in new commits
This looks good, but let's add some level of testing for Dig as well. |
func omnibusRoot()string { | ||
omnibusroot, err := filepath.Abs(path.Join(ExpectedOmnibusRoot())) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, "ERROR:", "Can not find omnibus installation directory for Chef Workstation") |
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.
Should this error also use the dist file?
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.
as in Chef Workstation part from "Can not find omnibus installation directory for Chef Workstation" can be used from dist ile ??
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.
Updated it with fmt.Fprintln(os.Stderr, "ERROR:", "Can not find omnibus installation directory for", dist.WorkstationProduct)
This should get rebased on master |
adhoc to confirm functionality: https://buildkite.com/chef/chef-chef-workstation-master-omnibus-adhoc/builds/501#02ff98c2-cc72-4bda-a52b-0a66b0a63862 |
} | ||
|
||
func ExpectedOmnibusRoot()string { | ||
groot := os.Getenv("GEM_ROOT") |
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 don't think we can assume this will be present in the user's environment because we're no longer loading this in the context of the ruby environment.
Instead, we should look relative to the chef
executable directory.
74c45b4
to
4ff6ab3
Compare
if omnibusInstall() == true { | ||
showVersionViaVersionManifest() | ||
} else { | ||
fmt.Fprintln(os.Stderr, "ERROR:", "Can not find omnibus installation directory for", dist.WorkstationProduct) |
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 message won't necessarily mean much to the person using it, who doesn't really have awareness of 'omnibus'. Instead, maybe "$PRODUCT has not been installed via the platform-specific package provided by $DISTRIBUTOR-NAME. Version information is not available."?
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.
According to my understanding,
$PRODUCT - would be a dynamic value containing e.g (Chef-workstation)
what would be $DISTRIBUTOR-NAME?? or may be I am understanding it wrong
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.
Comments are inline. Please delete your local branch before pulling this down to avoid conflicts/merge breakage.
I ran an adhoc of this and it's failing to pull the version on my mac:
|
This is looking good - we're almost there. Two things remaining - let's check the caess where we have errors that we can't reasonably recover from, and exit at those locations or return the errors to the caller(s) so that they can exit gracefully. Separately, please run |
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.
Reviwed
if omnibusInstall() == true { | ||
showVersionViaVersionManifest() | ||
} else { | ||
fmt.Fprintln(os.Stderr, "ERROR:", "Can not find omnibus installation directory for", dist.WorkstationProduct) |
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.
According to my understanding,
$PRODUCT - would be a dynamic value containing e.g (Chef-workstation)
what would be $DISTRIBUTOR-NAME?? or may be I am understanding it wrong
cf993f1
to
8a3ef2b
Compare
Provides the option to pass -v/--version through chef-main-wrapper in golang, with a function version() where all the logic from chef-cli with ruby code is pulled and switched with golang This removes the overhead of starting the ruby VM to report version , most of which is loaded from files distributed in the chef-workstation build. Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
…ibutor name in constat Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
Signed-off-by: Pranay Singh <i5singh.pranay@gmail.com>
8a3ef2b
to
a80f130
Compare
Adding the option for the chef -v through go wrapper
Description
Provides the option to pass -v/--version through chef-main-wrapper in golang, with a function version() where all the logic from chef-cli with ruby code is pulled and switched with golang
Related Issue
fixes #656
Related PR which will replace this in future #1465
Types of changes
Checklist: