Skip to content

Commit

Permalink
Run the hello test on multiple architectures (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmoor authored Oct 23, 2020
1 parent d9cc0ca commit cde2582
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/kind-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
66 changes: 52 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 12 additions & 3 deletions cmd/ko/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"flag"
"io/ioutil"
"log"
"os"
Expand All @@ -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)
Expand All @@ -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
}
}
41 changes: 38 additions & 3 deletions pkg/publish/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package publish
import (
"fmt"
"log"
"os"
"strings"

"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit cde2582

Please sign in to comment.