-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
dockerfile: arg for controlling go build flags #3994
Conversation
This introduces a new `make test-race` target, which will compile buildkitd using the `go build -race` flag, which is useful for detecting data races. Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
here's a sample run against a specific test:
which replicates a data race:
|
@@ -34,6 +34,10 @@ clean: | |||
test: | |||
./hack/test integration gateway dockerfile | |||
|
|||
.PHONY: test-race | |||
test-race: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this new target is overkill, and it's sufficient to just indicate the new CGO_ENABLED=1 BUILDFLAGS="-race"
envs in the CONTRIBUTING.md?
Adding this to all PRs might be overkill, but perhaps there's a limited number of integration tests that could be called via github actions (once the existing data races are fixed, see #3862 for instance)? |
Dockerfile
Outdated
ARG GO_RACE_ENABLED | ||
RUN --mount=target=. --mount=target=/root/.cache,type=cache \ | ||
--mount=target=/go/pkg/mod,type=cache \ | ||
--mount=source=/tmp/.ldflags,target=/tmp/.ldflags,from=buildkit-version \ | ||
CGO_ENABLED=0 xx-go build -ldflags "$(cat /tmp/.ldflags) -extldflags '-static'" -tags "osusergo netgo static_build seccomp ${BUILDKITD_TAGS}" -o /usr/bin/buildkitd ./cmd/buildkitd && \ | ||
xx-verify --static /usr/bin/buildkitd | ||
CGO_ENABLED="$GO_RACE_ENABLED" xx-go build $(if [ "$GO_RACE_ENABLED" != "0" ]; then echo -race; fi) -ldflags "$(cat /tmp/.ldflags) -extldflags '-static'" -tags "osusergo netgo static_build seccomp ${BUILDKITD_TAGS}" -o /usr/bin/buildkitd ./cmd/buildkitd && \ | ||
if [ "$GO_RACE_ENABLED" = "0" ]; then xx-verify --static /usr/bin/buildkitd; fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a generic name for this, maybe BUILDFLAGS
empty by default? Might be useful in the future. Same for CGO_ENABLED
defaulting to 0
or we could detect if -race
is being passed and set the right value?
ARG BUILDFLAGS
ARG CGO_ENABLED=0
RUN --mount=target=. --mount=target=/root/.cache,type=cache \
--mount=target=/go/pkg/mod,type=cache \
--mount=source=/tmp/.ldflags,target=/tmp/.ldflags,from=buildkit-version \
xx-go build ${BUILDFLAGS} -ldflags "$(cat /tmp/.ldflags) -extldflags '-static'" -tags "osusergo netgo static_build seccomp ${BUILDKITD_TAGS}" -o /usr/bin/buildkitd ./cmd/buildkitd && \
xx-verify --static /usr/bin/buildkitd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea; I also introduced a VERIFYFLAGS
which is used to prevent the xx-verify --static ...
call, by explicitly doing export VERIFYFLAGS=""
(since --race
requires cgo which is not static).
If there's a use-case for allowing users to change the VERIFYFLAGS
, we could make the bash code allow users to set it (and maybe error out if it contains -static
).
c63fb17
to
a92c55f
Compare
This introduces new `BUILDFLAGS`, `VERIFYFLAGS`, and `CGO_ENABLED` build-args, which can be used to change how buildkitd is compiled. This, for example, can be used to enable the go data race detector during integration testing: CGO_ENABLED=1 BUILDFLAGS="-race" TESTFLAGS="-v -test.run=TestClientGatewayIntegration/TestClientGatewaySolve" TESTPKGS=./client ./hack/test integration This additionally introduces a new `make test-race` target, which simplifies how to run all tests with the race detector. Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
This introduces new
BUILDFLAGS
,VERIFYFLAGS
, andCGO_ENABLED
build-args,which can be used to change how buildkitd is compiled.
This, for example, can be used to enable the go data race detector during
integration testing:
This additionally introduces a new
make test-race
target, whichsimplifies how to run all tests with the race detector.
Signed-off-by: Alex Couture-Beil alex@earthly.dev