From ac987db40db0d67289a25ddb37437bf85856ca77 Mon Sep 17 00:00:00 2001 From: Gregory Haskins Date: Fri, 4 Nov 2016 15:12:08 -0400 Subject: [PATCH] [BUILD] Generalize our options passed to docker-run Running things under docker will have various options in common, so lets capture this in a way to promote reuse. For instance, we always want to: * volume mount fabric.git to $GOPATH and set WORKDIR * use -i --rm * optionally use --user Change-Id: Iddca0d25fd0f08b34c2b1e5fbd10dd49def3351f Signed-off-by: Greg Haskins --- Makefile | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index d90438379a5..903e4934bd8 100644 --- a/Makefile +++ b/Makefile @@ -48,14 +48,22 @@ endif PKGNAME = github.com/$(PROJECT_NAME) GO_LDFLAGS = -X $(PKGNAME)/metadata.Version=$(PROJECT_VERSION) CGO_FLAGS = CGO_CFLAGS=" " CGO_LDFLAGS="-lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy" -UID = $(shell id -u) ARCH=$(shell uname -m) +OS=$(shell uname) CHAINTOOL_RELEASE=v0.10.0 BASEIMAGE_RELEASE=$(shell cat ./.baseimage-release) DOCKER_TAG=$(ARCH)-$(PROJECT_VERSION) BASE_DOCKER_TAG=$(ARCH)-$(BASEIMAGE_RELEASE) +ifneq ($(OS),Darwin) +DOCKER_FLAGS=--user=$(shell id -u) +endif + +DRUN = docker run -i --rm $(DOCKER_FLAGS) \ + -v $(abspath .):/opt/gopath/src/$(PKGNAME) \ + -w /opt/gopath/src/$(PKGNAME) + EXECUTABLES = go docker git curl K := $(foreach exec,$(EXECUTABLES),\ $(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH: Check dependencies"))) @@ -117,11 +125,11 @@ linter: gotools %/bin/protoc-gen-go: Makefile @echo "Building $@" @mkdir -p $(@D) - @docker run -i \ - --user=$(UID) \ + @$(DRUN) \ -v $(abspath vendor/github.com/golang/protobuf):/opt/gopath/src/github.com/golang/protobuf \ -v $(abspath $(@D)):/opt/gopath/bin \ - hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) go install github.com/golang/protobuf/protoc-gen-go + hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \ + go install github.com/golang/protobuf/protoc-gen-go build/bin/chaintool: Makefile @echo "Installing chaintool" @@ -139,11 +147,9 @@ build/docker/bin/%: $(PROJECT_FILES) $(eval TARGET = ${patsubst build/docker/bin/%,%,${@}}) @echo "Building $@" @mkdir -p build/docker/bin build/docker/pkg - @docker run -i \ - --user=$(UID) \ + @$(DRUN) \ -v $(abspath build/docker/bin):/opt/gopath/bin \ -v $(abspath build/docker/pkg):/opt/gopath/pkg \ - -v $(abspath .):/opt/gopath/src/$(PKGNAME) \ hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \ go install -ldflags "$(GO_LDFLAGS)" $(pkgmap.$(@F)) @touch $@