Skip to content

Conversation

@thaJeztah
Copy link
Member

We include this in the moby/moby repo, but it looks like we didn't for the CLI.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added this to the 28.0.0 milestone Sep 2, 2024
@thaJeztah thaJeztah self-assigned this Sep 2, 2024
@thaJeztah thaJeztah mentioned this pull request Sep 2, 2024
1 task
@thaJeztah
Copy link
Member Author

Heh. Looks like alpine doesn't support v5 anymore?

 > [build-alpine 1/1] RUN xx-apk add --no-cache musl-dev gcc:
0.064 fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/main/armel/APKINDEX.tar.gz
0.237 fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/community/armel/APKINDEX.tar.gz
0.237 WARNING: fetching https://dl-cdn.alpinelinux.org/alpine/v3.20/main: No such file or directory
0.264 WARNING: fetching https://dl-cdn.alpinelinux.org/alpine/v3.20/community: No such file or directory
0.265 ERROR: unable to select packages:
0.265   alpine-keys (no such package):
0.265     required by: world[alpine-keys]
------
Dockerfile:25
--------------------
  23 |     ARG TARGETPLATFORM
  24 |     # gcc is installed for libgcc only
  25 | >>> RUN xx-apk add --no-cache musl-dev gcc

@codecov-commenter
Copy link

codecov-commenter commented Sep 2, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Dockerfile Outdated
Comment on lines 24 to 25
# gcc is installed for libgcc only
RUN xx-apk add --no-cache musl-dev gcc
RUN xx-apk add --no-cache musl-dev libgcc
Copy link
Member Author

@thaJeztah thaJeztah Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting; this is causing failures on arm/v6 and arm/v7; it looks like we're explicitly disabling CGO (CGO_ENABLED=0), but then try to compile with -buildmode=pie - seems like something is off somewhere.

 > [build-plugins 1/1] RUN --mount=ro --mount=type=cache,target=/root/.cache     xx-go --wrap &&     TARGET=/out ./scripts/build/plugins e2e/cli-plugins/plugins/*:
0.127 Building static docker-helloworld
0.127 + CGO_ENABLED=0
0.127 + GO111MODULE=auto
0.127 + go build -o /out/plugins-linux-arm/docker-helloworld -tags ' osusergo' -ldflags ' -X "github.com/docker/cli/cli/version.GitCommit=5c123b1" -X "github.com/docker/cli/cli/version.BuildTime=2024-09-02T13:52:17Z" -X "github.com/docker/cli/cli/version.Version=pr-5387" -extldflags -static' -buildmode=pie github.com/docker/cli/cli-plugins/examples/helloworld
0.135 -buildmode=pie requires external (cgo) linking, but cgo is not enabled

The -buildmode=pie is probably set through GO_BUILDMODE ?

source ./scripts/build/.variables
for p in cli-plugins/examples/* "$@" ; do
[ -d "$p" ] || continue
n=$(basename "$p")
TARGET_PLUGIN="$(dirname "${TARGET}")/plugins-${GOOS}-${GOARCH}/docker-${n}"
mkdir -p "$(dirname "${TARGET_PLUGIN}")"
echo "Building $GO_LINKMODE $(basename "${TARGET_PLUGIN}")"
(set -x ; CGO_ENABLED=0 GO111MODULE=auto go build -o "${TARGET_PLUGIN}" -tags "${GO_BUILDTAGS}" -ldflags "${GO_LDFLAGS}" ${GO_BUILDMODE} "github.com/docker/cli/${p}")
done

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, so the .variables sets CGO_ENABLED=1 on arm;

if [ -z "$CGO_ENABLED" ]; then
case "$(go env GOOS)" in
linux)
case "$(go env GOARCH)" in
amd64|arm64|arm|s390x|riscv64)
CGO_ENABLED=1
;;
*)
CGO_ENABLED=0
;;
esac
;;

And if enabled, it sets -buildmode=pie;

if [ "$CGO_ENABLED" = "1" ] && [ "$(go env GOOS)" != "windows" ]; then
case "$(go env GOARCH)" in
mips*|ppc64)
# pie build mode is not supported on mips architectures
;;
*)
GO_BUILDMODE="-buildmode=pie"
;;
esac
fi

So that looks to be conflicting with the hard-coded CGO_ENABLED=0 in this script.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly; doesn't fail on other PRs - wondering now what's causing that issue;

#18 [build-plugins 1/1] RUN --mount=ro --mount=type=cache,target=/root/.cache     xx-go --wrap &&     TARGET=/out ./scripts/build/plugins e2e/cli-plugins/plugins/*
#18 0.126 Building static docker-helloworld
#18 0.126 + CGO_ENABLED=0
#18 0.126 + GO111MODULE=auto
#18 0.126 + go build -o /out/plugins-linux-arm/docker-helloworld -tags ' osusergo' -ldflags ' -X "github.com/docker/cli/cli/version.GitCommit=0cebca4" -X "github.com/docker/cli/cli/version.BuildTime=2024-09-02T14:50:36Z" -X "github.com/docker/cli/cli/version.Version=pr-5389" -extldflags -static' -buildmode=pie github.com/docker/cli/cli-plugins/examples/helloworld
#18 19.75 # github.com/docker/cli/cli-plugins/examples/helloworld
#18 19.75 loadinternal: cannot find runtime/cgo
#18 19.85 Building static docker-badmeta
#18 19.85 + CGO_ENABLED=0
#18 19.85 + GO111MODULE=auto


echo "Building $GO_LINKMODE $(basename "${TARGET_PLUGIN}")"
(set -x ; CGO_ENABLED=0 GO111MODULE=auto go build -o "${TARGET_PLUGIN}" -tags "${GO_BUILDTAGS}" -ldflags "${GO_LDFLAGS}" ${GO_BUILDMODE} "github.com/docker/cli/${p}")
(set -x ; CGO_ENABLED=0 GO111MODULE=auto go build -o "${TARGET_PLUGIN}" -tags "${GO_BUILDTAGS}" -ldflags "${GO_LDFLAGS}" "github.com/docker/cli/${p}")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, so this fixed the plugins being compiled, but looks like the binary itself does still require gcc, not just libgcc ?

 > [build 2/2] RUN --mount=type=bind,target=.,ro     --mount=type=cache,target=/root/.cache     --mount=type=tmpfs,target=cli/winresources     xx-go --wrap &&     TARGET=/out ./scripts/build/binary &&     xx-verify $([ "static" = "static" ] && echo "--static") /out/docker:
0.113 + go build -o /out/docker-linux-arm-v6 -tags ' osusergo pkcs11' -ldflags ' -X "github.com/docker/cli/cli/version.GitCommit=7e15277994" -X "github.com/docker/cli/cli/version.BuildTime=2024-09-02T14:39:44Z" -X "github.com/docker/cli/cli/version.Version=pr-5388" -extldflags -static' '-buildmode=pie' github.com/docker/cli/cmd/docker
29.74 # github.com/docker/cli/cmd/docker
29.74 /usr/local/go/pkg/tool/linux_amd64/link: running armv6-alpine-linux-musleabihf-clang failed: exit status 1
29.74 clang: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
29.74 ld.lld: error: cannot open crtbeginT.o: No such file or directory
29.74 ld.lld: error: unable to find library -lgcc
29.74 ld.lld: error: unable to find library -lgcc_eh
29.74 ld.lld: error: cannot open crtend.o: No such file or directory
29.74 clang: error: linker command failed with exit code 1 (use -v to see invocation)

We include this in the moby/moby repo, but it looks like
we didn't for the CLI.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The comment describes we need gcc for libgcc only, so we may
as well install that.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The `.variables` sets `CGO_ENABLED=1` on arm; https://github.com/docker/cli/blob/b0c41b78d8c80c5f8faa736cf3c74dc31092e443/scripts/build/.variables#L57-L68
And if enabled, it sets `-buildmode=pie`; https://github.com/docker/cli/blob/b0c41b78d8c80c5f8faa736cf3c74dc31092e443/scripts/build/.variables#L79-L88

But that looks to be conflicting with the hard-coded `CGO_ENABLED=0` in
this script.

    > [build-plugins 1/1] RUN --mount=ro --mount=type=cache,target=/root/.cache     xx-go --wrap &&     TARGET=/out ./scripts/build/plugins e2e/cli-plugins/plugins/*:
    0.127 Building static docker-helloworld
    0.127 + CGO_ENABLED=0
    0.127 + GO111MODULE=auto
    0.127 + go build -o /out/plugins-linux-arm/docker-helloworld -tags ' osusergo' -ldflags ' -X "github.com/docker/cli/cli/version.GitCommit=5c123b1" -X "github.com/docker/cli/cli/version.BuildTime=2024-09-02T13:52:17Z" -X "github.com/docker/cli/cli/version.Version=pr-5387" -extldflags -static' -buildmode=pie github.com/docker/cli/cli-plugins/examples/helloworld
    0.135 -buildmode=pie requires external (cgo) linking, but cgo is not enabled

Remove `GO_BUILDMODE` from this script so that we don't try to build
with `-buildmode=pie`.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This reverts commit df2a797.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants