-
Notifications
You must be signed in to change notification settings - Fork 405
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
Enable setting the working dir for the go tool #365
Conversation
Can you explain the |
And to resolve local "import paths" correctly, the function needs to know the current directory, from the new
Not without changing the method signatures AFAICT. We could call a non-exported |
pkg/commands/options/build.go
Outdated
|
||
// Dir allows for setting the working directory for invocations of the `go` tool. | ||
// Empty string means the current working directory. | ||
Dir string |
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.
Can we rename this to WorkingDir
or WorkingDirectory
? I think that would help with the name collision for #365
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.
Done. Also squashed the commits.
This change adds a `WorkingDirectory` field to `options.BuildOptions`, but doesn't expose this as a CLI flag. The default zero value means the current working directory. The value is used as the directory for executing `go` tool commands. When embedding ko in other tools, it is sometimes necessary to set the working directory for executing the `go` tool, instead of assuming the current process working directory. An example of where this is required from Skaffold: https://github.com/GoogleContainerTools/skaffold/tree/master/examples/microservices In this example, the working directory doesn't contain either `go.mod` or any Go files. The `skaffold.yaml` configuration file specifies a `context` field for each image, which is the directory where the `go` tool can find package information.
This change adds a
WorkingDirectory
field tooptions.BuildOptions
, but doesn'texpose this as a CLI flag. The default zero value means the current
working directory. The value is used as the working directory for
executing
go
tool commands.When embedding ko in other tools, it is sometimes necessary to set the
working directory for executing the
go
tool, instead of assuming thecurrent process working directory.
An example of where this is required from Skaffold:
https://github.com/GoogleContainerTools/skaffold/tree/master/examples/microservices
In this example, the working directory doesn't contain either
go.mod
or any Go files. The
skaffold.yaml
configuration file specifiesa
context
field for each image, which is the directory where thego
tool can find package information.
I considered updating the
buildContext
interface to wrapgo/build.Context
.That'd avoid duplicating the
dir
field ingobuild
andbuildContext
.Instead of add that to this pull request, I made that change in another branch,
mainly to explore what that could look like:
https://github.com/halvards/ko/blob/base-dir-buildcontext/pkg/build/context.go#L17
PLMKWYT (this could be a starting point for #305)