hellogopher
hellogopher copied to clipboard
feature: build static task
Could we implement a task for the Makefile to do something like CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo .?
This helps to build a static binary for a docker image that has no dynamics.
Not sure if this is good enough, but seems to do the job for me...
# Build Static
.PHONY: static
static: fmt lint vendor | $(BASE) ; $(info $(M) building static executable…) @ ## Build static program binary
$Q cd $(BASE) && CGO_ENABLED=0 $(GO) build \
-a \
-installsuffix cgo \
-tags release \
-ldflags '-X $(PACKAGE)/cmd.Version=$(VERSION) -X $(PACKAGE)/cmd.BuildDate=$(DATE)' \
-o bin/$(PACKAGE) main.go
I think this is good enough. I don't add it directly because adding features goes against the "minimal" Makefile I try to provide here. But people interested in such a rule are likely to find this issue.