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

Does not compile in docker under Apple Silicon #33

Closed
halostatue opened this issue Apr 7, 2022 · 11 comments · Fixed by #44
Closed

Does not compile in docker under Apple Silicon #33

halostatue opened this issue Apr 7, 2022 · 11 comments · Fixed by #44
Labels

Comments

@halostatue
Copy link

❯ bin/dockerized --compile=docker
Compiling dockerized...
go: downloading github.com/docker/compose/v2 v2.3.3
go: downloading github.com/hashicorp/go-version v1.3.0
go: downloading github.com/mitchellh/mapstructure v1.4.3
go: downloading github.com/opencontainers/go-digest v1.0.0
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/imdario/mergo v0.3.12
go: downloading github.com/docker/docker v20.10.3-0.20220121014307-40bb9831756f+incompatible
go: downloading github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
go: downloading github.com/spf13/pflag v1.0.5
go: downloading github.com/theupdateframework/notary v0.6.1
go: downloading github.com/buger/goterm v1.0.4
go: downloading github.com/containerd/containerd v1.6.1
go: downloading github.com/docker/buildx v0.7.1
go: downloading github.com/hashicorp/go-multierror v1.1.1
go: downloading github.com/moby/buildkit v0.9.1-0.20211019185819-8778943ac3da
go: downloading github.com/opencontainers/image-spec v1.0.2
go: downloading github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b
go: downloading golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
go: downloading golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
go: downloading github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c
go: downloading github.com/morikuni/aec v1.0.0
go: downloading github.com/containerd/console v1.0.3
go: downloading github.com/AlecAivazis/survey/v2 v2.3.2
go: downloading github.com/golang/mock v1.6.0
go: downloading google.golang.org/grpc v1.45.0
go: downloading github.com/klauspost/compress v1.13.5
go: downloading github.com/opencontainers/runc v1.1.0
go: downloading golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
go: downloading github.com/moby/sys/signal v0.6.0
go: downloading github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415
go: downloading github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412
go: downloading golang.org/x/net v0.0.0-20211216030914-fe4d6282115f
go: downloading github.com/moby/sys/symlink v0.2.0
go: downloading golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b
go: downloading github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb
go: downloading github.com/gogo/protobuf v1.3.2
go: downloading github.com/docker/go-metrics v0.0.1
go: downloading github.com/prometheus/client_golang v1.11.0
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/prompt/prompt.go:20:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/progress/writer.go:24:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:26:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build_buildkit.go:26:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:27:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:28:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:29:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/prompt/prompt_mock.go:10:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build_classic.go:40:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/api/labels.go:22:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/pkg/archive/archive.go:26:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:32:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/command/image/build/dockerignore.go:8:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:33:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:34:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/pkg/jsonmessage/jsonmessage.go:11:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/pkg/jsonmessage/jsonmessage.go:12:2: zip: not a valid zip file
/go/pkg/mod/github.com/distribution/distribution/[email protected]/digestset/set.go:9:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/api/types/registry/registry.go:7:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/pkg/idtools/idtools_unix.go:17:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]/counter.go:3:8: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]/handler.go:7:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]/sockets/proxy.go:9:2: zip: not a valid zip file
/go/pkg/mod/golang.org/x/[email protected]/ssh/terminal/terminal.go:14:2: zip: not a valid zip file
/go/pkg/mod/github.com/containerd/[email protected]/errdefs/grpc.go:24:2: zip: not a valid zip file
/go/pkg/mod/github.com/containerd/[email protected]/errdefs/grpc.go:25:2: zip: not a valid zip file
Failed to compile dockerized

Compiling on the host works just fine.

@boukeversteegh
Copy link
Contributor

Hi @halostatue ! Finally managed to fix the CI pipeline, which was holding back a fix for this.

I've applied your suggestion to set GOARCH=ARM64. This is passed onto the docker GO environment which compiles dockerized. However, I'm not sure that it will now compile correctly.

Could you have a try, with the latest version?

git clone https://github.com/datastack-net/dockerized.git
bin/dockerized --compile

@halostatue
Copy link
Author

Will do.

@halostatue
Copy link
Author

No luck:

bin/dockerized --compile
Compiling dockerized...
go: downloading github.com/compose-spec/compose-go v1.1.0
go: downloading github.com/docker/compose/v2 v2.3.3
go: downloading github.com/fatih/color v1.13.0
go: downloading github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
go: downloading github.com/docker/cli v20.10.3-0.20210702143511-f782d1355eff+incompatible
go: downloading github.com/docker/distribution v2.8.1+incompatible
go: downloading github.com/docker/hub-tool v0.4.4
go: downloading github.com/hashicorp/go-version v1.3.0
go: downloading github.com/distribution/distribution/v3 v3.0.0-20210316161203-a01c71e2477e
go: downloading github.com/docker/go-connections v0.4.0
go: downloading github.com/mitchellh/mapstructure v1.4.3
go: downloading github.com/opencontainers/go-digest v1.0.0
go: downloading golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
go: downloading github.com/mattn/go-colorable v0.1.12
go: downloading github.com/mattn/go-isatty v0.0.14
go: downloading golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/sirupsen/logrus v1.8.1
go: downloading github.com/docker/go-units v0.4.0
go: downloading github.com/imdario/mergo v0.3.12
go: downloading github.com/mattn/go-shellwords v1.0.12
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading github.com/spf13/pflag v1.0.5
go: downloading github.com/docker/docker v20.10.3-0.20220121014307-40bb9831756f+incompatible
go: downloading github.com/spf13/cobra v1.3.0
go: downloading github.com/theupdateframework/notary v0.6.1
go: downloading github.com/buger/goterm v1.0.4
go: downloading github.com/containerd/containerd v1.6.1
go: downloading github.com/docker/buildx v0.7.1
go: downloading github.com/hashicorp/go-multierror v1.1.1
go: downloading github.com/moby/buildkit v0.9.1-0.20211019185819-8778943ac3da
go: downloading github.com/opencontainers/image-spec v1.0.2
go: downloading github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b
go: downloading github.com/google/uuid v1.2.0
go: downloading github.com/xeipuuv/gojsonschema v1.2.0
go: downloading github.com/fvbommel/sortorder v1.0.2
go: downloading github.com/morikuni/aec v1.0.0
go: downloading github.com/containerd/console v1.0.3
go: downloading github.com/AlecAivazis/survey/v2 v2.3.2
go: downloading github.com/golang/mock v1.6.0
go: downloading google.golang.org/grpc v1.45.0
go: downloading github.com/klauspost/compress v1.13.5
go: downloading github.com/opencontainers/runc v1.1.0
go: downloading golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
go: downloading github.com/moby/sys/signal v0.6.0
go: downloading github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
go: downloading github.com/tonistiigi/fsutil v0.0.0-20210818161904-4442383b5028
go: downloading github.com/tonistiigi/opentelemetry-go-contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.0.0-20210714055410-d010b05b4939
go: downloading go.opentelemetry.io/contrib v0.21.0
go: downloading go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.3.0
go: downloading go.opentelemetry.io/otel v1.3.0
go: downloading go.opentelemetry.io/otel/sdk v1.3.0
go: downloading go.opentelemetry.io/otel/trace v1.3.0
go: downloading golang.org/x/net v0.0.0-20211216030914-fe4d6282115f
go: downloading github.com/gofrs/flock v0.8.0
go: downloading golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
go: downloading github.com/docker/docker-credential-helpers v0.6.4
go: downloading github.com/moby/sys/symlink v0.2.0
go: downloading google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa
go: downloading github.com/gogo/protobuf v1.3.2
go: downloading github.com/golang/protobuf v1.5.2
go: downloading github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
go: downloading github.com/gogo/googleapis v1.4.0
go: downloading github.com/containerd/typeurl v1.0.2
go: downloading go.opentelemetry.io/proto/otlp v0.11.0
go: downloading google.golang.org/protobuf v1.27.1
go: downloading github.com/containerd/continuity v0.2.2
go: downloading github.com/grpc-ecosystem/grpc-gateway v1.16.0
go: downloading github.com/tonistiigi/units v0.0.0-20180711220420-6950e57a87ea
go: downloading github.com/tonistiigi/vt100 v0.0.0-20210615222946-8066bb97264f
go: downloading golang.org/x/text v0.3.7
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/prompt/prompt.go:20:2: zip: not a valid zip file
/go/pkg/mod/github.com/tonistiigi/[email protected]/diskwriter_unix.go:9:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:26:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build_buildkit.go:26:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:27:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:28:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build.go:29:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/manifest/types/types.go:6:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/manifest/types/types.go:7:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/manifest/types/types.go:8:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/client/container_commit.go:9:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/errdefs/http_helpers.go:8:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/registry/client/fetcher.go:14:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/registry/client/client.go:13:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/trust/trust.go:17:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/trust/trust.go:18:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/trust/trust.go:19:2: zip: not a valid zip file
/go/pkg/mod/github.com/compose-spec/[email protected]/loader/loader.go:38:2: zip: not a valid zip file
/go/pkg/mod/github.com/moby/[email protected]/frontend/gateway/grpcclient/client.go:16:2: zip: not a valid zip file
/go/pkg/mod/github.com/moby/[email protected]/api/services/control/control.pb.go:9:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/api/types/swarm/runtime/plugin.pb.go:16:8: zip: not a valid zip file
/go/pkg/mod/github.com/moby/[email protected]/solver/pb/ops.pb.go:13:2: zip: not a valid zip file
/go/pkg/mod/github.com/moby/[email protected]/api/services/control/control.pb.go:11:2: zip: not a valid zip file
/go/pkg/mod/go.opentelemetry.io/proto/[email protected]/collector/trace/v1/trace_service.pb.gw.go:16:2: zip: not a valid zip file
/go/pkg/mod/google.golang.org/[email protected]/internal/status/status.go:34:2: zip: not a valid zip file
/go/pkg/mod/google.golang.org/[email protected]/internal/status/status.go:35:2: zip: not a valid zip file
/go/pkg/mod/github.com/moby/[email protected]/frontend/gateway/grpcclient/client.go:18:2: zip: not a valid zip file
/go/pkg/mod/github.com/moby/[email protected]/api/services/control/control.pb.go:12:2: zip: not a valid zip file
/go/pkg/mod/go.opentelemetry.io/proto/[email protected]/collector/trace/v1/trace_service.pb.gw.go:18:2: zip: not a valid zip file
/go/pkg/mod/go.opentelemetry.io/proto/[email protected]/collector/trace/v1/trace_service.pb.gw.go:19:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/compose/[email protected]/pkg/compose/build_classic.go:40:2: zip: not a valid zip file
/go/pkg/mod/github.com/distribution/distribution/[email protected]/digestset/set.go:9:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/pkg/idtools/idtools_unix.go:17:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/command/cli.go:35:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/flags/common.go:12:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/trust/trust.go:27:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/trust/trust.go:28:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/trust/trust.go:29:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/trust/trust.go:30:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/trust/trust.go:31:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/trust/trust.go:32:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/trust/trust.go:33:2: zip: not a valid zip file
/go/pkg/mod/github.com/docker/[email protected]+incompatible/cli/trust/trust.go:34:2: zip: not a valid zip file
/go/pkg/mod/github.com/compose-spec/[email protected]/schema/schema.go:24:2: zip: not a valid zip file
/go/pkg/mod/github.com/moby/[email protected]/session/grpc.go:13:2: zip: not a valid zip file
/go/pkg/mod/go.opentelemetry.io/otel/exporters/otlp/[email protected]/internal/tracetransform/instrumentation.go:18:2: zip: not a valid zip file
/go/pkg/mod/go.opentelemetry.io/otel/exporters/otlp/[email protected]/internal/tracetransform/attribute.go:19:2: zip: not a valid zip file
/go/pkg/mod/go.opentelemetry.io/otel/exporters/otlp/[email protected]/internal/tracetransform/span.go:21:2: zip: not a valid zip file
/go/pkg/mod/github.com/moby/[email protected]/util/bklog/log.go:7:2: zip: not a valid zip file
/go/pkg/mod/github.com/moby/[email protected]/session/auth/auth.go:12:2: zip: not a valid zip file
/go/pkg/mod/github.com/moby/[email protected]/util/sshutil/keyscan.go:9:2: zip: not a valid zip file
/go/pkg/mod/github.com/compose-spec/[email protected]/types/project.go:27:2: zip: not a valid zip file
Failed to compile dockerized

@boukeversteegh
Copy link
Contributor

Strange. I'm suspecting it has to do with the volume mount which caches the go packages. Also due to #34 .

Could you try removing the cache volume from bin/dockerized (line 80) and try again?

-v "${DOCKERIZED_ROOT}/.cache:/go/pkg" \

   if [ "${DOCKERIZED_COMPILE:-docker}" == "docker" ]; then
     docker run \
       --rm \
       --entrypoint=go \
       -e "GOOS=${DOCKERIZED_COMPILE_GOOS}" \
       -e "GOARCH=${DOCKERIZED_COMPILE_GOARCH}" \
       -v "${DOCKERIZED_ROOT}:/src" \
       -v "${DOCKERIZED_ROOT}/build:/build" \
-      -v "${DOCKERIZED_ROOT}/.cache:/go/pkg" \
       -w //src \
       "golang:1.17.8" \
       build -ldflags "$GO_LDFLAGS" -o //build/ .

@halostatue
Copy link
Author

That worked. Related to that, I have had to sudo rm -rf ~/.cache/go to clean things up on that. This isn’t a surprise because the native golang:1.17.8 runs everything as root, which means that the permissions get wonky for any shared environment. I’m not sure how to fix that without creating an intermediary Docker image that creates a non-root user and inherits from golang:1.17.8.

@halostatue
Copy link
Author

One thing: ./build/dockerized is not executable after building in Docker.

@boukeversteegh
Copy link
Contributor

That worked. Related to that, I have had to sudo rm -rf ~/.cache/go to clean things up on that. This isn’t a surprise because the native golang:1.17.8 runs everything as root, which means that the permissions get wonky for any shared environment. I’m not sure how to fix that without creating an intermediary Docker image that creates a non-root user and inherits from golang:1.17.8.

Thanks for trying!

I wonder if the problem isn't rather that docker itself runs as root. Someone at hackernews also pointed out that a lack of user-mapping can cause problems with file ownership: https://news.ycombinator.com/item?id=30629926 .

What are the file permissions of the binary on your system? i.e. ls -l build/dockerized?

@halostatue
Copy link
Author

I’ll have to try a bit later. I did chmod +x and things seemed to work after that, so it was certainly missing the executable bit.

github-actions bot pushed a commit that referenced this issue Apr 22, 2022
## [2.19.4](v2.19.3...v2.19.4) (2022-04-22)

### Bug Fixes

* Does not compile in docker under Apple Silicon ([94928c6](94928c6)), closes [#33](#33)
@github-actions
Copy link

🎉 This issue has been resolved in version 2.19.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@boukeversteegh
Copy link
Contributor

Thanks for your testing, it helped hash out a solution. Turns out on Ubuntu the binary was also owned by root, but with 755 permissions, so I hadn't noticed it.

I was able to work around the issue by:

  • using a docker volume instead of a mounted directory to cache the go packages
  • chowning and chmodding the binary after compilation

Please try out the new release if you can :-)

@halostatue
Copy link
Author

Looks good except for the other issue I have open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants