-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Faster K3s Binary Build Option #7805
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
20f9be6
Add local build option
dereknola 1a2a400
Finish build and package steps
dereknola d202b9e
Don't run version for binary check
dereknola b22d949
Add golang caching to builds
dereknola 6ca7bd5
Simplify env
dereknola b754099
Don't download trivy
dereknola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
./.cache | ||
./.dapper | ||
./.trash-cache | ||
./.git/objects/pack | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
ARG GOLANG=golang:1.20.4-alpine3.18 | ||
FROM ${GOLANG} as infra | ||
|
||
ARG http_proxy=$http_proxy | ||
ARG https_proxy=$https_proxy | ||
ARG no_proxy=$no_proxy | ||
ENV http_proxy=$http_proxy | ||
ENV https_proxy=$https_proxy | ||
ENV no_proxy=$no_proxy | ||
|
||
RUN apk -U --no-cache add bash git gcc musl-dev docker vim less file curl wget ca-certificates jq linux-headers \ | ||
zlib-dev tar zip squashfs-tools npm coreutils python3 py3-pip openssl-dev libffi-dev libseccomp libseccomp-dev \ | ||
libseccomp-static make libuv-static sqlite-dev sqlite-static libselinux libselinux-dev zlib-dev zlib-static \ | ||
zstd pigz alpine-sdk binutils-gold btrfs-progs-dev btrfs-progs-static gawk yq \ | ||
&& \ | ||
if [ "$(go env GOARCH)" = "amd64" ]; then \ | ||
apk -U --no-cache add mingw-w64-gcc; \ | ||
fi | ||
|
||
RUN python3 -m pip install awscli | ||
|
||
# this works for both go 1.17 and 1.18 | ||
RUN GOPROXY=direct go install golang.org/x/tools/cmd/goimports@gopls/v0.11.0 | ||
RUN rm -rf /go/src /go/pkg | ||
|
||
RUN if [ "$(go env GOARCH)" = "amd64" ]; then \ | ||
curl -sL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.51.2; \ | ||
fi | ||
|
||
ARG SELINUX=true | ||
ENV SELINUX $SELINUX | ||
ENV STATIC_BUILD true | ||
ENV SRC_DIR=/go/src/github.com/k3s-io/k3s | ||
WORKDIR ${SRC_DIR}/ | ||
|
||
|
||
FROM infra as build | ||
|
||
ARG SKIP_VALIDATE | ||
|
||
COPY ./scripts/ ./scripts | ||
COPY ./go.mod ./go.sum ./main.go ./ | ||
COPY ./manifests ./manifests | ||
RUN mkdir -p bin dist | ||
RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \ | ||
./scripts/download | ||
|
||
COPY ./cmd ./cmd | ||
COPY ./pkg ./pkg | ||
COPY ./tests ./tests | ||
COPY ./.git ./.git | ||
RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \ | ||
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \ | ||
./scripts/build | ||
|
||
COPY ./contrib ./contrib | ||
RUN --mount=type=cache,id=gomod,target=/go/pkg/mod \ | ||
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \ | ||
./scripts/package-cli | ||
|
||
RUN ./scripts/binary_size_check.sh | ||
|
||
FROM scratch as result | ||
ENV SRC_DIR=/go/src/github.com/k3s-io/k3s | ||
COPY --from=build ${SRC_DIR}/dist /dist | ||
COPY --from=build ${SRC_DIR}/bin /bin | ||
COPY --from=build ${SRC_DIR}/build/out /build/out | ||
COPY --from=build ${SRC_DIR}/build/static /build/static | ||
COPY --from=build ${SRC_DIR}/pkg/static /pkg/static | ||
COPY --from=build ${SRC_DIR}/pkg/deploy /pkg/deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This folder contains the bulk of the
.git
~1.6GB size, but is not needed to extract the commit ID or branch when callinggit status
or other git info commands. Ignoring this folder enables a much lower copy of only some 40KB to docker containers and still allows use of thescripts/version.sh
.