Skip to content

Commit ee2b426

Browse files
author
Namiki Yuta
committed
Respect proxy settings in build scripts
Respect proxy settings to build Fabric behind a proxy. Set environment values http_proxy, HTTP_PROXY, https_proxy or HTTPS_PROXY and execute `make peer`. This patch fixes FAB-308. To build docker javaenv-image, the Internet access is needed for wget Gradle distribution. So we need to pass proxy configurations by build arg to Docker. Additionally, in core/chaincode/shim/java/build.gradle, Gradle will get com.google.protobuf plugin from the Internet during build process. Because this process is executed in docker-build, defining JAVA_OPTS in the host, which execute docker-build, is no effect. Signed-off-by: Namiki Yuta <[email protected]> Change-Id: I226c115f49ec242b79ef56a34c03012fb11f78c6
1 parent 1a52284 commit ee2b426

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

Makefile

+26-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@ ifneq ($(OS),Darwin)
6363
DOCKER_FLAGS=--user=$(shell id -u)
6464
endif
6565

66+
ifneq ($(http_proxy),)
67+
DOCKER_ARGS_PROXY+=--build-arg http_proxy=$(http_proxy)
68+
DOCKER_FLAGS+=-e http_proxy=$(http_proxy)
69+
endif
70+
ifneq ($(https_proxy),)
71+
DOCKER_ARGS_PROXY+=--build-arg https_proxy=$(https_proxy)
72+
DOCKER_FLAGS+=-e https_proxy=$(https_proxy)
73+
endif
74+
ifneq ($(HTTP_PROXY),)
75+
DOCKER_ARGS_PROXY+=--build-arg HTTP_PROXY=$(HTTP_PROXY)
76+
DOCKER_FLAGS+=-e HTTP_PROXY=$(HTTP_PROXY)
77+
endif
78+
ifneq ($(HTTPS_PROXY),)
79+
DOCKER_ARGS_PROXY+=--build-arg HTTPS_PROXY=$(HTTPS_PROXY)
80+
DOCKER_FLAGS+=-e HTTPS_PROXY=$(HTTPS_PROXY)
81+
endif
82+
ifneq ($(no_proxy),)
83+
DOCKER_ARGS_PROXY+=--build-arg no_proxy=$(no_proxy)
84+
DOCKER_FLAGS+=-e no_proxy=$(no_proxy)
85+
endif
86+
ifneq ($(NO_PROXY),)
87+
DOCKER_ARGS_PROXY+=--build-arg NO_PROXY=$(NO_PROXY)
88+
DOCKER_FLAGS+=-e NO_PROXY=$(NO_PROXY)
89+
endif
90+
6691
DRUN = docker run -i --rm $(DOCKER_FLAGS) \
6792
-v $(abspath .):/opt/gopath/src/$(PKGNAME) \
6893
-w /opt/gopath/src/$(PKGNAME)
@@ -196,7 +221,7 @@ build/image/%/.dummy: Makefile build/image/%/payload
196221
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
197222
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
198223
> $(@D)/Dockerfile
199-
docker build -t $(PROJECT_NAME)-$(TARGET) $(@D)
224+
docker build $(DOCKER_ARGS_PROXY) -t $(PROJECT_NAME)-$(TARGET) $(@D)
200225
docker tag $(PROJECT_NAME)-$(TARGET) $(PROJECT_NAME)-$(TARGET):$(DOCKER_TAG)
201226
@touch $@
202227

core/chaincode/shim/java/javabuild.sh

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
set -e
2020
PARENTDIR=$(pwd)
2121

22+
function getProxyHost {
23+
ADDR=${1#*://}
24+
echo ${ADDR%:*}
25+
}
26+
27+
function getProxyPort {
28+
ADDR=${1#*://}
29+
echo ${ADDR#*:}
30+
}
31+
32+
[ -n "$http_proxy" ] && JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=$(getProxyHost $http_proxy) -Dhttp.proxyPort=$(getProxyPort $http_proxy)"
33+
[ -n "$https_proxy" ] && JAVA_OPTS="$JAVA_OPTS -Dhttps.proxyHost=$(getProxyHost $https_proxy) -Dhttps.proxyPort=$(getProxyPort $https_proxy)"
34+
[ -n "$HTTP_PROXY" ] && JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=$(getProxyHost $HTTP_PROXY) -Dhttp.proxyPort=$(getProxyPort $HTTP_PROXY)"
35+
[ -n "$HTTPS_PROXY" ] && JAVA_OPTS="$JAVA_OPTS -Dhttps.proxyHost=$(getProxyHost $HTTPS_PROXY) -Dhttps.proxyPort=$(getProxyPort $HTTPS_PROXY)"
36+
export JAVA_OPTS
2237

2338
gradle -q -b ${PARENTDIR}/core/chaincode/shim/java/build.gradle clean
2439
gradle -q -b ${PARENTDIR}/core/chaincode/shim/java/build.gradle build

0 commit comments

Comments
 (0)