knative-extensions / reconciler-test

Behaviour driven reconciler testing framework.
Apache License 2.0
29 stars 38 forks source link

Cannot publish images on MacOS host #276

Open aliok opened 2 years ago

aliok commented 2 years ago

I am running some reconciler tests (specifically, the ones in Knative Eventing) on my MacOS machine.

The framework tries to do ko publish: https://github.com/knative-sandbox/reconciler-test/blob/be32f9c185c5e5596c24c7a70831fe15032d6f81/pkg/images/ko.go#L25

2022/01/12 15:03:03 failed to publish images: error building "ko://knative.dev/reconciler-test/cmd/eventshub": no child with platform darwin/amd64 in index gcr.io/distroless/static:nonroot

When I pass a PLATFORM=linux/amd64 env var, this time I get this:

2022/01/12 15:04:01 error creating builder: error setting up builder options: cannot use --platform with GOOS="darwin"

...and, I cannot set GOOS env var to my call for test as it doesn't make sense.

aliok commented 2 years ago

As a workaround, what I did locally is, I change the cmd function here: https://github.com/knative-sandbox/reconciler-test/blob/be32f9c185c5e5596c24c7a70831fe15032d6f81/pkg/images/cmd.go#L26-L31

func cmd(cmdLine string) *exec.Cmd {
    cmdSplit := strings.Split(cmdLine, " ")
    cmd := cmdSplit[0]
    args := cmdSplit[1:]
    c := exec.Command(cmd, args...)
    c.Env = os.Environ()
    c.Env = append(c.Env, "GOOS=linux")
    c.Env = append(c.Env, "CGO_ENABLED=0")
    c.Stderr = os.Stdout // Pipe the stderr in stdout
    return c
}

I also removed the PLATFORM env var.

aliok commented 2 years ago

Why CGO_ENABLED=0? I was having this issue due to cross compilation: https://github.com/golang/go/issues/22510

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 90 days with no activity. It will automatically close after 30 more days of inactivity. Reopen the issue with /reopen. Mark the issue as fresh by adding the comment /remove-lifecycle stale.

aliok commented 1 month ago

I bumped into a similar issue today. This time with an Apple Silicon machine:

logger.go:130: 2024-09-19T12:00:12.656+0300 DEBUG   ko/cmd.go:55    2024/09/19 12:00:12 Using base gcr.io/distroless/static:nonroot@sha256:dcd3f1f09adef5689088c9c4d96a8d98c889d8281d3946145074f89eafe7e1af for knative.dev/reconciler-test/cmd/eventshub   {"test": "TestIntegration"}
    logger.go:130: 2024-09-19T12:00:12.681+0300 DEBUG   ko/cmd.go:55    Error: failed to publish images: error building "ko://knative.dev/reconciler-test/cmd/eventshub": no matching platforms in base image index {"test": "TestIntegration"}
    logger.go:130: 2024-09-19T12:00:12.703+0300 DEBUG   ko/cmd.go:55    2024/09/19 12:00:12 error during command execution:failed to publish images: error building "ko://knative.dev/reconciler-test/cmd/eventshub": no matching platforms in base image index {"test": "TestIntegration"}
...
    logger.go:130: 2024-09-19T12:01:29.025+0300 WARN    environment/images.go:100   Ko publish failed, using image directly {"test": "TestIntegration", "error": "ko publish failed: exit status 1 -- command: [\"go\" \"run\" \"github.com/google/ko@v0.11.2\" \"publish\" \"-B\" \"knative.dev/reconciler-test/cmd/eventshub\"]", "image": "knative.dev/reconciler-test/cmd/eventshub"}
aliok commented 1 month ago

Ok, this time, I don't change the vendored reconciler-test code.

Instead,