Skip to content

Commit

Permalink
🌱 Reproducible builds with static binary
Browse files Browse the repository at this point in the history
Changes to goreleaser to have static binaries and reproducible builds.
  • Loading branch information
naveensrinivasan committed Oct 25, 2021
1 parent c3d51a7 commit 311d2e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
18 changes: 14 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
project_name: scorecard
env:
- GO111MODULE=on
- CGO_ENABLED=1
# https://stackoverflow.com/a/62821358/19407
- CGO_ENABLED=0
before:
hooks:
- go mod download
builds:
flags:
# trimpath is for reproducible builds
# remove all file system paths from the resulting executable.
# Instead of absolute file system paths, the recorded file names
# will begin with either "go" (for the standard library),
# or a module path@version (when using modules),
# or a plain import path (when using GOPATH).
- -trimpath
- -tags=netgo

- id: linux
binary: scorecard-linux-{{ .Arch }}
Expand All @@ -18,7 +28,7 @@ builds:
- 386
- arm
ldflags:
- -s -w {{.Env.VERSION_LDFLAGS}}
- -s {{.Env.VERSION_LDFLAGS}}

- id: darwin
binary: scorecard-darwin-{{ .Arch }}
Expand All @@ -29,7 +39,7 @@ builds:
- amd64
- arm64
ldflags:
- -s -w {{.Env.VERSION_LDFLAGS}}
- -s {{.Env.VERSION_LDFLAGS}}

- id: windows
binary: scorecard-windows-{{ .Arch }}
Expand All @@ -43,7 +53,7 @@ builds:
- arm
ldflags:
- -buildmode=exe
- -s -w {{.Env.VERSION_LDFLAGS}}
- -s {{.Env.VERSION_LDFLAGS}}

checksum:
# Algorithm to be used.
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ PROTOC := $(shell which protoc)
IMAGE_NAME = scorecard
OUTPUT = output
IGNORED_CI_TEST="E2E TEST:blob|E2E TEST:executable"
VERSION_LDFLAGS=$(shell ./scripts/version-ldflags)
LDFLAGS=$(shell echo "-w -extldflags \"-static\" $(VERSION_LDFLAGS)")
LDFLAGS=$(shell ./scripts/version-ldflags)

############################### make help #####################################
.PHONY: help
Expand Down
2 changes: 1 addition & 1 deletion scripts/version-ldflags
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ GIT_HASH=$(git rev-parse HEAD)
SOURCE_DATE_EPOCH=$(git log --date=iso8601-strict -1 --pretty=%ct)
GIT_TREESTATE=$(if git diff --quiet; then echo "clean"; else echo "dirty"; fi)
PKG=$(go list -m | head -n1)/pkg
echo "-X $PKG.gitVersion=$GIT_VERSION -X $PKG.gitCommit=$GIT_HASH -X $PKG.gitTreeState=$GIT_TREESTATE -X $PKG.buildDate=$SOURCE_DATE_EPOCH"
echo "-X $PKG.gitVersion=$GIT_VERSION -X $PKG.gitCommit=$GIT_HASH -X $PKG.gitTreeState=$GIT_TREESTATE -X $PKG.buildDate=$SOURCE_DATE_EPOCH -w -extldflags \"-static\""

0 comments on commit 311d2e2

Please sign in to comment.