Skip to content
This repository has been archived by the owner on Dec 2, 2021. It is now read-only.

Commit

Permalink
FAB-10400 add docker image to build
Browse files Browse the repository at this point in the history
modified multi-stage build to clone fabric
checkout master
build peer binary
copy in plugin source (no tests)
dep ensure
build plugin
copy into hyperledger/fabric-peers:latest
also had to modify core.yaml to add in pluggable
endorsement and validation default settings

added check for dependent images
added integration-test target
refactored multi-stage build, much more efficient
add extract of .so from image
cleanup docker dross
align network_setup.sh cleanup with byfn.sh
aligned with v0.18.0 burrow release

Change-Id: If8285bce6bd7eb1cb313a37082b2d1419fe75442
Signed-off-by: Christopher Ferris <chrisfer@us.ibm.com>
  • Loading branch information
christo4ferris committed Jun 1, 2018
1 parent 526eb00 commit 298759f
Show file tree
Hide file tree
Showing 12 changed files with 829 additions and 41 deletions.
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright IBM Corp. All Rights Reserved
# SPDX-License-Identifier: Apache-2.0
#
# REQUIRES fabric-buildenv image
# git checkout github.com/hyperledger/fabric && cd fabric && make buildenv
#
# This is the second phase of the fabric-peer-evm image build.
# The first phase builds a baseline image (fabric-peer-evm-base:latest)
# that has a peer built with the 'pluginsenabled' tag set and which
# has the merged vendored dependencies of fabric and the evm plugin.
# If only the go source of the plugin, or the core.yaml have changed, only
# this phase will be built, saving considerable build time.
#
ARG GO_TAGS
ARG CGO_LDFLAGS_ALLOW

FROM fabric-peer-evm-base:latest as evmscc-builder
COPY ./plugin/evmscc.go ./plugin/evmscc.go
COPY ./statemanager/statemanager.go ./statemanager/statemanager.go
RUN sed -i 's/fabric-chaincode-evm/fabric/g' ./plugin/evmscc.go
RUN dep ensure
RUN ${CGO_LDFLAGS_ALLOW} go build -o /go/lib/evmscc.so -tags '${GO_TAGS}' -buildmode=plugin ./plugin

FROM hyperledger/fabric-peer:latest
COPY --from=evmscc-builder /opt/gopath/src/github.com/hyperledger/fabric/.build/bin/peer /usr/local/bin/peer
COPY --from=evmscc-builder /go/lib/evmscc.so /opt/lib/evmscc.so
COPY config/core.yaml /etc/hyperledger/fabric
30 changes: 30 additions & 0 deletions Dockerfile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Copyright IBM Corp. All Rights Reserved
# SPDX-License-Identifier: Apache-2.0
#
# REQUIRES fabric-buildenv image
# git checkout github.com/hyperledger/fabric && cd fabric && make buildenv
#
# This is the first phase of the fabric-peer-evm image build.
# This phase builds a baseline image (fabric-peer-evm-base:latest)
# that has a peer built with the 'pluginsenabled' tag set and which
# has the merged vendored dependencies of fabric and the evm plugin.
# This phase takes considerably longer than phase 2 (Dockerfile) because
# it must solve for the new dependencies of the plugin and import those into
# the vendor directory of the cloned fabric repository.
#
ARG GO_TAGS
ARG CGO_LDFLAGS_ALLOW

FROM hyperledger/fabric-buildenv:latest
WORKDIR $GOPATH/src/github.com/hyperledger/
RUN git clone https://github.com/hyperledger/fabric.git
WORKDIR $GOPATH/src/github.com/hyperledger/fabric
RUN git checkout master
RUN EXECUTABLES=go GO_TAGS=pluginsenabled EXPERIMENTAL=false DOCKER_DYNAMIC_LINK=true make peer

COPY ./plugin/evmscc.go ./plugin/evmscc.go
COPY ./statemanager/statemanager.go ./statemanager/statemanager.go
RUN sed -i 's/fabric-chaincode-evm/fabric/g' ./plugin/evmscc.go
RUN sed -i '/[[prune]]/ i [[constraint]]\n version = "v0.18.0"\n name = "github.com/hyperledger/burrow"\n\n[[override]]\n revision = "13ed8ac0738b1390630f86f6bf0943730c6d8037"\n name = "github.com/tmthrgd/go-hex"\n\n[[override]]\n revision = "dd20358a264c772b4a83e477b0cfce4c88a7001d"\n name = "github.com/tendermint/go-crypto"\n\n[[override]]\n version = "~0.6.0"\n name = "github.com/tendermint/tmlibs"' ./Gopkg.toml
RUN dep ensure
72 changes: 46 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
# - check-deps - check for vendored dependencies that are no longer used
# - checks - runs all non-integration tests/checks
# - clean - cleans the build area
# - docker - builds the hyperledger/fabric-peer-evm image
# - docker-base - builds the base peer image for the docker multi-stage build
# - evmscc - build evmscc shared library for native OS
# - evmscc-linux - build evmscc shared library for Linux, so it could be used in Docker
# - evmscc-linux build evmscc shared library for linux
# - gotools - installs go tools like golint
# - license - checks go source files for Apache license header
# - linter - runs all code checks
# - unit-test - runs the go-test based unit tests
# - integration-test - runs the e2e_cli based test

