Skip to content

Commit

Permalink
Improve docker build/experience
Browse files Browse the repository at this point in the history
This change aligns docker build methods to be more generic,
more closely aligned with fabric.git, and allows the resulting
docker image to be more turnkey (it includes demo config/keys).

Change-Id: Ifc7213bf7d3c74355e7013c09d5621b6cc06f54e
Signed-off-by: Greg Haskins <[email protected]>
  • Loading branch information
ghaskins committed Jan 9, 2017
1 parent 72a87e3 commit e1fbfbf
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 26 deletions.
43 changes: 21 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ K := $(foreach exec,$(EXECUTABLES),\
ARCH=$(shell uname -m)
BASEIMAGE_RELEASE = 0.2.2
PKGNAME = github.com/hyperledger/$(PROJECT_NAME)
pkgmap.cop := $(PKGNAME)
SAMPLECONFIG = $(shell git ls-files images/cop/config)

DOCKER_ORG = hyperledger
IMAGES = $(PROJECT_NAME) $(PROJECT_NAME)-runtime

image-path-map.fabric-cop := cop
image-path-map.fabric-cop-runtime := runtime

include docker-env.mk

all: docker unit-tests
Expand Down Expand Up @@ -78,15 +81,15 @@ cop:

# We (re)build a package within a docker context but persist the $GOPATH/pkg
# directory so that subsequent builds are faster
build/docker/bin/$(PROJECT_NAME):
build/docker/bin/cop:
@echo "Building $@"
@mkdir -p build/docker/bin build/docker/$(PROJECT_NAME)/pkg
@mkdir -p $(@D) build/docker/$(@F)/pkg
@$(DRUN) \
-v $(abspath build/docker/bin):/opt/gopath/bin \
-v $(abspath build/docker/$(PROJECT_NAME)/pkg):/opt/gopath/pkg \
-v $(abspath build/docker/$(@F)/pkg):/opt/gopath/pkg \
hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \
go install -ldflags "$(DOCKER_GO_LDFLAGS)" $(pkgmap.cop)/cli
mv build/docker/bin/cli build/docker/bin/$(PROJECT_NAME)
go install -ldflags "$(DOCKER_GO_LDFLAGS)" $(PKGNAME)/cli
mv build/docker/bin/cli $@
@touch $@

build/docker/busybox:
Expand All @@ -97,33 +100,29 @@ build/docker/busybox:

build/image/$(PROJECT_NAME)/$(DUMMY): build/image/$(PROJECT_NAME)-runtime/$(DUMMY)

# payload definitions'
build/image/$(PROJECT_NAME)/payload: build/docker/bin/$(PROJECT_NAME)
# payload definitions
build/image/$(PROJECT_NAME)/payload: build/docker/bin/cop \
build/sampleconfig.tar.bz2
build/image/$(PROJECT_NAME)-runtime/payload: build/docker/busybox

build/image/%/payload:
mkdir -p $@
cp $^ $@

build/image/$(PROJECT_NAME)/$(DUMMY): Makefile build/image/$(PROJECT_NAME)/payload
@echo "Building docker $(PROJECT_NAME) image"
@cat images/cop/Dockerfile.in \
build/image/%/$(DUMMY): Makefile build/image/%/payload
$(eval TARGET = ${patsubst build/image/%/$(DUMMY),%,${@}})
$(eval DOCKER_NAME = $(DOCKER_ORG)/$(TARGET))
@echo "Building docker $(TARGET) image"
@cat images/$(image-path-map.$(TARGET))/Dockerfile.in \
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
> $(@D)/Dockerfile
$(DBUILD) -t $(DOCKER_ORG)/$(PROJECT_NAME) $(@D)
docker tag $(DOCKER_ORG)/$(PROJECT_NAME) $(DOCKER_ORG)/$(PROJECT_NAME):$(DOCKER_TAG)
$(DBUILD) -t $(DOCKER_NAME) $(@D)
docker tag $(DOCKER_NAME) $(DOCKER_NAME):$(DOCKER_TAG)
@touch $@

build/image/$(PROJECT_NAME)-runtime/$(DUMMY): Makefile build/image/$(PROJECT_NAME)-runtime/payload
@echo "Building docker $(PROJECT_NAME)-runtime image"
@cat images/runtime/Dockerfile.in \
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
> $(@D)/Dockerfile
$(DBUILD) -t $(DOCKER_ORG)/$(PROJECT_NAME)-runtime $(@D)
docker tag $(DOCKER_ORG)/$(PROJECT_NAME)-runtime $(DOCKER_ORG)/$(PROJECT_NAME)-runtime:$(DOCKER_TAG)
@touch $@
build/sampleconfig.tar.bz2: $(SAMPLECONFIG)
tar -jc -C images/cop/config $(patsubst images/cop/config/%,%,$(SAMPLECONFIG)) > $@

unit-tests: checks cop
@scripts/run_tests
Expand Down
8 changes: 4 additions & 4 deletions images/cop/Dockerfile.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM hyperledger/fabric-cop-runtime:_TAG_
ENV COP_HOME /etc/hyperledger/fabric-cop
RUN mkdir -p /etc/hyperledger/fabric-cop
COPY payload/fabric-cop /usr/local/bin
RUN mv /usr/local/bin/fabric-cop /usr/local/bin/cop
RUN mkdir -p $COP_HOME /var/hyperledger/fabric-cop
COPY payload/cop /usr/local/bin
ADD payload/sampleconfig.tar.bz2 $COP_HOME
EXPOSE 8888
CMD cop
CMD cop server start -address 0.0.0.0 -config $COP_HOME/cop.json
3 changes: 3 additions & 0 deletions images/cop/config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory contains sample configuration data for COP.

These files will ultimately be loaded as the default in the docker container under /etc/hyperledger/fabric-cop. It is intended that these files will be replaced for production deployment, such as with a volume mount or derived image.
23 changes: 23 additions & 0 deletions images/cop/config/cop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"tls_disable":true,
"users": {
"admin": {
"pass": "adminpw",
"type": "client",
"group": "bank_a",
"attrs": [{"name":"hf.Registrar.Roles","value":"client,peer,validator,auditor"}, {"name":"hf.Registrar.DelegateRoles", "value": "client"}]
}
},
"groups": {
"banks_and_institutions": {
"banks": ["bank_a", "bank_b", "bank_c"],
"institutions": ["institution_a"]
}
},
"signing": {
"default": {
"usages": ["cert sign"],
"expiry": "8000h"
}
}
}
20 changes: 20 additions & 0 deletions images/cop/config/csr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"hosts": [
"myhost.com",
"www.myhost.com"
],
"CN": "admin",
"key": {
"algo": "ecdsa",
"size": 256
},
"names": [
{
"O": "Hyperledger Fabric",
"OU": "COP",
"L": "Raleigh",
"ST": "North Carolina",
"C": "US"
}
]
}

0 comments on commit e1fbfbf

Please sign in to comment.