Implements jib.GetDependenciesMaven/GetDependenciesGradle.#1058
Implements jib.GetDependenciesMaven/GetDependenciesGradle.#1058balopat merged 34 commits intoGoogleContainerTools:jib_skaffoldfrom
Conversation
pkg/skaffold/jib/jib.go
Outdated
| return err == nil | ||
| } | ||
|
|
||
| func getDependencies(workspace string, buildFile string, defaultExecutable string, windowsExecutable string, isWindows bool, subCommand []string, artifactName string) ([]string, error) { |
There was a problem hiding this comment.
Would a struct over a long param list be preferred?
There was a problem hiding this comment.
Could isWindows be a package variable? I created some helpers for execution that looks for the maven/gradle wrappers with different extensions. (https://github.com/briandealwis/skaffold/tree/jib-build)
There was a problem hiding this comment.
Linking the commit for reference: briandealwis@1ec213d
I'll try to change that and see if the testing works well.
There was a problem hiding this comment.
Hmm, not sure if package variables are good for readability? @GoogleContainerTools/container-tools
pkg/skaffold/jib/jib.go
Outdated
| if isWindows { | ||
| if exists(workspace, windowsExecutable) { | ||
| executable = "call" | ||
| subCommand = append([]string{windowsExecutable}, subCommand...) |
There was a problem hiding this comment.
Do we need to use call from within Go?
There was a problem hiding this comment.
Ah, I actually need to use cmd.exe /C ... instead. Also, @GoogleContainerTools/container-tools is there a style preference for using back-ticks for string constants vs quotes?
There was a problem hiding this comment.
Not that I'm aware of: we generally follow standard Go & Kubernetes Coding Conventions: https://github.com/kubernetes/community/blob/master/contributors/guide/coding-conventions.md
In practice, raw string literals (back-ticks) in Go are only used for strings containing a back-slash or double quotes. Other string declarations should probably use the interpreted string literal form (double quotes) unless there is a special requirement to do so.
For specific discussion of string constants (ones declared with const), see the "String constants" section on https://blog.golang.org/constants
There was a problem hiding this comment.
Thanks for clarifying!
pkg/skaffold/jib/jib.go
Outdated
| return getDependencies(workspace, "build.gradle", "gradle", "gradlew.bat", isWindows, []string{"_jibSkaffoldFiles", "-q"}, "jib-gradle") | ||
| } | ||
|
|
||
| func exists(workspace string, filename string) bool { |
There was a problem hiding this comment.
It would be worth making this an isDir() that also tests that the !info.IsDir()?
There was a problem hiding this comment.
Not sure what the directory check is for?
There was a problem hiding this comment.
Right now this will return true for a directory.
pkg/skaffold/jib/jib.go
Outdated
| return err == nil | ||
| } | ||
|
|
||
| func getDependencies(workspace string, buildFile string, defaultExecutable string, windowsExecutable string, isWindows bool, subCommand []string, artifactName string) ([]string, error) { |
There was a problem hiding this comment.
Could isWindows be a package variable? I created some helpers for execution that looks for the maven/gradle wrappers with different extensions. (https://github.com/briandealwis/skaffold/tree/jib-build)
pkg/skaffold/jib/jib.go
Outdated
| // All paths are absolute. | ||
| // TODO(coollog): Add support for multi-module projects. | ||
| func GetDependenciesMaven(workspace string, _ /*a*/ *v1alpha3.JibMavenArtifact, isWindows bool) ([]string, error) { | ||
| return getDependencies(workspace, "pom.xml", "mvn", "mvnw.cmd", isWindows, []string{"jib:_skaffold-files", "-q"}, "jib-maven") |
There was a problem hiding this comment.
This might need to specify the profile in use.
| type JibMavenArtifact struct { | ||
| // Only multi-module | ||
| Module string `yaml:"module"` | ||
| Profile string `yaml:"profile"` |
There was a problem hiding this comment.
Turns out profile is not multimodule only.
125e03b to
6895843
Compare
balopat
left a comment
There was a problem hiding this comment.
Operating system related code should go to *_GOOS suffixed files instead of explicit runtime.GOOS checks. Unit tests that are testing platform dependent code can be also separated out to run/be built only on the given OS using build tags.
docs: https://golang.org/pkg/go/build/
See this minikube package as an example: https://github.com/kubernetes/minikube/tree/master/pkg/minikube/cluster
|
@balopat Will change into that format. |
pkg/skaffold/jib/jib.go
Outdated
| gradleWindowsWrapper = "gradlew.bat" | ||
| ) | ||
|
|
||
| func getCommandMaven(workspace string, a *v1alpha3.JibMavenArtifact, isWindows bool) (executable string, subCommand []string) { |
There was a problem hiding this comment.
Can we generalize this and getCommandGradle to take the subcommand as an argument?
There was a problem hiding this comment.
getCommand does take subCommand (defaultSubCommand) as an argument
|
Changed to use *_GOOS filename format - LMK if this looks okay. |
pkg/skaffold/jib/jib.go
Outdated
| return getDependencies(workspace, "build.gradle", "gradle", "gradlew.bat", isWindows, []string{"_jibSkaffoldFiles", "-q"}, "jib-gradle") | ||
| } | ||
|
|
||
| func exists(workspace string, filename string) bool { |
There was a problem hiding this comment.
Right now this will return true for a directory.
| package jib | ||
|
|
||
| func getWrapper() string { | ||
| return "gradlew" |
There was a problem hiding this comment.
Oh is this missing something?
There was a problem hiding this comment.
Oh oops. Hmm, how did this even pass the tests.
pkg/skaffold/jib/jib_darwin.go
Outdated
|
|
||
| wrapperExecutable := getWrapper() | ||
| if exists(workspace, wrapperExecutable) { | ||
| executable = "./" + wrapperExecutable |
There was a problem hiding this comment.
I think it's worth making the path absolute just in case the command-execution sets a different working directory
pkg/skaffold/jib/jib_linux.go
Outdated
| package jib | ||
|
|
||
| func getWrapper() string { | ||
| return "gradlew" |
pkg/skaffold/jib/jib_linux.go
Outdated
|
|
||
| wrapperExecutable := getWrapper() | ||
| if exists(workspace, wrapperExecutable) { | ||
| executable = "./" + wrapperExecutable |
There was a problem hiding this comment.
Ditto returning an absolute path
pkg/skaffold/jib/jib_darwin.go
Outdated
| return "gradlew" | ||
| } | ||
|
|
||
| func getCommand(workspace string, defaultExecutable string, defaultSubCommand []string) (executable string, subCommand []string) { |
There was a problem hiding this comment.
Can you capitalize this so that it can be used elsewhere?
Or provide InvokeMaven and InvokeGradle variants that hide the wrapper bit.
There was a problem hiding this comment.
I think I'll leave that to another PR - one that would use this method from another package - it's probably good to keep visibility as low as possible until it needs to be exposed.
There was a problem hiding this comment.
I want to replace what I have :-)
There was a problem hiding this comment.
Would making getCommandMaven and getCommandGradle exposed be good? I'll change it to include a custom subcommand to use.
|
Hmm, it seems if I name a test like |
|
Alright, finally got Windows to pass. |
| @@ -0,0 +1,38 @@ | |||
| /* | |||
There was a problem hiding this comment.
do we really need both jib_linux and jib_darwin? @balopat ?
There was a problem hiding this comment.
no just call it jib.go and put // +build linux darwin at the top
There was a problem hiding this comment.
you can call it jib_unix.go if you really want
There was a problem hiding this comment.
Okay, will go with jib_unix.go since jib.go has common logic shared with jib_windows.go
…n imports ¯\_(ツ)_/¯.
Codecov Report
@@ Coverage Diff @@
## jib_skaffold #1058 +/- ##
================================================
+ Coverage 40.72% 41.55% +0.82%
================================================
Files 72 77 +5
Lines 3104 3148 +44
================================================
+ Hits 1264 1308 +44
Misses 1715 1715
Partials 125 125
Continue to review full report at Codecov.
|
balopat
left a comment
There was a problem hiding this comment.
left some more reorganizational comments and nits
pkg/skaffold/jib/jib.go
Outdated
|
|
||
| func getDependencies(workspace string, buildFile string, executable string, subCommand []string, artifactName string) ([]string, error) { | ||
| if _, err := resolveFile(workspace, buildFile); err != nil { | ||
| return nil, errors.Errorf("no %s found", buildFile) |
There was a problem hiding this comment.
nit: use errors.Wrap instead with err
pkg/skaffold/jib/jib.go
Outdated
| } | ||
|
|
||
| // resolveFile resolves the absolute path of the file named filename in directory workspace, erroring if it is not a file | ||
| func resolveFile(workspace string, filename string) (string, error) { |
There was a problem hiding this comment.
- this could live in
pkg/skaffold/util/util.go - I would rename it to just
AbsFile. workspace->dir
pkg/skaffold/jib/jib_unix.go
Outdated
| package jib | ||
|
|
||
| func getWrapper(defaultExecutable string) string { | ||
| switch defaultExecutable { |
There was a problem hiding this comment.
this smells a little bit like we are trying to decide between maven/gradle logic using arbitrary consts (lack of enums I guess?), while in other cases we are using "Maven/Gradle" postfix. It's starting to get confusing what logic belongs to maven/gradle and what's common. I'd like to see if introducing the subpackages under jib/maven, jib/gradle would help or not.
|
Rearranged the structure into separate |
|
It looks good to me, go ahead with the tests! |
pkg/skaffold/jib/jib_unix.go
Outdated
| "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" | ||
| ) | ||
|
|
||
| func getCommand(workspace string, defaultExecutable string, wrapperExecutable string, defaultSubCommand []string) *exec.Cmd { |
There was a problem hiding this comment.
if there's no alternative to the subCommand, do we need to specify default?
There was a problem hiding this comment.
Nope, I'll rename to just subCommand
|
We don't need to cover expanding directories in this pr, right? |
|
Tests are updated as well and added TODO for expanding directories in follow-up PR. |
This PR builds off of #1043 and should merge that before merging this.
Implements
jib/jib.gowithGetDependenciesMavenandGetDependenciesGradle.For Maven, calls out to
mvn jib:_skaffold-files -q. Uses the wrappermvnwif present. Uses Windows wrappermvnw.cmdif present and OS is Windows.For Gradle, calls out to
gradle _jibSkaffoldFiles -q. Uses the wrappergradlewif present. Uses Windows wrappergradlew.batif present and OS is Windows.Note that this only covers the single-module use case and multi-module use case will be added in future PRs.
@GoogleContainerTools/java-tools