Open caoshitong369 opened 3 years ago
Trying to build static PIE version (on Fedora 33, for "FROM scratch" container):
go build -buildmode=pie -tags "osusergo,netgo,static" -ldflags '-linkmode external -extldflags "-static-pie" -X github.com/google/cadvisor/version.Version=v0.39.0.51+a2ec5fc7 -X github.com/google/cadvisor/version.Revision=a2ec5fc7 -X github.com/google/cadvisor/version.Branch=feature-poc -X github.com/google/cadvisor/version.BuildUser=eero.t.tamminen@intel.com -X github.com/google/cadvisor/version.BuildDate=20210610-19:02:42 -X github.com/google/cadvisor/version.GoVersion=1.15.12' -o /home/ettammin/work/containers/cadvisor/cadvisor github.com/google/cadvisor/cmd
Gives similar error:
go: finding module for package github.com/google/cadvisor/cmd
go: found github.com/google/cadvisor/cmd in github.com/google/cadvisor/cmd v0.0.0-20210610165627-f2f65b461d86
go: github.com/google/cadvisor/cmd@v0.0.0-20210610165627-f2f65b461d86 requires
github.com/google/cadvisor@v0.0.0: reading github.com/google/cadvisor/go.mod at revision v0.0.0: unknown revision v0.0.0
Although similar build options worked fine for runC.
Trying to give correct cAdvisor version on CLI, also fails:
package github.com/google/cadvisor/cmd@v0.39.0.51+a2ec5fc7: can only use path@version syntax with 'go get'
And adding the correct cAdvisor version to "go.mod" cAdvisor module line is not accepted go.mod file syntax.
How one is supposed to build completely static binary?
PS. ./docs/deploy.md
states that ./deploy/build.sh
builds static cAdvisor version, but that's not true. First it calls "make build" on host which builds version of cAdvisor linking host C-library dynamically. Then that script does same inside the container with Alpine / MUSL. I.e. neither build does work without corresponding libc.
FYI: If I do the static build from "cmd" subdirectory / use relative path:
$ go build -buildmode=pie -tags "osusergo,netgo,static" -ldflags '-linkmode external -extldflags "-static-pie" -X github.com/google/cadvisor/version.Version=v0.39.0.51+a2ec5fc7 -X github.com/google/cadvisor/version.Revision=a2ec5fc7 -X github.com/google/cadvisor/version.Branch=feature-poc -X github.com/google/cadvisor/version.BuildUser=eero.t.tamminen@intel.com -X github.com/google/cadvisor/version.BuildDate=20210614-17:02:42 -X github.com/google/cadvisor/version.GoVersion=1.15.12' -o cadvisor .
Then it succeeds without Golang version errors... Any idea why?
github.com/google/cadvisor/cmd@v0.0.0-20201124224909-ac63c56b6be0 requires github.com/google/cadvisor@v0.0.0: reading https://goproxy.cn/github.com/google/cadvisor/@v/v0.0.0.mod: 404 Not Found server response: not found: github.com/google/cadvisor@v0.0.0: invalid version: unknown revision v0.0.0