Skip to content

Commit

Permalink
Respect proxy settings in build scripts
Browse files Browse the repository at this point in the history
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 <y.namiki@gmail.com>
Change-Id: I226c115f49ec242b79ef56a34c03012fb11f78c6
  • Loading branch information
Namiki Yuta committed Nov 25, 2016
1 parent 1a52284 commit ee2b426
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ ifneq ($(OS),Darwin)
DOCKER_FLAGS=--user=$(shell id -u)
endif

ifneq ($(http_proxy),)
DOCKER_ARGS_PROXY+=--build-arg http_proxy=$(http_proxy)
DOCKER_FLAGS+=-e http_proxy=$(http_proxy)
endif
ifneq ($(https_proxy),)
DOCKER_ARGS_PROXY+=--build-arg https_proxy=$(https_proxy)
DOCKER_FLAGS+=-e https_proxy=$(https_proxy)
endif
ifneq ($(HTTP_PROXY),)
DOCKER_ARGS_PROXY+=--build-arg HTTP_PROXY=$(HTTP_PROXY)
DOCKER_FLAGS+=-e HTTP_PROXY=$(HTTP_PROXY)
endif
ifneq ($(HTTPS_PROXY),)
DOCKER_ARGS_PROXY+=--build-arg HTTPS_PROXY=$(HTTPS_PROXY)
DOCKER_FLAGS+=-e HTTPS_PROXY=$(HTTPS_PROXY)
endif
ifneq ($(no_proxy),)
DOCKER_ARGS_PROXY+=--build-arg no_proxy=$(no_proxy)
DOCKER_FLAGS+=-e no_proxy=$(no_proxy)
endif
ifneq ($(NO_PROXY),)
DOCKER_ARGS_PROXY+=--build-arg NO_PROXY=$(NO_PROXY)
DOCKER_FLAGS+=-e NO_PROXY=$(NO_PROXY)
endif

DRUN = docker run -i --rm $(DOCKER_FLAGS) \
-v $(abspath .):/opt/gopath/src/$(PKGNAME) \
-w /opt/gopath/src/$(PKGNAME)
Expand Down Expand Up @@ -196,7 +221,7 @@ build/image/%/.dummy: Makefile build/image/%/payload
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
> $(@D)/Dockerfile
docker build -t $(PROJECT_NAME)-$(TARGET) $(@D)
docker build $(DOCKER_ARGS_PROXY) -t $(PROJECT_NAME)-$(TARGET) $(@D)
docker tag $(PROJECT_NAME)-$(TARGET) $(PROJECT_NAME)-$(TARGET):$(DOCKER_TAG)
@touch $@

Expand Down
15 changes: 15 additions & 0 deletions core/chaincode/shim/java/javabuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
set -e
PARENTDIR=$(pwd)

function getProxyHost {
ADDR=${1#*://}
echo ${ADDR%:*}
}

function getProxyPort {
ADDR=${1#*://}
echo ${ADDR#*:}
}

[ -n "$http_proxy" ] && JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=$(getProxyHost $http_proxy) -Dhttp.proxyPort=$(getProxyPort $http_proxy)"
[ -n "$https_proxy" ] && JAVA_OPTS="$JAVA_OPTS -Dhttps.proxyHost=$(getProxyHost $https_proxy) -Dhttps.proxyPort=$(getProxyPort $https_proxy)"
[ -n "$HTTP_PROXY" ] && JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=$(getProxyHost $HTTP_PROXY) -Dhttp.proxyPort=$(getProxyPort $HTTP_PROXY)"
[ -n "$HTTPS_PROXY" ] && JAVA_OPTS="$JAVA_OPTS -Dhttps.proxyHost=$(getProxyHost $HTTPS_PROXY) -Dhttps.proxyPort=$(getProxyPort $HTTPS_PROXY)"
export JAVA_OPTS

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

0 comments on commit ee2b426

Please sign in to comment.