ARCH=$(shell go env GOARCH)
BASEIMAGE_RELEASE=0.4.8
Expand All @@ -26,10 +29,12 @@ BASE_DOCKER_TAG=$(ARCH)-$(BASEIMAGE_RELEASE)
EVMSCC=github.com/hyperledger/fabric-chaincode-evm
FABRIC=github.com/hyperledger/fabric
LIB_DIR=/opt/gopath/lib

GO_TAGS=nopkcs11
BUILD_DIR ?= .build
GOOS ?= $(shell go env GOOS)

PACKAGES = ./statemanager/... ./plugin/...
SRCFILES = ./plugin/evmscc.go ./statemanager/statemanager.go

# We need this flag due to https://github.com/golang/go/issues/23739
CGO_LDFLAGS_ALLOW = CGO_LDFLAGS_ALLOW="-I/usr/local/share/libtool"
Expand All @@ -38,7 +43,7 @@ EXECUTABLES ?= go docker git curl
K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH: Check dependencies")))

all: checks evmscc-linux
all: checks evmscc docker integration-test

checks: basic-checks unit-test

Expand All @@ -58,41 +63,56 @@ include gotools.mk
gotools: gotools-install

unit-test: $(PROJECT_FILES)
echo "Running unit-tests"
go test -tags \"$(GO_TAGS)\" $(PACKAGES)
@echo "Running unit-tests"
@go test -tags "$(GO_TAGS)" $(PACKAGES)

unit-tests: unit-test

linter: check-deps
@echo "LINT: Running code checks.."
./scripts/golinter.sh
@scripts/golinter.sh

check-deps:
check-deps:
@echo "DEP: Checking for dependency issues.."
./scripts/check_deps.sh
@scripts/check_deps.sh

changelog:
./scripts/changelog.sh v$(PREV_VERSION) v$(BASE_VERSION)
@scripts/changelog.sh v$(PREV_VERSION) v$(BASE_VERSION)

.PHONY: docker-base
docker-base: dependencies $(BUILD_DIR)/base-image/$(DUMMY)

$(BUILD_DIR)/base-image/$(DUMMY): Gopkg.toml Gopkg.lock
@mkdir -p $(@D)
@docker build --no-cache --build-arg GO_TAGS --build-arg CGO_LDFLAGS_ALLOW . -f Dockerfile.base -t fabric-peer-evm-base:latest
@touch $@

docker: docker-base $(BUILD_DIR)/peer-image/$(DUMMY)

$(BUILD_DIR)/peer-image/$(DUMMY): $(SRCFILES) ./config/core.yaml
@mkdir -p $(@D)
@docker build --no-cache --build-arg GO_TAGS --build-arg CGO_LDFLAGS_ALLOW . -t hyperledger/fabric-peer-evm:latest
@scripts/docker-cleanup.sh
@touch $@

.PHONY: dependencies
dependencies:
@scripts/check_docker_deps.sh

.PHONY: integration-test
integration-test: docker
@echo "Running integration-test"
@cd e2e_cli && ./network_setup.sh down && ./network_setup.sh up mychannel 1

evmscc: $(BUILD_DIR)/$(GOOS)/lib/evmscc.so

DRUN = docker run -i --rm $(DOCKER_RUN_FLAGS) -w /opt/gopath/src/$(EVMSCC)
evmscc-linux:
@GOOS=linux make evmscc

evmscc-linux: $(BUILD_DIR)/linux/lib/evmscc.so
$(BUILD_DIR)/linux/lib/evmscc.so:
$(BUILD_DIR)/$(GOOS)/lib/evmscc.so: docker
@echo "Extracting $(GOOS) evmscc.so from image"
@mkdir -p $(@D)
$(eval TMPDIR := $(shell mktemp -d /tmp/evmscc-build.XXXXX))
@echo $(TMPDIR)
@rsync -az --exclude=".*/" --exclude=".*" --exclude="build/" $(GOPATH)/src/$(FABRIC) $(TMPDIR)
@rsync -az --exclude=".*/" --exclude=".*" --exclude="build/" $(GOPATH)/src/$(EVMSCC) $(TMPDIR)
@echo "Building $@"
@$(DRUN) \
-v $(TMPDIR)/fabric-chaincode-evm:/opt/gopath/src/$(EVMSCC) \
-v $(TMPDIR)/fabric:/opt/gopath/src/$(FABRIC) \
-v $(abspath $(@D)):$(LIB_DIR) \
-v $(PWD)/scripts/build.sh:/opt/build.sh \
-e LIB_DIR=$(LIB_DIR) \
$(BASE_DOCKER_NS)/fabric-baseimage:$(BASE_DOCKER_TAG) \
bash -c '/opt/build.sh /opt/gopath/src/$(FABRIC) /opt/gopath/src/$(EVMSCC)'
@rm -rf $(TMPDIR)
@docker run --rm -v $(PWD)/$(@D):/tmp/build/ hyperledger/fabric-peer-evm:latest /bin/bash -c 'cp /opt/lib/evmscc.so /tmp/build/'

.PHONY: clean
clean:
Expand Down
Loading

0 comments on commit 298759f

Please sign in to comment.