1
0
mirror of https://github.com/ko-build/ko.git synced 2025-11-06 09:19:12 +02:00

[modules] Dependent command packages can now be built with ko (#154)

Thus if you have a (in)direct command package as a dependency
say `myhost.com/go/package/cmd/run` you can now publish this
with the following ko command

  ko publish myhost.com/go/package/cmd/run
This commit is contained in:
Dave Protasowski
2020-05-01 10:18:26 -04:00
committed by GitHub
parent 429a4097a7
commit 6cbfe964d7
3 changed files with 105 additions and 20 deletions

View File

@@ -17,6 +17,7 @@ package build
import (
"archive/tar"
"context"
gb "go/build"
"io"
"io/ioutil"
"path"
@@ -69,12 +70,31 @@ func TestGoBuildIsSupportedRefWithModules(t *testing.T) {
if err != nil {
t.Fatalf("random.Image() = %v", err)
}
mod := &modInfo{
Path: "github.com/google/ko/cmd/ko/test",
Dir: ".",
mods := &modules{
main: &modInfo{
Path: "github.com/google/ko/cmd/ko/test",
Dir: ".",
},
deps: map[string]*modInfo{
"github.com/some/module/cmd": &modInfo{
Path: "github.com/some/module/cmd",
Dir: ".",
},
},
}
ng, err := NewGo(WithBaseImages(func(string) (v1.Image, error) { return base, nil }), withModuleInfo(mod))
opts := []Option{
WithBaseImages(func(string) (v1.Image, error) { return base, nil }),
withModuleInfo(mods),
withBuildContext(stubBuildContext{
// make all referenced deps commands
"github.com/google/ko/cmd/ko/test": &gb.Package{Name: "main"},
"github.com/some/module/cmd": &gb.Package{Name: "main"},
}),
}
ng, err := NewGo(opts...)
if err != nil {
t.Fatalf("NewGo() = %v", err)
}
@@ -82,6 +102,7 @@ func TestGoBuildIsSupportedRefWithModules(t *testing.T) {
// Supported import paths.
for _, importpath := range []string{
"github.com/google/ko/cmd/ko/test", // ko can build the test package.
"github.com/some/module/cmd", // ko can build commands in dependent modules
} {
t.Run(importpath, func(t *testing.T) {
if !ng.IsSupportedReference(importpath) {
@@ -376,3 +397,9 @@ func TestGoBuild(t *testing.T) {
}
})
}
type stubBuildContext map[string]*gb.Package
func (s stubBuildContext) Import(path string, srcDir string, mode gb.ImportMode) (*gb.Package, error) {
return s[path], nil
}