Closed RainbowMango closed 2 years ago
@RainbowMango: This request has been marked as needing help from a contributor.
Please ensure the request meets the requirements listed here.
If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help
command.
I found there is make images stage in local-up.sh But there are no make images stage in remote-up can we set the make containers optional ? I guess it will work in private environment but ci pipeline will always costs time
The original intention of hack/local-up-karmada.sh
is to build Karmada from the source.
can we set the make containers optional ?
How to do that?
Maybe we should try to find the root cause first before making any decisions.
to 1: I used to skip the make container in local-up manually
2: You mean Why we do make build binary and put it into docker container faster then we make binary in docker compile context and then put it into docker execution context?
/kind help
how to fasten make images
now the multi-stage docker image build cost too much time, In CI, it takes about 32 minutes,
but before https://github.com/karmada-io/karmada/pull/927 (NOT using multi-stage: just compile karmada components with local environment, and copy it into docker image) it only takes 8 minutes.
@gy95: The label(s) kind/help
cannot be applied, because the repository doesn't have them.
I found there is make images stage in local-up.sh But there are no make images stage in remote-up can we set the make containers optional ? I guess it will work in private environment but ci pipeline will always costs time
I agree with @wuyingjun-lucky. I compare two logs. The longer one build binary package as follows:
Remove above logs they are almost the same.
it will download the image : golang:1.17-alpine3.15 repeatedly in each build
I test building binaries on host (out of docker) as Before. Firstly aggregated-apiserver
spend 27s, while controller-manager
9s (faster much than aggregated-apiserver).
# commit aa39b35dedff7e1feb950f0a7583b480f7bb29ae (HEAD -> master)
➜ time CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags "-X github.com/karmada-io/karmada/pkg/version.gitVersion= -X github.com/karmada-io/karmada/pkg/version.gitCommit=9d0c1fb679690e9fd7bb2a973f8e70e1f8ac57fb -X github.com/karmada-io/karmada/pkg/version.gitTreeState="clean" -X github.com/karmada-io/karmada/pkg/version.buildDate=2022-04-27T08:45:12Z" \
-o karmada-aggregated-apiserver \
cmd/aggregated-apiserver/main.go
________________________________________________________
Executed in 27.30 secs fish external
usr time 131.76 secs 0.20 millis 131.76 secs
sys time 17.43 secs 1.15 millis 17.43 secs
➜ time CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags "-X github.com/karmada-io/karmada/pkg/version.gitVersion= -X github.com/karmada-io/karmada/pkg/version.gitCommit=9d0c1fb679690e9fd7bb2a973f8e70e1f8ac57fb -X github.com/karmada-io/karmada/pkg/version.gitTreeState="clean" -X github.com/karmada-io/karmada/pkg/version.buildDate=2022-04-27T08:45:12Z" \
-o karmada-controller-manager \
cmd/controller-manager/controller-manager.go
________________________________________________________
Executed in 9.34 secs fish external
usr time 32.15 secs 12.76 millis 32.14 secs
sys time 5.66 secs 3.05 millis 5.66 secs
Then build in docker. bothaggregated-apiserver
and controller-manager
spend about 40s(calculate by date
).
# commit cd05ffee6e3f79858147f08454e3c2eac0fbdb30 (HEAD -> master)
➜ karmada git:(master) ✗ time VERSION=latest REGISTRY=swr.ap-southeast-1.myhuaweicloud.com/karmada hack/docker.sh karmada-aggregated-apiserver
Sending build context to Docker daemon 114.4MB
[1/2] STEP 1/7: FROM golang:1.17 AS builder
[1/2] STEP 2/7: WORKDIR /go/src/github.com/karmada-io/karmada
--> Using cache 6ae9f471a8110b2985aea152cdb319005351954aac915ec435349f604bccbba9
--> 6ae9f471a81
[1/2] STEP 3/7: COPY . /go/src/github.com/karmada-io/karmada
--> 6570120c969
[1/2] STEP 4/7: ARG GO_LDFLAGS
--> 4a5780f3285
[1/2] STEP 5/7: RUN date
Fri May 6 14:02:40 UTC 2022 <======== START
--> 33ddbaa6b76
[1/2] STEP 6/7: RUN CGO_ENABLED=0 go build -ldflags "${GO_LDFLAGS}" -o /bin/karmada-aggregated-apiserver cmd/aggregated-apiserver/main.go
--> 7c77f31bef4
[1/2] STEP 7/7: RUN date
Fri May 6 14:03:22 UTC 2022 <======== END: takes 42s
--> b57cd1e7af4
[2/2] STEP 1/3: FROM alpine:3.15.1
[2/2] STEP 2/3: COPY --from=builder /bin/karmada-aggregated-apiserver /bin/karmada-aggregated-apiserver
--> dd2025ea7ca
[2/2] STEP 3/3: CMD ["/bin/karmada-aggregated-apiserver"]
[2/2] COMMIT swr.ap-southeast-1.myhuaweicloud.com/karmada/karmada-aggregated-apiserver:latest
--> 98ae42adff7
Successfully tagged swr.ap-southeast-1.myhuaweicloud.com/karmada/karmada-aggregated-apiserver:latest
98ae42adff74349a19aad2ded6ecbbf488f7e0f1f7de889f923374ff97a14ca8
Successfully built 98ae42adff74
Successfully tagged swr.ap-southeast-1.myhuaweicloud.com/karmada/karmada-aggregated-apiserver:latest
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
________________________________________________________
Executed in 51.00 secs fish external
usr time 355.42 millis 0.21 millis 355.20 millis
sys time 900.51 millis 1.09 millis 899.43 millis
➜ karmada git:(master) ✗
➜ karmada git:(master) ✗ time VERSION=latest REGISTRY=swr.ap-southeast-1.myhuaweicloud.com/karmada hack/docker.sh karmada-controller-manager
Sending build context to Docker daemon 114.4MB
[1/2] STEP 1/7: FROM golang:1.17 AS builder
[1/2] STEP 2/7: WORKDIR /go/src/github.com/karmada-io/karmada
--> Using cache 6ae9f471a8110b2985aea152cdb319005351954aac915ec435349f604bccbba9
--> 6ae9f471a81
[1/2] STEP 3/7: COPY . /go/src/github.com/karmada-io/karmada
--> 977fa38908a
[1/2] STEP 4/7: ARG GO_LDFLAGS
--> be30ab342aa
[1/2] STEP 5/7: RUN date
Fri May 6 14:04:01 UTC 2022 <======== START
--> 4a19032ebb8
[1/2] STEP 6/7: RUN CGO_ENABLED=0 go build -ldflags "$GO_LDFLAGS" -o /bin/karmada-controller-manager cmd/controller-manager/controller-manager.go
--> 8501a6bbb80
[1/2] STEP 7/7: RUN date
Fri May 6 14:04:47 UTC 2022 <======== END: takes 46s
--> 6b4d5f46bdc
[2/2] STEP 1/3: FROM alpine:3.15.1
[2/2] STEP 2/3: COPY --from=builder /bin/karmada-controller-manager /bin/karmada-controller-manager
--> 918f0dbf7aa
[2/2] STEP 3/3: CMD ["/bin/karmada-controller-manager"]
[2/2] COMMIT swr.ap-southeast-1.myhuaweicloud.com/karmada/karmada-controller-manager:latest
--> 6a6568686cb
Successfully tagged swr.ap-southeast-1.myhuaweicloud.com/karmada/karmada-controller-manager:latest
6a6568686cb95d50aa887e1c3bde3bf149bcdb57ebbd4f9a60b5069b6fb564ef
Successfully built 6a6568686cb9
Successfully tagged swr.ap-southeast-1.myhuaweicloud.com/karmada/karmada-controller-manager:latest
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
________________________________________________________
Executed in 55.08 secs fish external
usr time 349.99 millis 0.23 millis 349.77 millis
sys time 854.03 millis 1.16 millis 852.87 millis
Probably guess: when build on host, GOCACHE
helps reduce the building time.
GOCACHE
The directory where the go command will store cached
information for reuse in future builds.
But i have no ideal how to share GOCAHE betweens docker build
. There is no -v
option when in docker build
========= TEST FOR GOCACHE ========
Step 1: go build karmada-aggregated-apiserver
$ time CGO_ENABLED=0 go build -o /bin/karmada-aggregated-apiserver cmd/aggregated-apiserver/main.go
real 0m44.364s
user 1m30.948s
sys 0m15.446s
Step 2: go build karmada-controller-manager. It spends 15s
$ time CGO_ENABLED=0 go build -o /bin/karmada-controller-manager cmd/controller-manager/controller-manager.go
real 0m14.896s
user 0m25.336s
sys 0m5.824s
Step 3: clean GOCACHE
and rebuild karmada-controller-manager again. It takes 51s
$ rm -rf `go env GOCACHE`
$ time CGO_ENABLED=0 go build -o /bin/karmada-controller-manager cmd/controller-manager/controller-manager.go
real 0m51.287s
user 1m45.802s
sys 0m19.012s
I didn't find an effective way. kubernetes
did not build image in multi stage either.
Maybe we shall revert? @gy95 @RainbowMango
No, we need multi-stage for multi-platform images. But, can we revert the single platform image(prefix with image-)?
multi-stage is not requirement for multi-platform. In kubernetes, build multi-platform image without multi-stage build.
Well, good to know. What're the images look like between different platforms? I mean if the image has the same name?
I guess no, there is an os suffix. https://github.com/kubernetes/kubernetes/blob/c8b3b293c047ff9971cb5542a446c9c525877f50/test/images/image-util.sh#L77
And this image is built for testing.
I guess no, there is an os suffix. https://github.com/kubernetes/kubernetes/blob/c8b3b293c047ff9971cb5542a446c9c525877f50/test/images/image-util.sh#L77
And this image is built for testing.
Multi-stage is not necessary. But go build in docker image seems necessary.
When I clone the repo and make containers ,I found the containers can not work on my k8s because my working os is mac and my k8s is linux. But now it resolved.
When I clone and deploy Kubesphere
it will not happen.
https://github.com/kubesphere/kubesphere/blob/master/build/ks-controller-manager/Dockerfile
In build.sh:
GOOS=linux GOARCH=${GOARCH} go build \
-o linux/${GOARCH}/xxx \
cmd/xxx/main.go
In Dockerfile:
FROM alpine:3.15.1
...
ADD ${{TARGETPLATFORM}}/xxx /bin/xxx
...
Then we can build multi platform:
GOARCH=amd64 build.sh
GOARCH=arm64 build.sh
docker buildx build --platform="linux/amd64,linux/arm64" --push ....
Another schema。
Step1 build and push image with suffix -<arch>
docker buildx build --platform=linux/amd64 --push -t karmada/xxx-amd64:latest
docker buildx build --platform=linux/arm64 --push -t karmada/xxx-arm64:latest
Step2 merge manifest
docker manifest create karmada/xxx:latest \
karmada/xxx-amd64:latest \
karmada/xxx-amd64:latest
docker manifest push karmada/xxx:latest
But docker manifest
is experimental.
FYI:
https://docs.docker.com/engine/reference/commandline/manifest/
https://github.com/kubernetes/kubernetes/blob/3c1a3dea59c31ab9f5e1ff2350eca719af3c2b2c/test/images/image-util.sh#L234-L249
/assign
In build.sh:
GOOS=linux GOARCH=${GOARCH} go build \ -o linux/${GOARCH}/xxx \ cmd/xxx/main.go
In Dockerfile:
FROM alpine:3.15.1 ... ADD ${{TARGETPLATFORM}}/xxx /bin/xxx ...
Then we can build multi platform:
GOARCH=amd64 build.sh GOARCH=arm64 build.sh docker buildx build --platform="linux/amd64,linux/arm64" --push ....
I do not aggress with the schema with reversion. I think we should focus on how to reduce the costs when building on docker building stage but not trying to move the building stage outside of docker context The dockerfile should define how to make the docker container precisely and anyone can use one command just as docker build to make the container. But in the schema. Firstly we should set os and make a binary , then find the binary and place it to a right position ,finally we make the container.
What would you like to be added: The
hack/local-up-karmada.sh
is used for users and developers to set up the Karmada environment quickly. But the execution time suddenly gets very long, especially after we change the way building images in #927.Now it takes about
14
minutes on my side and it just needs3~5
minutes before.We can get the execution time change from CI logs as well(from the job
setup e2e test environment
):8
minutes. click me for full logs32
minutes. click me for full logsWhy is this needed: This change has affected users to evaluate Karmada. See #1719
cc @gy95 @ikaven1024 (I'm not blaming you, just want to notice that we might have to make changes based on your work.) /help