Skip to content

Commit

Permalink
[BUILD] Generalize our options passed to docker-run
Browse files Browse the repository at this point in the history
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 <gregory.haskins@gmail.com>
  • Loading branch information
ghaskins committed Nov 21, 2016
1 parent 5dbd1f0 commit ac987db
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down Expand Up @@ -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"
Expand All @@ -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 $@
Expand Down

0 comments on commit ac987db

Please sign in to comment.