Skip to content

Commit

Permalink
[FAB-2826] Add support for $(DOCKER_NS)
Browse files Browse the repository at this point in the history
This patch makes it possible to consistently override the namespace
of the resulting docker images and the linkages between containers
using two new environment variables:

BASE_DOCKER_NS
DOCKER_NS

The default for each is 'hyperledger', which means that by default
this patch has no effect.  However, a user/CI-process may opt to
override this by setting [BASE_]DOCKER_NS to something else.

For example:

```DOCKER_NS=nexus.hyperledger.org:5000/ghaskins make docker```

would produce all images under this namespace, like

nexus.hyperledger.org:5000/ghaskins/fabric-peer
nexus.hyperledger.org:5000/ghaskins/fabric-orderer
nexus.hyperledger.org:5000/ghaskins/fabric-ccenv
nexus.hyperledger.org:5000/ghaskins/fabric-javaenv

Perhaps more importantly, the peer build would provide the variable
subsitution for $([BASE_]DOCKER_NS) in the yaml configuration such that
the peer may be linked to the proper chaincode container without
requiring the yaml file to be rejiggered.

Fixes FAB-2826

Change-Id: I532726e726939bac18c15b92f231add4dd80a482
Signed-off-by: Greg Haskins <gregory.haskins@gmail.com>
  • Loading branch information
ghaskins committed Mar 30, 2017
1 parent a785a4c commit e7294a5
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 34 deletions.
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ BASEIMAGE_RELEASE=$(shell cat ./.baseimage-release)
METADATA_VAR = Version=$(PROJECT_VERSION)
METADATA_VAR += BaseVersion=$(BASEIMAGE_RELEASE)
METADATA_VAR += BaseDockerLabel=$(BASE_DOCKER_LABEL)
METADATA_VAR += DockerNamespace=$(DOCKER_NS)
METADATA_VAR += BaseDockerNamespace=$(BASE_DOCKER_NS)

GO_LDFLAGS = $(patsubst %,-X $(PKGNAME)/common/metadata.%,$(METADATA_VAR))

Expand Down Expand Up @@ -144,7 +146,7 @@ behave-peer-chaincode: build/bin/peer peer-docker orderer-docker

linter: buildenv
@echo "LINT: Running code checks.."
@$(DRUN) hyperledger/fabric-buildenv:$(DOCKER_TAG) ./scripts/golinter.sh
@$(DRUN) $(DOCKER_NS)/fabric-buildenv:$(DOCKER_TAG) ./scripts/golinter.sh

%/chaintool: Makefile
@echo "Installing chaintool"
Expand All @@ -161,7 +163,7 @@ build/docker/bin/%: $(PROJECT_FILES)
@$(DRUN) \
-v $(abspath build/docker/bin):/opt/gopath/bin \
-v $(abspath build/docker/$(TARGET)/pkg):/opt/gopath/pkg \
hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \
$(BASE_DOCKER_NS)/fabric-baseimage:$(BASE_DOCKER_TAG) \
go install -ldflags "$(DOCKER_GO_LDFLAGS)" $(pkgmap.$(@F))
@touch $@

Expand All @@ -175,7 +177,7 @@ build/docker/gotools: gotools/Makefile
@$(DRUN) \
-v $(abspath $@):/opt/gotools \
-w /opt/gopath/src/$(PKGNAME)/gotools \
hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \
$(BASE_DOCKER_NS)/fabric-baseimage:$(BASE_DOCKER_TAG) \
make install BINDIR=/opt/gotools/bin OBJDIR=/opt/gotools/obj

# Both peer and peer-docker depend on ccenv and javaenv (all docker env images it supports).
Expand Down Expand Up @@ -228,6 +230,8 @@ build/image/%/payload:

build/image/%/Dockerfile: images/%/Dockerfile.in
@cat $< \
| sed -e 's/_BASE_NS_/$(BASE_DOCKER_NS)/g' \
| sed -e 's/_NS_/$(DOCKER_NS)/g' \
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
> $@
Expand All @@ -237,8 +241,8 @@ build/image/%/Dockerfile: images/%/Dockerfile.in
build/image/%/$(DUMMY): Makefile build/image/%/payload build/image/%/Dockerfile
$(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}})
@echo "Building docker $(TARGET)-image"
$(DBUILD) -t $(PROJECT_NAME)-$(TARGET) $(@D)
docker tag $(PROJECT_NAME)-$(TARGET) $(PROJECT_NAME)-$(TARGET):$(DOCKER_TAG)
$(DBUILD) -t $(DOCKER_NS)/fabric-$(TARGET) $(@D)
docker tag $(DOCKER_NS)/fabric-$(TARGET) $(DOCKER_NS)/fabric-$(TARGET):$(DOCKER_TAG)
@touch $@

build/gotools.tar.bz2: build/docker/gotools
Expand All @@ -258,11 +262,11 @@ build/%.tar.bz2:

.PHONY: protos
protos: buildenv
@$(DRUN) hyperledger/fabric-buildenv:$(DOCKER_TAG) ./scripts/compile_protos.sh
@$(DRUN) $(DOCKER_NS)/fabric-buildenv:$(DOCKER_TAG) ./scripts/compile_protos.sh

%-docker-clean:
$(eval TARGET = ${patsubst %-docker-clean,%,${@}})
-docker images -q $(PROJECT_NAME)-$(TARGET) | xargs -I '{}' docker rmi -f '{}'
-docker images -q $(DOCKER_NS)/fabric-$(TARGET) | xargs -I '{}' docker rmi -f '{}'
-@rm -rf build/image/$(TARGET) ||:

docker-clean: $(patsubst %,%-docker-clean, $(IMAGES))
Expand Down
2 changes: 2 additions & 0 deletions common/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ package metadata
var Version string
var BaseVersion string
var BaseDockerLabel string
var DockerNamespace string
var BaseDockerNamespace string
6 changes: 3 additions & 3 deletions core/chaincode/chaincodetest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,16 @@ chaincode:
name:

# Generic builder environment, suitable for most chaincode types
builder: hyperledger/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)
builder: $(DOCKER_NS)/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)

golang:
# golang will never need more than baseos
runtime: hyperledger/fabric-baseos:$(ARCH)-$(BASE_VERSION)
runtime: $(BASE_DOCKER_NS)/fabric-baseos:$(ARCH)-$(BASE_VERSION)

car:
# car may need more facilities (JVM, etc) in the future as the catalog
# of platforms are expanded. For now, we can just use baseos
runtime: hyperledger/fabric-baseos:$(ARCH)-$(BASE_VERSION)
runtime: $(BASE_DOCKER_NS)/fabric-baseos:$(ARCH)-$(BASE_VERSION)

# timeout in millisecs for starting up a container and waiting for Register
# to come through. 1sec should be plenty for chaincode unit tests
Expand Down
6 changes: 4 additions & 2 deletions core/container/util/dockerutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"runtime"
"strings"

"github.com/fsouza/go-dockerclient"
docker "github.com/fsouza/go-dockerclient"
"github.com/hyperledger/fabric/common/metadata"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -59,7 +59,9 @@ func parseDockerfileTemplate(template string) string {
r := strings.NewReplacer(
"$(ARCH)", getArch(),
"$(PROJECT_VERSION)", metadata.Version,
"$(BASE_VERSION)", metadata.BaseVersion)
"$(BASE_VERSION)", metadata.BaseVersion,
"$(DOCKER_NS)", metadata.DockerNamespace,
"$(BASE_DOCKER_NS)", metadata.BaseDockerNamespace)

return r.Replace(template)
}
Expand Down
14 changes: 7 additions & 7 deletions core/endorser/endorser_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ peer:
listenAddress: 0.0.0.0:6060

mspConfigPath: ../../msp/sampleconfig

