Skip to content

feature: build static task #6

Open

Description

@flaccid

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.

Activity

  1. flaccid commented on Jul 10, 2017

    @flaccid
    Author

    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
    
  2. vincentbernat commented on Jul 10, 2017

    @vincentbernat
    Owner

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions