-
Notifications
You must be signed in to change notification settings - Fork 404
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
Add support for Go build flags #340
Add support for Go build flags #340
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
7d6437a
to
920d8cb
Compare
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.
Thanks for doing this -- a few comments, but it's looking pretty good.
037a944
to
a88c9be
Compare
pkg/build/options.go
Outdated
@@ -45,6 +46,15 @@ func WithDisabledOptimizations() Option { | |||
} | |||
} | |||
|
|||
// WithGoReleaserBuildConfig is a functional option for providing build | |||
// settings based on a GoReleaser style configuration. | |||
func WithGoReleaserBuildConfig(buildCfgOverrides map[string]config.Build) Option { |
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 this is impossible for external dependents to use because config.Build
is internal/
. (cc @halvards)
We may want to have a pkg/config
(or something) that exposes the usable subset of goreleaser's config.Build
, then do some translation to talk advantage of their stuff.
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.
Good point. Thanks. I moved it to pkg/config
. However, I am wondering whether maybe something like pkg/ref/goreleaser/config
would be better, because pkg/config
is pretty generic.
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.
@jonjohnsonjr Did you have to think about the name of package?
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.
Sorry, missed this comment. That's a good point.
My intuition is that this would only affect build config, so it might make more sense to flip the name and call this build.Config
instead of config.Build
?
I'm indifferent re: config vs configuration, but this seems reasonable enough:
builder.Build(..., build.WithConfig(build.Config{}))
We already have build.Result
so it fits in well. If we want to have a separate configuration for e.g. the publisher stuff (currently set by KO_DOCKER_REPO), that could be mirrored as publisher.Config
. I think scoping the configuration to the relevant package is probably best, but I'd be interested in other ideas.
Sorry for the back and forth on this :P
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.
No problem, not at all. I am here to learn. Naming things can be hard and build.Config
makes perfect sense while also improves the readability of the code. I will change that right away.
a88c9be
to
9b1e390
Compare
9b1e390
to
0fbec7b
Compare
pkg/build/config.go
Outdated
import "strings" | ||
|
||
// Note: The structs, types, and functions are based upon GoReleaser build | ||
// configuration to have a loosly compatible YAML configuration: |
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.
// configuration to have a loosly compatible YAML configuration: | |
// configuration to have a loosely compatible YAML configuration: |
pkg/build/options.go
Outdated
@@ -45,6 +45,15 @@ func WithDisabledOptimizations() Option { | |||
} | |||
} | |||
|
|||
// WithConfig is a functional option for providing build settings based on a | |||
// GoReleaser Build influenced configuration. | |||
func WithConfig(buildCfgOverrides map[string]Config) Option { |
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.
Document what the key is here.
|
||
// Config contains the build configuration section. The name was changed from | ||
// the original GoReleaser name to match better with the ko namings. | ||
type Config struct { |
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 would comment out anything that we don't currently respect and put a big fat TODO comment at the top, maybe pointing to an existing issue or a new issue to track progress.
I believe we only respect Ldflags
and Flags
currently?
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.
Yes, it is only Ldflags
and Flags
with this PR. In the project I am currently working on, I see the potential that maybe something like ModTimestamp
and Env
would be interesting, too. I would like to tackle that with subsequent PRs.
pkg/build/config.go
Outdated
Goarm []string `yaml:",omitempty"` | ||
Gomips []string `yaml:",omitempty"` | ||
Targets []string `yaml:",omitempty"` | ||
Dir string `yaml:",omitempty"` |
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.
0fbec7b
to
04135ed
Compare
I think we'll want to combine the changes from #365 with this PR. This PR uses |
270915c
to
ead5e7f
Compare
Changing the code to make sure that |
Apologies for taking a while to get around to looking at this. It's been a while since I got too deep into the
Interesting. This has been challenging in the past when dealing with go submodules within a repository.
I think I prefer the simplicity of changing the function signatures. It makes it easier to review at least. |
ead5e7f
to
03e4b3e
Compare
@jonjohnsonjr I added comments to |
There are use cases, where multiple Go build flags need to be set. However, the environment variable to pass flags to Go build has some limits for `ldFlags`. Add GoReleaser inspired configuration section to `.ko.yaml` to support setting specific Go build and ldFlags to be used by the build. Like GoReleaser the content of the configuration can use Go templates. Currently, only a section for environment variables is included. In order to reduce dependency overhead, only the respective config structs from https://github.com/goreleaser/goreleaser/blob/master/pkg/config/config.go are used internally to load from `.ko.yaml`.
03e4b3e
to
606e66e
Compare
@imjasonh want to take a look? I think we're getting close to something that's actually not bad! |
This adds the `Build()` method for building artifacts using ko. It supports both publishing the resulting image to a registry, and sideloading it to the local Docker daemon. The `temporary.go` file contains the structs intended to be added to the schema. This implementation is still missing the following features: - integration test - dependencies (for file watching) - insecure registries - debug mode - support for `go` flags and environment variables (waiting on ko-build/ko#340) - actually plumbing the builder into the Skaffold CLI and API :-) Tracking: GoogleContainerTools#6041
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.
Looks great! Thanks for your hard work on this @HeavyWombat
@jonjohnsonjr Anything else you want to see before we merge this? We should probably cut a release after so people can use it more easily.
I want to experiment for a bit before cutting a release, I think. |
Thanks for looking into it. If there is anything I can help with, please let me know. |
This adds the `Build()` method for building artifacts using ko. It supports both publishing the resulting image to a registry, and sideloading it to the local Docker daemon. The Skaffold docker client is used in the ko builder. This ensures that any Minikube config set by Skaffold is used. The ko builder uses the docker client when sideloading images to the docker daemon. The `temporary.go` file contains the structs intended to be added to the schema. The additions to the design proposal explain image naming for the ko builder, specifically how container images are named and how Go import paths are resolved when using the proposed ko builder. This commit includes ko builder unit tests for non-current-working-directory workspace dirs. These verify that the ko builder works even if the context specified in `skaffold.yaml` differs from the current working directory. This implementation is still missing the following features: - integration test - dependencies (for file watching) - insecure registries - debug mode - support for `go` flags and environment variables (based on ko-build/ko#340) - actually plumbing the builder into the Skaffold CLI and API :-) Tracking: GoogleContainerTools#6041
This adds the `Build()` method for building artifacts using ko. It supports both publishing the resulting image to a registry, and sideloading it to the local Docker daemon. The Skaffold docker client is used in the ko builder. This ensures that any Minikube config set by Skaffold is used. The ko builder uses the docker client when sideloading images to the docker daemon. The `temporary.go` file contains the structs intended to be added to the schema. The additions to the design proposal explain image naming for the ko builder, specifically how container images are named and how Go import paths are resolved when using the proposed ko builder. This commit includes ko builder unit tests for non-current-working-directory workspace dirs. These verify that the ko builder works even if the context specified in `skaffold.yaml` differs from the current working directory. This implementation is still missing the following features: - integration test - dependencies (for file watching) - insecure registries - debug mode - support for `go` flags and environment variables (based on ko-build/ko#340) - actually plumbing the builder into the Skaffold CLI and API :-) Tracking: GoogleContainerTools#6041
This adds the `Build()` method for building artifacts using ko. It supports both publishing the resulting image to a registry, and sideloading it to the local Docker daemon. The Skaffold docker client is used in the ko builder. This ensures that any Minikube config set by Skaffold is used. The ko builder uses the docker client when sideloading images to the docker daemon. The `temporary.go` file contains the structs intended to be added to the schema. The additions to the design proposal explain image naming for the ko builder, specifically how container images are named and how Go import paths are resolved when using the proposed ko builder. This commit includes ko builder unit tests for non-current-working-directory workspace dirs. These verify that the ko builder works even if the context specified in `skaffold.yaml` differs from the current working directory. This implementation is still missing the following features: - integration test - dependencies (for file watching) - insecure registries - debug mode - support for `go` flags and environment variables (based on ko-build/ko#340) - actually plumbing the builder into the Skaffold CLI and API :-) Tracking: GoogleContainerTools#6041
This adds the `Build()` method for building artifacts using ko. It supports both publishing the resulting image to a registry, and sideloading it to the local Docker daemon. The Skaffold docker client is used in the ko builder. This ensures that any Minikube config set by Skaffold is used. The ko builder uses the docker client when sideloading images to the docker daemon. The `temporary.go` file contains the structs intended to be added to the schema. The additions to the design proposal explain image naming for the ko builder, specifically how container images are named and how Go import paths are resolved when using the proposed ko builder. This commit includes ko builder unit tests for non-current-working-directory workspace dirs. These verify that the ko builder works even if the context specified in `skaffold.yaml` differs from the current working directory. This implementation is still missing the following features: - integration test - dependencies (for file watching) - insecure registries - debug mode - support for `go` flags and environment variables (based on ko-build/ko#340) - actually plumbing the builder into the Skaffold CLI and API :-) Tracking: GoogleContainerTools#6041
This adds the `Build()` method for building artifacts using ko. It supports both publishing the resulting image to a registry, and sideloading it to the local Docker daemon. The Skaffold docker client is used in the ko builder. This ensures that any Minikube config set by Skaffold is used. The ko builder uses the docker client when sideloading images to the docker daemon. The `temporary.go` file contains the structs intended to be added to the schema. The additions to the design proposal explain image naming for the ko builder, specifically how container images are named and how Go import paths are resolved when using the proposed ko builder. This commit includes ko builder unit tests for non-current-working-directory workspace dirs. These verify that the ko builder works even if the context specified in `skaffold.yaml` differs from the current working directory. This implementation is still missing the following features: - integration test - dependencies (for file watching) - insecure registries - debug mode - support for `go` flags and environment variables (based on ko-build/ko#340) - actually plumbing the builder into the Skaffold CLI and API :-) Tracking: GoogleContainerTools#6041
This adds the `Build()` method for building artifacts using ko. It supports both publishing the resulting image to a registry, and sideloading it to the local Docker daemon. The Skaffold docker client is used in the ko builder. This ensures that any Minikube config set by Skaffold is used. The ko builder uses the docker client when sideloading images to the docker daemon. The `temporary.go` file contains the structs intended to be added to the schema. The additions to the design proposal explain image naming for the ko builder, specifically how container images are named and how Go import paths are resolved when using the proposed ko builder. This commit includes ko builder unit tests for non-current-working-directory workspace dirs. These verify that the ko builder works even if the context specified in `skaffold.yaml` differs from the current working directory. This implementation is still missing the following features: - integration test - dependencies (for file watching) - insecure registries - debug mode - support for `go` flags and environment variables (based on ko-build/ko#340) - actually plumbing the builder into the Skaffold CLI and API :-) Tracking: GoogleContainerTools#6041
This adds the `Build()` method for building artifacts using ko. It supports both publishing the resulting image to a registry, and sideloading it to the local Docker daemon. The Skaffold docker client is used in the ko builder. This ensures that any Minikube config set by Skaffold is used. The ko builder uses the docker client when sideloading images to the docker daemon. The `temporary.go` file contains the structs intended to be added to the schema. The additions to the design proposal explain image naming for the ko builder, specifically how container images are named and how Go import paths are resolved when using the proposed ko builder. This commit includes ko builder unit tests for non-current-working-directory workspace dirs. These verify that the ko builder works even if the context specified in `skaffold.yaml` differs from the current working directory. This implementation is still missing the following features: - integration test - dependencies (for file watching) - insecure registries - debug mode - support for `go` flags and environment variables (based on ko-build/ko#340) - actually plumbing the builder into the Skaffold CLI and API :-) Tracking: GoogleContainerTools#6041
* Add core ko builder implementation This adds the `Build()` method for building artifacts using ko. It supports both publishing the resulting image to a registry, and sideloading it to the local Docker daemon. The Skaffold docker client is used in the ko builder. This ensures that any Minikube config set by Skaffold is used. The ko builder uses the docker client when sideloading images to the docker daemon. The `temporary.go` file contains the structs intended to be added to the schema. The additions to the design proposal explain image naming for the ko builder, specifically how container images are named and how Go import paths are resolved when using the proposed ko builder. This commit includes ko builder unit tests for non-current-working-directory workspace dirs. These verify that the ko builder works even if the context specified in `skaffold.yaml` differs from the current working directory. This implementation is still missing the following features: - integration test - dependencies (for file watching) - insecure registries - debug mode - support for `go` flags and environment variables (based on ko-build/ko#340) - actually plumbing the builder into the Skaffold CLI and API :-) Tracking: #6041 * Improve ko Builder unit tests Split out the confusing end-to-end unit test with tests for individual functions. * Reorder test inputs and expected outputs Also fix typo in design proposal. * Add TODO to update import path Reminders to update the import path once the contents of `pkg/skaffold/build/ko/schema` have been added to the real schema in `pkg/skaffold/schema/latest/v1`. * Fix lint errors for TODO comments in import block Adding the TODO in the import block resulted in gci linter errors: https://app.travis-ci.com/github/GoogleContainerTools/skaffold/jobs/530642848#L313
Matches the GoReleaser format. Related: ko-build#340
Enables programmatically overriding build configs when ko is embedded in another tool. Related: ko-build#340, ko-build#419
Matches the GoReleaser format. Related: ko-build#340
Enables programmatically overriding build configs when ko is embedded in another tool. Related: ko-build#340, ko-build#419
* Enable setting environment variables in .ko.yaml Matches the GoReleaser format. Related: #340 * Use different env example
Enables programmatically overriding build configs when ko is embedded in another tool. Related: ko-build#340, ko-build#419
* Set build config via BuildOptions Enables programmatically overriding build configs when ko is embedded in another tool. Related: #340, #419 * Use local registry for base images in unit tests Tests create a local registry (using ggcr) with a dummy base image. This speeds up tests, since they don't need to hit gcr.io to fetch the default distroless base image. * Update function comment to refer to random image
Fixes #316
There are use cases, where multiple Go build flags need to be set. However, the environment variable to pass flags to Go build has some limits for
ldFlags
.Proposed changes:
.ko.yaml
to support setting specific Go build and ldFlags to be used by the build.KO_GOBUILD_FLAGS
to add extra build flags andKO_GOBUILD_LDFLAGS
to add extra ldFlags.