# BCCSP (Blockchain crypto provider): Select which crypto implementation or
# library to use
BCCSP:
Expand All @@ -325,9 +325,9 @@ peer:
# SHA2 is hardcoded in several places, not only BCCSP
Hash: SHA2
Security: 256
FileKeyStore:
FileKeyStore:
KeyStore:

###############################################################################
#
# VM section
Expand Down Expand Up @@ -370,24 +370,24 @@ chaincode:
name:

# Generic builder environment, suitable for most chaincode types
builder: hyperledger/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)
builder: $(DOCKER_NS)/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)

golang:
# golang will never need more than baseos
runtime: hyperledger/fabric-baseos:$(ARCH)-$(BASE_VERSION)
runtime: $(BASE_DOCKER_NS)/fabric-baseos:$(ARCH)-$(BASE_VERSION)

car:
# car may need more facilities (JVM, etc) in the future as the catalog
# of platforms are expanded. For now, we can just use baseos
runtime: hyperledger/fabric-baseos:$(ARCH)-$(BASE_VERSION)
runtime: $(BASE_DOCKER_NS)/fabric-baseos:$(ARCH)-$(BASE_VERSION)

java:
# This is an image based on java:openjdk-8 with addition compiler
# tools added for java shim layer packaging.
# This image is packed with shim layer libraries that are necessary
# for Java chaincode runtime.
Dockerfile: |
FROM hyperledger/fabric-javaenv:$(ARCH)-$(PROJECT_VERSION)
FROM $(DOCKER_NS)/fabric-javaenv:$(ARCH)-$(PROJECT_VERSION)
# timeout in millisecs for starting up a container and waiting for Register
# to come through. 1sec should be plenty for chaincode unit tests
Expand Down
5 changes: 4 additions & 1 deletion docker-env.mk
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ DRUN = docker run -i --rm $(DOCKER_RUN_FLAGS) \

DBUILD = docker build $(DOCKER_BUILD_FLAGS)

DOCKER_TAG=$(ARCH)-$(PROJECT_VERSION)
BASE_DOCKER_NS ?= hyperledger
BASE_DOCKER_TAG=$(ARCH)-$(BASEIMAGE_RELEASE)

DOCKER_NS ?= hyperledger
DOCKER_TAG=$(ARCH)-$(PROJECT_VERSION)

BASE_DOCKER_LABEL=org.hyperledger.fabric

DOCKER_GO_LDFLAGS += $(GO_LDFLAGS)
Expand Down
2 changes: 1 addition & 1 deletion images/buildenv/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM hyperledger/fabric-baseimage:_BASE_TAG_
FROM _BASE_NS_/fabric-baseimage:_BASE_TAG_
COPY payload/protoc-gen-go /usr/local/bin/
ADD payload/gotools.tar.bz2 /usr/local/bin/
2 changes: 1 addition & 1 deletion images/ccenv/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hyperledger/fabric-baseimage:_BASE_TAG_
FROM _BASE_NS_/fabric-baseimage:_BASE_TAG_
COPY payload/chaintool payload/protoc-gen-go /usr/local/bin/
ADD payload/goshim.tar.bz2 $GOPATH/src/
RUN mkdir -p /chaincode/input /chaincode/output
4 changes: 2 additions & 2 deletions images/couchdb/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hyperledger/fabric-baseimage:_BASE_TAG_
FROM _BASE_NS_/fabric-baseimage:_BASE_TAG_

# Based on https://github.com/klaemo/docker-couchdb/blob/master/2.0.0/Dockerfile

Expand Down Expand Up @@ -38,7 +38,7 @@ RUN set -x \
&& cp tini tini-static /usr/local/bin/ \
# Clean up su-exec and tini
&& rm -rf /tmp/tini \
&& rm -rf /tmp/su-exec
&& rm -rf /tmp/su-exec

ARG COUCHDB_VERSION=2.0.0

Expand Down
2 changes: 1 addition & 1 deletion images/javaenv/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hyperledger/fabric-baseimage:_BASE_TAG_
FROM _BASE_NS_/fabric-baseimage:_BASE_TAG_
RUN curl -sSL https://services.gradle.org/distributions/gradle-2.12-bin.zip > /tmp/gradle-2.12-bin.zip
RUN unzip -qo /tmp/gradle-2.12-bin.zip -d /opt && rm /tmp/gradle-2.12-bin.zip
RUN ln -s /opt/gradle-2.12/bin/gradle /usr/bin
Expand Down
2 changes: 1 addition & 1 deletion images/kafka/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hyperledger/fabric-baseimage:_BASE_TAG_
FROM _BASE_NS_/fabric-baseimage:_BASE_TAG_

ENV SCALA_VERSION=2.11 \
KAFKA_VERSION=0.9.0.1 \
Expand Down
2 changes: 1 addition & 1 deletion images/orderer/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hyperledger/fabric-baseos:_BASE_TAG_
FROM _BASE_NS_/fabric-baseos:_BASE_TAG_
ENV ORDERER_CFG_PATH /etc/hyperledger/fabric
ENV ORDERER_GENERAL_LOCALMSPDIR $ORDERER_CFG_PATH/msp/sampleconfig
ENV ORDERER_GENERAL_GENESISPROFILE=SampleInsecureSolo
Expand Down
2 changes: 1 addition & 1 deletion images/peer/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hyperledger/fabric-baseos:_BASE_TAG_
FROM _BASE_NS_/fabric-baseos:_BASE_TAG_
ENV PEER_CFG_PATH /etc/hyperledger/fabric
ENV CORE_PEER_MSPCONFIGPATH $PEER_CFG_PATH/msp/sampleconfig
RUN mkdir -p /var/hyperledger/production $PEER_CFG_PATH
Expand Down
2 changes: 1 addition & 1 deletion images/testenv/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hyperledger/fabric-buildenv:_TAG_
FROM _NS_/fabric-buildenv:_TAG_

# fabric configuration locations
ENV PEER_CFG_PATH /etc/hyperledger/fabric
Expand Down
2 changes: 1 addition & 1 deletion images/zookeeper/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hyperledger/fabric-baseimage:_BASE_TAG_
FROM _BASE_NS_/fabric-baseimage:_BASE_TAG_
# Based on https://github.com/31z4/zookeeper-docker/blob/master/3.4.9/Dockerfile

# Install su-exec
Expand Down
8 changes: 4 additions & 4 deletions peer/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -309,24 +309,24 @@ chaincode:
name:

# Generic builder environment, suitable for most chaincode types
builder: hyperledger/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)
builder: $(DOCKER_NS)/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)

golang:
# golang will never need more than baseos
runtime: hyperledger/fabric-baseos:$(ARCH)-$(BASE_VERSION)
runtime: $(BASE_DOCKER_NS)/fabric-baseos:$(ARCH)-$(BASE_VERSION)

car:
# car may need more facilities (JVM, etc) in the future as the catalog
# of platforms are expanded. For now, we can just use baseos
runtime: hyperledger/fabric-baseos:$(ARCH)-$(BASE_VERSION)
runtime: $(BASE_DOCKER_NS)/fabric-baseos:$(ARCH)-$(BASE_VERSION)

java:
# This is an image based on java:openjdk-8 with addition compiler
# tools added for java shim layer packaging.
# This image is packed with shim layer libraries that are necessary
# for Java chaincode runtime.
Dockerfile: |
from hyperledger/fabric-javaenv:$(ARCH)-$(PROJECT_VERSION)
from $(DOCKER_NS)/fabric-javaenv:$(ARCH)-$(PROJECT_VERSION)
# timeout in millisecs for starting up a container and waiting for Register
# to come through. 1sec should be plenty for chaincode unit tests
Expand Down

0 comments on commit e7294a5

Please sign in to comment.