Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot publish images on MacOS host #276

Open
aliok opened this issue Jan 12, 2022 · 5 comments
Open

Cannot publish images on MacOS host #276

aliok opened this issue Jan 12, 2022 · 5 comments

Comments

@aliok
Copy link
Member

aliok commented Jan 12, 2022

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
Copy link
Member Author

aliok commented Jan 12, 2022

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
Copy link
Member Author

aliok commented Jan 12, 2022

Why CGO_ENABLED=0? I was having this issue due to cross compilation: golang/go#22510

@github-actions
Copy link

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.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 13, 2022
@aliok
Copy link
Member Author

aliok commented Sep 19, 2024

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/[email protected]\" \"publish\" \"-B\" \"knative.dev/reconciler-test/cmd/eventshub\"]", "image": "knative.dev/reconciler-test/cmd/eventshub"}

@aliok aliok reopened this Sep 19, 2024
@aliok
Copy link
Member Author

aliok commented Sep 19, 2024

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

Instead,

  • Run the command manually: go run github.com/google/[email protected] publish -B knative.dev/reconciler-test/cmd/eventshub
  • Get the image output: docker.io/aliok/eventshub@sha256:8d039adcf7a375adeab0954786fbb9da615973c09001de87a3a6dfc19fae2b78 or docker.io/aliok/eventshub:latest
  • Use that temporarily (no checking in) in the test setup:
        ctx, env := global.Environment(
                 ...
		// TODO: remove
		eventshub.WithCustomImage("docker.io/aliok/eventshub:latest"),
	)

@github-actions github-actions bot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant