Skip to content

Commit ee471b6

Browse files
g2flyermbrandenburger
authored andcommitted
Docker related changes
* enable containers (and related scripts) to be optionally SGX_MODE aware and run in HW mode iff SGX_MODE=HW * also some dockerfile cleanup Signed-off-by: michael steiner <[email protected]>
1 parent 13a2097 commit ee471b6

File tree

23 files changed

+227
-108
lines changed

23 files changed

+227
-108
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ env:
2323
- SGX_MODE=SIM
2424
- SGX_SDK=/opt/intel/sgxsdk
2525
# SGX SSL
26-
- OPENSSL=1.1.0j
26+
- OPENSSL_VERSION=1.1.0j
2727
- SGXSSL_VERSION=v2.4.1
2828
- SGXSSL=/opt/intel/sgxssl
2929
# NANOPB
@@ -51,8 +51,8 @@ before_install:
5151
- chmod +x ${SGX_SDK_BIN}
5252
- sudo sh -c "echo 'yes' | ./${SGX_SDK_BIN}"; popd
5353
# SGX SSL
54-
- pushd $HOME; git clone --branch $SGXSSL_VERSION https://github.com/intel/intel-sgx-ssl.git
55-
- wget https://www.openssl.org/source/openssl-$OPENSSL.tar.gz; mv openssl-$OPENSSL.tar.gz intel-sgx-ssl/openssl_source
54+
- pushd $HOME; git clone --branch ${SGXSSL_VERSION} https://github.com/intel/intel-sgx-ssl.git
55+
- wget https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz; mv openssl-${OPENSSL_VERSION}.tar.gz intel-sgx-ssl/openssl_source
5656
- cd intel-sgx-ssl/Linux; make SGX_MODE=SIM DESTDIR=$SGXSSL all test
5757
- cd intel-sgx-ssl/Linux; make install; popd
5858
# NANOPB

demo/README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,20 @@ Below is the script's help text.
5353
```
5454
startFPCAuctionNetwork.sh [options]
5555
56-
This script, by default, will teardown possible previous iterations of this demo, generate new
57-
crypto material for the network, start an FPC network as defined in $FPC_PATH/utils/docker-compose,
58-
install the mock golang auction chaincode($FPC_PATH/demo/chaincode/golang), install the FPC
59-
compliant auction chaincode($FPC_PATH/demo/chaincode/fpc), register auction users, and bring up
60-
both the fabric-gatway & frontend UI. If the fabric-gateway and frontend UI docker images have
61-
not previously been built it will build them, otherwise the script will reuse the images already
62-
existing. The FPC chaincode will not be built unless specified by the flag --build-cc.
63-
By calling the script with both build options, you will be able to run the demo without having
64-
to build the whole FPC project (e.g., by calling `make` in $FPC_PATH).
56+
This script, by default, will teardown possible previous iterations of this
57+
demo, generate new crypto material for the network, start an FPC network as
58+
defined in \$FPC_PATH/utils/docker-compose, install the mock golang auction
59+
chaincode(\$FPC_PATH/demo/chaincode/golang), install the FPC compliant
60+
auction chaincode(\$FPC_PATH/demo/chaincode/fpc), register auction users,
61+
and bring up both the fabric-gatway & frontend UI.
62+
63+
If the fabric-gateway and frontend UI docker images have not previously been
64+
built it will build them, otherwise the script will reuse the images already
65+
existing. You can force a rebuild, though, by specifying the flag
66+
--build-client. The FPC chaincode will not be built unless specified by the
67+
flag --build-cc. By calling the script with both build options, you will be
68+
able to run the demo without having to build the whole FPC project (e.g., by
69+
calling `make` in $FPC_PATH).
6570
6671
options:
6772
--build-cc:
@@ -95,8 +100,10 @@ will delete all the unused volumes and chaincode images.
95100

96101
### Scripting
97102

98-
To facilitate demonstrations and also to help in testing, you can specify a scenario script defining the
99-
actions of the different parties and execute it using the command [scenario-run.sh](client/scripting/scenario-run.sh).
103+
To facilitate demonstrations and also to help in testing, you can specify with a simple
104+
[DSL](client/scripting/lib/dsl.sh) a scenario script defining the
105+
actions of the different parties and execute it using the command
106+
[scenario-run.sh](client/scripting/scenario-run.sh).
100107
Below is the script's help text.
101108
```
102109
scenario-run.sh [--help|-h|-?] [--bootstrap|-b] [--dry-run|-d] [--non-interactive|-n] [--skip-delay|-s] [--mock-reset|-r] <script-file>

demo/chaincode/fpc/Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,21 @@ build: $(BUILD_DIR)
2828
clean:
2929
-rm -rf $(BUILD_DIR)
3030

31+
32+
HW_EXTENSION=$(shell if [ "${SGX_MODE}" = "HW" ]; then echo "-hw"; fi)
33+
34+
FPC_DOCKER_NAMESPACE := hyperledger/fabric-private-chaincode
35+
FPC_DOCKER_CC_BUILDER_NAME = $(FPC_DOCKER_NAMESPACE)-cc-builder$(HW_EXTENSION)
36+
3137
docker-build: clean
32-
$(DOCKER) image inspect hyperledger/fabric-private-chaincode-cc-builder > /dev/null 2>&1 || { cd $(TOP)/utils/docker && make cc-builder; }
33-
$(DOCKER) run -u $$(id -u):$$(id -g) -v ${PWD}:/project/src/github.com/hyperledger-labs/fabric-private-chaincode/demo/chaincode/fpc -w /project/src/github.com/hyperledger-labs/fabric-private-chaincode/demo/chaincode/fpc hyperledger/fabric-private-chaincode-cc-builder sh -c 'make build'
38+
$(DOCKER) image inspect $(FPC_DOCKER_CC_BUILDER_NAME) > /dev/null 2>&1 \
39+
|| { cd $(TOP)/utils/docker && make cc-builder; }
40+
$(DOCKER) run \
41+
-u $$(id -u):$$(id -g)\
42+
-v ${PWD}:/project/src/github.com/hyperledger-labs/fabric-private-chaincode/demo/chaincode/fpc\
43+
-w /project/src/github.com/hyperledger-labs/fabric-private-chaincode/demo/chaincode/fpc\
44+
$(FPC_DOCKER_CC_BUILDER_NAME)\
45+
sh -c 'make build'
3446

3547
test: build
3648
./test.sh

demo/client/frontend/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public/img/users/c-mobile.svg:
6666

6767

6868
clobber:
69+
RUNNING_IMAGE=$$(${DOCKER} ps -q --filter ancestor=${DOCKER_IMAGE}); \
70+
if [ ! -z "$${RUNNING_IMAGE}" ]; then ${DOCKER} kill $${RUNNING_IMAGE}; fi
6971
IMAGE=$$(${DOCKER} images ${DOCKER_IMAGE} -q); \
70-
if [ ! -z "$${IMAGE}" ]; then ${DOCKER} rmi ${IMAGE}; fi
72+
if [ ! -z "$${IMAGE}" ]; then ${DOCKER} rmi -f $${IMAGE}; fi
7173
# make clobber in demo/ also would take care but better safe than sorry
7274
-$(RM) $(AVATAR_FILES)

demo/client/scripting/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ${GO_CMDS}: ${GO_CMDS:=.go}
1414
$(GO) build $@.go
1515

1616
test: build
17-
./scenario-run.sh --bootstrap --non-interactive ../../scenario/script
17+
./scenario-run.sh --bootstrap --non-interactive ../../scenario/script
1818

1919
clean:
2020
$(GO) $@

demo/scripts/startFPCAuctionNetwork.sh

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,32 @@ set -e
1111
help(){
1212
echo "$(basename $0) [options]
1313
14-
This script, by default, will teardown possible previous iterations of this demo, generate new
15-
crypto material for the network, start an FPC network as defined in \$FPC_PATH/utils/docker-compose,
16-
install the mock golang auction chaincode(\$FPC_PATH/demo/chaincode/golang), install the FPC
17-
compliant auction chaincode(\$FPC_PATH/demo/chaincode/fpc), register auction users, and bring up
18-
both the fabric-gatway & frontend UI. If the fabric-gateway and frontend UI docker images have
19-
not previously been built it will build them, otherwise the script will reuse the images already
20-
existing. The FPC chaincode will not be built unless specified by the flag --build-cc.
14+
This script, by default, will teardown possible previous iterations of this
15+
demo, generate new crypto material for the network, start an FPC network as
16+
defined in \$FPC_PATH/utils/docker-compose, install the mock golang auction
17+
chaincode(\$FPC_PATH/demo/chaincode/golang), install the FPC compliant
18+
auction chaincode(\$FPC_PATH/demo/chaincode/fpc), register auction users,
19+
and bring up both the fabric-gatway & frontend UI.
20+
21+
If the fabric-gateway and frontend UI docker images have not previously been
22+
built it will build them, otherwise the script will reuse the images already
23+
existing. You can force a rebuild, though, by specifying the flag
24+
--build-client. The FPC chaincode will not be built unless specified by the
25+
flag --build-cc. By calling the script with both build options, you will be
26+
able to run the demo without having to build the whole FPC project (e.g., by
27+
calling 'make' in \$FPC_PATH).
2128
2229
options:
2330
--build-cc:
24-
As part of bringing up the demo components, the auction cc in demo/chaincode/fpc will
25-
be rebuilt using the docker-build make target.
31+
As part of bringing up the demo components, the auction cc in
32+
demo/chaincode/fpc will be rebuilt using the docker-build make target.
2633
--build-client:
27-
As part of bringing up the demo components, the Fabric Gateway and the UI docker images
28-
will be built or rebuilt using current source code.
34+
As part of bringing up the demo components, the Fabric Gateway and
35+
the UI docker images will be built or rebuilt using current source
36+
code.
2937
--help,-h:
3038
Print this help screen.
31-
"
39+
"
3240
}
3341

3442

@@ -75,7 +83,7 @@ if $BUILD_CHAINCODE; then
7583
echo ""
7684
echo "Building FPC Auction Chaincode"
7785
pushd ${DEMO_ROOT}/chaincode/fpc
78-
make docker-build
86+
make SGX_MODE=${SGX_MODE} docker-build
7987
popd
8088
fi
8189

ecc/Dockerfile.boilerplate-ecc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ ARG CC_NAME="ecc"
88
ARG CC_PATH="/usr/local/bin"
99
ARG CC_LIB_PATH=${CC_PATH}"/enclave/lib"
1010

11+
ARG SGX_MODE
12+
ENV SGX_MODE=${SGX_MODE}
13+
# Note: the library copied below is SGX_MODE dependent, so we
14+
# define here a env which makes it easy recognizable which mode
15+
# the container is. No default, though, as we do not control
16+
# the build and rely on a proper value provided from outside.
17+
18+
1119
RUN mkdir -p ${CC_LIB_PATH}
1220

1321
ENV SGX_SDK=/opt/intel/sgxsdk

ecc/Dockerfile.fpc-app

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
FROM hyperledger/fabric-private-chaincode-boilerplate-ecc
5+
ARG BOILERPLATE_EXTENSION
6+
7+
FROM hyperledger/fabric-private-chaincode-boilerplate-ecc${BOILERPLATE_EXTENSION}
68

79
ARG enclave_so_path
810
ARG CC_PATH="/usr/local/bin"

ecc/Makefile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ VSCC_OUT = ecc-vscc.so
1616
DOCKER_CONTAINER_ID?=$$(docker ps | grep -- ${NET_ID}-${PEER_ID}-$(CC_NAME)- | awk '{print $$1;}')
1717
# the following are the required docker build parameters
1818
DOCKER_IMAGE ?= $$(docker images | grep -- ${NET_ID}-${PEER_ID}-$(CC_NAME)- | awk '{print $$1;}')
19-
DOCKER_BOILERPLATE_ECC_IMAGE ?= hyperledger/$(PROJECT_NAME)-boilerplate-ecc
19+
BOILERPLATE_EXTENSION=$(shell if [ "${SGX_MODE}" = "HW" ]; then echo "-hw"; fi)
20+
DOCKER_BOILERPLATE_ECC_IMAGE ?= hyperledger/$(PROJECT_NAME)-boilerplate-ecc$(BOILERPLATE_EXTENSION)
2021
INSTALLED_DOCKER_BOILERPLATE_ECC_IMAGE ?= $$(docker images | grep -- ${DOCKER_BOILERPLATE_ECC_IMAGE} | awk '{print $$1;}')
2122
DOCKER_ENCLAVE_SO_PATH ?= $(ENCLAVE_SO_PATH)
2223

@@ -71,21 +72,29 @@ ifdef FORCE_REBUILD
7172
endif
7273

7374
docker-boilerplate-ecc: ecc
74-
$(DOCKER) build $(DOCKER_BUILD_OPTS) -t $(DOCKER_BOILERPLATE_ECC_IMAGE) -f Dockerfile.boilerplate-ecc ..
75+
$(DOCKER) build $(DOCKER_BUILD_OPTS) -t $(DOCKER_BOILERPLATE_ECC_IMAGE) -f Dockerfile.boilerplate-ecc\
76+
--build-arg SGX_MODE=$(SGX_MODE)\
77+
..
7578

7679
docker-fpc-app: docker-boilerplate-ecc
7780
if [ -z "$(DOCKER_IMAGE)" ]; then\
7881
echo "\033[0;31mERROR: cannot override $(CC_NAME) docker image - not found\033[0m";\
7982
exit 1;\
8083
fi
8184
echo "\033[1;33mWARNING: overriding $(DOCKER_IMAGE) docker image\033[0m"
82-
$(DOCKER) build $(DOCKER_BUILD_OPTS) -t $(DOCKER_IMAGE) -f Dockerfile.fpc-app --build-arg enclave_so_path=$(DOCKER_ENCLAVE_SO_PATH) ..
85+
$(DOCKER) build $(DOCKER_BUILD_OPTS) -t $(DOCKER_IMAGE) -f Dockerfile.fpc-app \
86+
--build-arg BOILERPLATE_EXTENSION=$(BOILERPLATE_EXTENSION)\
87+
--build-arg enclave_so_path=$(DOCKER_ENCLAVE_SO_PATH)\
88+
..
8389

8490
docker-run:
91+
if [ "$(SGX_MODE)" = "HW" ]; then \
92+
SGX_DEVICE_PATH=$(if [ -e "/dev/isgx" ]; then echo "/dev/isgx"; elif [ -e "/dev/sgx" ]; then echo "/dev/sgx"; else echo "ERROR: NO SGX DEVICE FOUND"; fi);\
93+
DOCKER_SGX_ARGS="--device $${SGX_DEVICE_PATH} -v /var/run/aesmd:/var/run/aesmd";\
94+
fi;\
8595
$(DOCKER) run \
8696
-it \
87-
--device /dev/isgx \
88-
-v /var/run/aesmd:/var/run/aesmd \
97+
$${DOCKER_SGX_ARGS} \
8998
--name $(CC_NAME) \
9099
-e "CORE_CHAINCODE_LOGGING_LEVEL=DEBUG" \
91100
-e "CORE_CHAINCODE_LOGGING_SHIM=INFO" \

fabric/bin/peer.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ FPC_TOP_DIR="${SCRIPTDIR}/../../"
1010
FABRIC_SCRIPTDIR="${FPC_TOP_DIR}/fabric/bin/"
1111

1212
: ${FABRIC_CFG_PATH:=$(pwd)}
13+
: ${SGX_MODE:=SIM}
1314

1415
. ${FABRIC_SCRIPTDIR}/lib/common_utils.sh
1516
. ${FABRIC_SCRIPTDIR}/lib/common_ledger.sh
@@ -69,7 +70,7 @@ handle_chaincode_install() {
6970
DOCKER_IMAGE_NAME=$(${FPC_DOCKER_NAME_CMD} --cc-name ${FPC_NAME} --cc-version ${CC_VERSION} --net-id ${NET_ID} --peer-id ${PEER_ID}) || die "could not get docker image name"
7071

7172
# install docker
72-
try make ENCLAVE_SO_PATH=${CC_ENCLAVESOPATH} DOCKER_IMAGE=${DOCKER_IMAGE_NAME} -C ${FPC_TOP_DIR}/ecc docker-fpc-app
73+
try make SGX_MODE=${SGX_MODE} ENCLAVE_SO_PATH=${CC_ENCLAVESOPATH} DOCKER_IMAGE=${DOCKER_IMAGE_NAME} -C ${FPC_TOP_DIR}/ecc docker-fpc-app
7374

7475
# eplace path and lang arg with dummy go chaincode
7576
ARGS_EXEC=( 'chaincode' 'install' '-n' "${FPC_NAME}" '-v' "${CC_VERSION}" '-p' 'github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd' "${OTHER_ARGS[@]}" )

0 commit comments

Comments
 (0)