From ee474f3612a0c2be48662ccaac126b04bcbb94c4 Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Fri, 23 Oct 2020 10:24:51 -0700 Subject: [PATCH] Run the hello test on multiple architectures --- .travis.yml | 37 +++++++++++++++++++++++-------------- cmd/ko/test/main.go | 15 ++++++++++++--- pkg/publish/daemon.go | 41 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 73 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 12186d9a5e..373160a79c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,30 @@ -sudo: required - -dist: trusty - -services: - - docker - -language: - - go - +dist: bionic +language: go go: - - '1.14' - '1.15' - git: depth: 1 -install: true # skipping the default go dependencies install step +jobs: + include: + - arch: amd64 + - arch: arm64 + - arch: s390x + - arch: ppc64le script: - - bash integration_test.sh + # Make sure ko compiles for the right architecture. + - eval $(go env) + - go install -mod=vendor ./cmd/ko + # Try with all, and GOOS/GOARCH set. + - GOOS=${GOOS} GOARCH=${GOARCH} KO_DOCKER_REPO=ko.local ko publish --platform=all -B ./cmd/ko/test + - docker run -i ko.local/test -wait=false + # Try with the appropriate platform. + - KO_DOCKER_REPO=ko.local ko publish --platform=${GOOS}/${GOARCH} -B ./cmd/ko/test + - docker run -i ko.local/test -wait=false + # Try with just GOOS/GOARCH + - GOOS=${GOOS} GOARCH=${GOARCH} KO_DOCKER_REPO=ko.local ko publish -B ./cmd/ko/test + - docker run -i ko.local/test -wait=false + +notifications: + email: false diff --git a/cmd/ko/test/main.go b/cmd/ko/test/main.go index 4832b53e10..5f3e0109e5 100644 --- a/cmd/ko/test/main.go +++ b/cmd/ko/test/main.go @@ -15,6 +15,7 @@ package main import ( + "flag" "io/ioutil" "log" "os" @@ -23,7 +24,13 @@ import ( "syscall" ) +var ( + wait = flag.Bool("wait", true, "Whether to wait for SIGTERM") +) + func main() { + flag.Parse() + dp := os.Getenv("KO_DATA_PATH") file := filepath.Join(dp, "kenobi") bytes, err := ioutil.ReadFile(file) @@ -40,7 +47,9 @@ func main() { log.Print(string(bytes)) // Cause the pod to "hang" to allow us to check for a readiness state. - sigs := make(chan os.Signal, 1) - signal.Notify(sigs, syscall.SIGTERM) - <-sigs + if *wait { + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGTERM) + <-sigs + } } diff --git a/pkg/publish/daemon.go b/pkg/publish/daemon.go index 34606f0553..ce4778e9cd 100644 --- a/pkg/publish/daemon.go +++ b/pkg/publish/daemon.go @@ -17,6 +17,7 @@ package publish import ( "fmt" "log" + "os" "strings" "github.com/google/go-containerregistry/pkg/name" @@ -47,9 +48,43 @@ func (d *demon) Publish(br build.Result, s string) (name.Reference, error) { // https://github.com/google/go-containerregistry/issues/212 s = strings.ToLower(s) - // There's no way to write an index to a daemon, so attempt to downcast it to an image. - img, ok := br.(v1.Image) - if !ok { + // There's no way to write an index to a kind, so attempt to downcast it to an image. + var img v1.Image + switch i := br.(type) { + case v1.Image: + img = i + case v1.ImageIndex: + im, err := i.IndexManifest() + if err != nil { + return nil, err + } + goos, goarch := os.Getenv("GOOS"), os.Getenv("GOARCH") + if goos == "" { + goos = "linux" + } + if goarch == "" { + goarch = "amd64" + } + for _, manifest := range im.Manifests { + if manifest.Platform == nil { + continue + } + if manifest.Platform.OS != goos { + continue + } + if manifest.Platform.Architecture != goarch { + continue + } + img, err = i.Image(manifest.Digest) + if err != nil { + return nil, err + } + break + } + if img == nil { + return nil, fmt.Errorf("failed to find %s/%s image in index for image: %v", goos, goarch, s) + } + default: return nil, fmt.Errorf("failed to interpret %s result as image: %v", s, br) }