1
0
mirror of https://github.com/ko-build/ko.git synced 2025-07-15 23:54:17 +02:00

Add support for Go build flags (#340)

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`.
This commit is contained in:
Matthias Diester
2021-07-02 17:40:56 +02:00
committed by GitHub
parent ee23538378
commit ab4d264103
8 changed files with 326 additions and 11 deletions

View File

@ -20,6 +20,7 @@ import (
"context"
"testing"
"github.com/google/ko/pkg/build"
"github.com/google/ko/pkg/commands/options"
)
@ -45,3 +46,34 @@ func TestOverrideDefaultBaseImageUsingBuildOption(t *testing.T) {
t.Errorf("got digest %s, wanted %s", gotDigest, wantDigest)
}
}
func TestCreateBuildConfigs(t *testing.T) {
compare := func(expected string, actual string) {
if expected != actual {
t.Errorf("test case failed: expected '%#v', but actual value is '%#v'", expected, actual)
}
}
buildConfigs := []build.Config{
{ID: "defaults"},
{ID: "OnlyMain", Main: "test"},
{ID: "OnlyMainWithFile", Main: "test/main.go"},
{ID: "OnlyDir", Dir: "test"},
{ID: "DirAndMain", Dir: "test", Main: "main.go"},
}
for _, b := range buildConfigs {
for importPath, buildCfg := range createBuildConfigs("../..", []build.Config{b}) {
switch buildCfg.ID {
case "defaults":
compare("github.com/google/ko", importPath)
case "OnlyMain", "OnlyMainWithFile", "OnlyDir", "DirAndMain":
compare("github.com/google/ko/test", importPath)
default:
t.Fatalf("unknown test case: %s", buildCfg.ID)
}
}
}
}