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

Build fails on Mac #46987

Open
nivbend opened this issue Dec 25, 2023 · 6 comments
Open

Build fails on Mac #46987

nivbend opened this issue Dec 25, 2023 · 6 comments
Labels
kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/more-info-needed status/0-triage

Comments

@nivbend
Copy link

nivbend commented Dec 25, 2023

Description

Seems that ever since #44210 was merged in 24.0.0 build on Mac machines fail due to the missing goInChroot function.

Reproduce

main.go:

package main

import (
	"fmt"

	"github.com/docker/docker/layer"
)

func main() {
	var v layer.DiffID
	_ = v
	fmt.Println("OK")
}
$ GOOS=darwin go build main.go
# github.com/docker/docker/pkg/chrootarchive
../../../go/pkg/mod/github.com/docker/docker@v24.0.7+incompatible/pkg/chrootarchive/archive_unix.go:31:8: undefined: goInChroot
../../../go/pkg/mod/github.com/docker/docker@v24.0.7+incompatible/pkg/chrootarchive/archive_unix.go:53:8: undefined: goInChroot
../../../go/pkg/mod/github.com/docker/docker@v24.0.7+incompatible/pkg/chrootarchive/diff_unix.go:45:8: undefined: goInChroot

But on Linux it works just fine:

$ GOOS=linux go run main.go
OK

Expected behavior

Project should compile on Darwin like it did before.

docker version

Not relevant, it's a build issue.

docker info

Not relevant, it's a build issue.

Additional Info

Current workaround is to downgrade to v23:

replace github.com/docker/docker => github.com/docker/docker v23.0.8+incompatible
@nivbend nivbend added kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. status/0-triage labels Dec 25, 2023
@nivbend
Copy link
Author

nivbend commented Dec 25, 2023

I see this was fixed by #45724 and #46094. Maybe these could be backported to v24 until v25 goes out of beta?

@thaJeztah
Copy link
Member

Do you have more information how this package is used in your code-base on macOS? While those linked PRs fix the compile issue, those packages are intended for internal use in the daemon, and never designed to be used on macOS, so I'm curious how this code ended up in macOS code in your project.

@thaJeztah thaJeztah added kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/more-info-needed and removed kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. labels Dec 27, 2023
@elliotthill
Copy link

I'm also failing to compile on Mac

main.go (code from https://pkg.go.dev/github.com/docker/docker/client#section-readme)

package main

import (
	"context"
	"fmt"

	"github.com/docker/docker/api/types/container"
	"github.com/docker/docker/client"

)

func main() {
	cli, err := client.NewClientWithOpts(client.FromEnv)
	if err != nil {
		panic(err)
	}

	containers, err := cli.ContainerList(context.Background(), container.ListOptions{})
	if err != nil {
		panic(err)
	}

	for _, ctr := range containers {
		fmt.Printf("%s %s\n", ctr.ID, ctr.Image)
	}
}
> go run .
# github.com/docker/docker/client
../../../go/pkg/mod/github.com/docker/docker@v26.0.1-0.20240416134649-b7c059886c08+incompatible/client/errors.go:28:16: undefined: errors.As
../../../go/pkg/mod/github.com/docker/docker@v26.0.1-0.20240416134649-b7c059886c08+incompatible/client/request.go:127:14: undefined: errors.Is
../../../go/pkg/mod/github.com/docker/docker@v26.0.1-0.20240416134649-b7c059886c08+incompatible/client/request.go:129:14: undefined: errors.Is
../../../go/pkg/mod/github.com/docker/docker@v26.0.1-0.20240416134649-b7c059886c08+incompatible/client/request.go:153:13: undefined: errors.Is

I tried installing from head

go get github.com/docker/docker/errdefs@master
>go version
go version go1.21.9 darwin/amd64

There is a solution posted here:
golang/go#31370

go get github.com/docker/docker/errdefs@master

This also doesn't help the issue. I guess I am missing errdefs still?

> ls pkgsets/go1.21.9/global/pkg/mod/g...le/errdefs
defs.go			helpers.go		http_helpers.go		is.go
doc.go			helpers_test.go		http_helpers_test.go

There are some files in there, am I missing any? If so how do I get these missing files?

@thaJeztah
Copy link
Member

Tried reproducing, but didn't get that error; I should note that in my flow below, I didn't specify versions of indirect dependencies, and let go mod tidy pick whatever it found; generally (with github.com/docker/docker not yet being a go.mod, and not yet being a go module), I'd recommend matching the versions that are specified in the vendor.mod for the version your'e using; in my case, v26.0.1; https://github.com/moby/moby/blob/v26.0.1/vendor.mod#L5-L227

go version
go version go1.22.1 darwin/arm64

mkdir repro-46987 && cd repro-46987
go mod init myproject

cat > main.go <<-'EOF'
package main

import (
	"context"
	"fmt"

	"github.com/docker/docker/api/types/container"
	"github.com/docker/docker/client"

)

func main() {
	cli, err := client.NewClientWithOpts(client.FromEnv)
	if err != nil {
		panic(err)
	}

	containers, err := cli.ContainerList(context.Background(), container.ListOptions{})
	if err != nil {
		panic(err)
	}

	for _, ctr := range containers {
		fmt.Printf("%s %s\n", ctr.ID, ctr.Image)
	}
}
EOF

gofmt -w main.go
go get github.com/docker/docker@v26.0.1+incompatible
go mod tidy

go run main.go
e1698b649a0714d0425f48aac4cb3c19194093b08a9d9381da6c053dafa19563 nginx:alpine

@elliotthill
Copy link

Your flow doesn't reproduce the issue and works, so thanks! The problem must be user error on my part.

@shuheiktgw
Copy link

Just FYI, but I ran into the same errors with @elliotthill and realized github.com/pkg/errors v0.8.1 was specified in my go.mod's required section. If I used github.com/pkg/errors v0.9.1 instead everything worked fine 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/more-info-needed status/0-triage
Projects
None yet
Development

No branches or pull requests

4 participants