Skip to content

Commit ac987db

Browse files
committed
[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 <[email protected]>
1 parent 5dbd1f0 commit ac987db

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Makefile

+13-7
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,22 @@ endif
4848
PKGNAME = github.com/$(PROJECT_NAME)
4949
GO_LDFLAGS = -X $(PKGNAME)/metadata.Version=$(PROJECT_VERSION)
5050
CGO_FLAGS = CGO_CFLAGS=" " CGO_LDFLAGS="-lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy"
51-
UID = $(shell id -u)
5251
ARCH=$(shell uname -m)
52+
OS=$(shell uname)
5353
CHAINTOOL_RELEASE=v0.10.0
5454
BASEIMAGE_RELEASE=$(shell cat ./.baseimage-release)
5555

5656
DOCKER_TAG=$(ARCH)-$(PROJECT_VERSION)
5757
BASE_DOCKER_TAG=$(ARCH)-$(BASEIMAGE_RELEASE)
5858

59+
ifneq ($(OS),Darwin)
60+
DOCKER_FLAGS=--user=$(shell id -u)
61+
endif
62+
63+
DRUN = docker run -i --rm $(DOCKER_FLAGS) \
64+
-v $(abspath .):/opt/gopath/src/$(PKGNAME) \
65+
-w /opt/gopath/src/$(PKGNAME)
66+
5967
EXECUTABLES = go docker git curl
6068
K := $(foreach exec,$(EXECUTABLES),\
6169
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH: Check dependencies")))
@@ -117,11 +125,11 @@ linter: gotools
117125
%/bin/protoc-gen-go: Makefile
118126
@echo "Building $@"
119127
@mkdir -p $(@D)
120-
@docker run -i \
121-
--user=$(UID) \
128+
@$(DRUN) \
122129
-v $(abspath vendor/github.com/golang/protobuf):/opt/gopath/src/github.com/golang/protobuf \
123130
-v $(abspath $(@D)):/opt/gopath/bin \
124-
hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) go install github.com/golang/protobuf/protoc-gen-go
131+
hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \
132+
go install github.com/golang/protobuf/protoc-gen-go
125133

126134
build/bin/chaintool: Makefile
127135
@echo "Installing chaintool"
@@ -139,11 +147,9 @@ build/docker/bin/%: $(PROJECT_FILES)
139147
$(eval TARGET = ${patsubst build/docker/bin/%,%,${@}})
140148
@echo "Building $@"
141149
@mkdir -p build/docker/bin build/docker/pkg
142-
@docker run -i \
143-
--user=$(UID) \
150+
@$(DRUN) \
144151
-v $(abspath build/docker/bin):/opt/gopath/bin \
145152
-v $(abspath build/docker/pkg):/opt/gopath/pkg \
146-
-v $(abspath .):/opt/gopath/src/$(PKGNAME) \
147153
hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \
148154
go install -ldflags "$(GO_LDFLAGS)" $(pkgmap.$(@F))
149155
@touch $@

0 commit comments

Comments
 (0)