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

ci: optimize build #242

Merged
merged 1 commit into from
Oct 12, 2023
Merged

ci: optimize build #242

merged 1 commit into from
Oct 12, 2023

Conversation

sljeff
Copy link
Collaborator

@sljeff sljeff commented Oct 11, 2023

cd 的改动暂时放在 .github/workflows/optimize-build.yaml 里方便推分支的时候测试,没问题的话就迁移到 cd.yaml 里去

改动

  1. 用 go build 时的 GOARCH 来编译出不同平台的二进制,而不是在 qemu 环境里 build。qemu 的性能太差,在 action 里无论怎么优化也要跑十分钟以上。
  2. Dockerfile 中改为只是把二进制 COPY 进来
    • 如果说为了方便用户自己本地 build 镜像还是要保留一个正常的多阶段的 Dockerfile 的话,这个改动后的可以叫 cd.Dockerfile
  3. 分不同的 job 来 build 不同平台然后 merge 成一个镜像一起推上去

然后还有这些被迫的改动:

  • Makefile 里 CGO_ENABLED=0,因为 CGO 开了不能交叉编译
  • Dockerfile 里加了句 RUN chmod +x ehco 因为不知道为啥拷过去的二进制没有执行权限

效果

cd 总时间从十几分钟缩短到四分钟

image

同样 tag 的镜像是多平台的(不过我没有 arm 的 linux 设备可以测试)

image

@sljeff sljeff force-pushed the ci/optimize-build branch 9 times, most recently from 2939a3d to 36730a6 Compare October 11, 2023 15:59
@sljeff sljeff requested a review from Ehco1996 October 11, 2023 16:02
Copy link
Owner

@Ehco1996 Ehco1996 left a comment

Choose a reason for hiding this comment

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

restLGTM 太强了 不愧是最强 devops

@@ -17,7 +17,7 @@ FAIL_ON_STDOUT := awk '{ print } END { if (NR > 0) { exit 1 } }'
# -w -s 参数的解释:You will get the smallest binaries if you compile with -ldflags '-w -s'. The -w turns off DWARF debugging information
# for more information, please refer to https://stackoverflow.com/questions/22267189/what-does-the-w-flag-mean-when-passed-in-via-the-ldflags-option-to-the-go-comman
# we need CGO_ENABLED=1 because we import the node_exporter ,and we need install `glibc-source,libc6` to make it work
Copy link
Owner

Choose a reason for hiding this comment

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

开了 cgo 是因为内置了 node_exporter ,prometheus/node_exporter#400

Copy link
Owner

@Ehco1996 Ehco1996 Oct 12, 2023

Choose a reason for hiding this comment

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

之后调研一下哪些 collector 需要开 cgo 编译,暂时先合并了 感谢 jeff @sljeff

@sljeff sljeff requested a review from Ehco1996 October 12, 2023 10:07
@Ehco1996 Ehco1996 merged commit 513ef2d into master Oct 12, 2023
@sljeff sljeff deleted the ci/optimize-build branch October 12, 2023 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants