hellogopher icon indicating copy to clipboard operation
hellogopher copied to clipboard

feature: build static task

Open flaccid opened this issue 8 years ago • 2 comments

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.

flaccid avatar Jul 10 '17 05:07 flaccid

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

flaccid avatar Jul 10 '17 05:07 flaccid

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.

vincentbernat avatar Jul 10 '17 06:07 vincentbernat