From cde258294ff7be831199f61e6f6e8cc6ed17f564 Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Fri, 23 Oct 2020 16:47:34 -0700 Subject: [PATCH] Run the hello test on multiple architectures (#227) --- .github/workflows/kind-e2e.yaml | 2 +- .travis.yml | 66 ++++++++++++++++++++++++++------- cmd/ko/test/main.go | 15 ++++++-- pkg/publish/daemon.go | 41 ++++++++++++++++++-- 4 files changed, 103 insertions(+), 21 deletions(-) diff --git a/.github/workflows/kind-e2e.yaml b/.github/workflows/kind-e2e.yaml index 27407c5d90..729f227228 100644 --- a/.github/workflows/kind-e2e.yaml +++ b/.github/workflows/kind-e2e.yaml @@ -126,7 +126,7 @@ jobs: - name: Wait for ready nodes run: | - kubectl wait --for=condition=Ready nodes --all + kubectl wait --timeout=2m --for=condition=Ready nodes --all - name: Run Smoke Test run: | diff --git a/.travis.yml b/.travis.yml index 12186d9a5e..5fde9318d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,59 @@ -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 + OUTPUT=$(docker run -i ko.local/test -wait=false 2>&1) + if [[ ! "${OUTPUT}" =~ "$(cat ./cmd/ko/test/kodata/kenobi)" ]]; then + echo Mismatched output: ${OUTPUT}, wanted: $(cat ./cmd/ko/test/kodata/kenobi) + exit 1 + fi + if [[ ! "${OUTPUT}" =~ "$(cat ./cmd/ko/test/kodata/HEAD)" ]]; then + echo Mismatched output: ${OUTPUT}, wanted: $(cat ./cmd/ko/test/kodata/HEAD) + exit 1 + fi + + # Try with the appropriate platform. + - | + KO_DOCKER_REPO=ko.local ko publish --platform=${GOOS}/${GOARCH} -B ./cmd/ko/test + OUTPUT=$(docker run -i ko.local/test -wait=false 2>&1) + if [[ ! "${OUTPUT}" =~ "$(cat ./cmd/ko/test/kodata/kenobi)" ]]; then + echo Mismatched output: ${OUTPUT}, wanted: $(cat ./cmd/ko/test/kodata/kenobi) + exit 1 + fi + if [[ ! "${OUTPUT}" =~ "$(cat ./cmd/ko/test/kodata/HEAD)" ]]; then + echo Mismatched output: ${OUTPUT}, wanted: $(cat ./cmd/ko/test/kodata/HEAD) + exit 1 + fi + + # Try with just GOOS/GOARCH + - | + GOOS=${GOOS} GOARCH=${GOARCH} KO_DOCKER_REPO=ko.local ko publish -B ./cmd/ko/test + OUTPUT=$(docker run -i ko.local/test -wait=false 2>&1) + if [[ ! "${OUTPUT}" =~ "$(cat ./cmd/ko/test/kodata/kenobi)" ]]; then + echo Mismatched output: ${OUTPUT}, wanted: $(cat ./cmd/ko/test/kodata/kenobi) + exit 1 + fi + if [[ ! "${OUTPUT}" =~ "$(cat ./cmd/ko/test/kodata/HEAD)" ]]; then + echo Mismatched output: ${OUTPUT}, wanted: $(cat ./cmd/ko/test/kodata/HEAD) + exit 1 + fi + +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) }