Skip to content

Instantly share code, notes, and snippets.

@thockin
Last active August 28, 2016 16:36
Show Gist options
  • Save thockin/36674d78bf213608f0e2ae4de06ef30d to your computer and use it in GitHub Desktop.
Save thockin/36674d78bf213608f0e2ae4de06ef30d to your computer and use it in GitHub Desktop.
Use docker to build Go, via Makefile
bin/$(ARCH)/$(BIN): FORCE
@mkdir -p bin/$(ARCH)
@mkdir -p .go/src/$(GO_PKG) .go/pkg .go/bin .go/std/$(ARCH)
docker run \
-u $$(id -u):$$(id -g) \
-v $$(pwd)/.go:/go \
-v $$(pwd):/go/src/$(GO_PKG) \
-v $$(pwd)/bin/$(ARCH):/go/bin \
-v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \
$(BUILD_IMAGE) \
/bin/sh -c " \
cd /go/src/$(GO_PKG) && \
CGO_ENABLED=0 \
go install \
-installsuffix static \
./... \
"
@thockin
Copy link
Author

thockin commented Aug 28, 2016

In this case BUILD_IMAGE=golang:1.7.0-alpine, ARCH=amd64, BIN=yourapp, and GO_PKG=github.com/yourname/yourapp

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