Skip to content

Commit

Permalink
add ldflags for static pie
Browse files Browse the repository at this point in the history
  • Loading branch information
jackgopack4 committed Oct 25, 2024
1 parent 8af7a4e commit 955bc44
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ifeq (, $(shell command -v ocb 2>/dev/null))
[ "$${machine}" != x86_64 ] || machine=amd64 ;\
echo "Installing ocb ($${os}/$${machine}) at $(OTELCOL_BUILDER_DIR)";\
mkdir -p $(OTELCOL_BUILDER_DIR) ;\
CGO_ENABLED=0 go install -trimpath -ldflags="-s -w" -buildmode=pie go.opentelemetry.io/collector/cmd/builder@v$(OTELCOL_BUILDER_VERSION) ;\
CGO_ENABLED=0 go install -trimpath -ldflags='-linkmode external -s -w -extldflags "--static-pie"' -buildmode=pie go.opentelemetry.io/collector/cmd/builder@v$(OTELCOL_BUILDER_VERSION) ;\
mv $$(go env GOPATH)/bin/builder $(OTELCOL_BUILDER) ;\
}
else
Expand Down
1 change: 0 additions & 1 deletion cmd/builder/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,3 @@ sboms:
artifacts: archive
- id: package
artifacts: package

4 changes: 2 additions & 2 deletions cmd/goreleaser/internal/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Generate(dist string) config.Project {
DockerSigns: DockerSigns(),
SBOMs: SBOM(),
Version: 2,
Monorepo: config.Monorepo{
Monorepo: config.Monorepo{
TagPrefix: "v",
},
}
Expand All @@ -74,7 +74,7 @@ func Build(dist string) config.Build {
BuildDetails: config.BuildDetails{
Env: []string{"CGO_ENABLED=0"},
Flags: []string{"-trimpath", "-buildmode=pie"},
Ldflags: []string{"-s", "-w"},
Ldflags: []string{"-linkmode external", "-s", "-w", "-extldflags \"--static-pie\""},
},
Goos: []string{"darwin", "linux", "windows"},
Goarch: Architectures,
Expand Down
2 changes: 2 additions & 0 deletions distributions/otelcol-contrib/.goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ builds:
dir: _build
binary: otelcol-contrib
ldflags:
- -linkmode external
- -s
- -w
- -extldflags "--static-pie"
flags:
- -trimpath
- -buildmode=pie
Expand Down
2 changes: 2 additions & 0 deletions distributions/otelcol-k8s/.goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ builds:
dir: _build
binary: otelcol-k8s
ldflags:
- -linkmode external
- -s
- -w
- -extldflags "--static-pie"
flags:
- -trimpath
- -buildmode=pie
Expand Down
2 changes: 2 additions & 0 deletions distributions/otelcol-otlp/.goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ builds:
dir: _build
binary: otelcol-otlp
ldflags:
- -linkmode external
- -s
- -w
- -extldflags "--static-pie"
flags:
- -trimpath
- -buildmode=pie
Expand Down
2 changes: 2 additions & 0 deletions distributions/otelcol/.goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ builds:
dir: _build
binary: otelcol
ldflags:
- -linkmode external
- -s
- -w
- -extldflags "--static-pie"
flags:
- -trimpath
- -buildmode=pie
Expand Down

0 comments on commit 955bc44

Please sign in to comment.