Skip to content

Commit 35d5884

Browse files
author
Simon Stone
committed
[FAB-6415] Various chaincode deployment updates
Update to latest Docker Gradle plugin - Removes various build warnings. Use Gradle wrapper (./gradlew) if present in chaincode - Enables chaincode developer to specify own Gradle version. Remove v1.3 version of shim from Docker image - Why was this ever added? Certainly not needed for Fabric v2.0. Add jitpack.io to generated Maven POM -Maven can't find the JSON dependencies. Add support for Gradle build scripts written in Kotlin - Latest version of Gradle supports Kotlin build script, we need to check for this when trying to figure out what kind of project we're dealing with. Enable JAR file deployment - If JARs are present and no Gradle/Maven files are present, then just use the JARs. Only works with new programming model. Significantly improves deployment time, as no compilation occurs. Add tests for all of the above! Signed-off-by: Simon Stone <[email protected]> Change-Id: I66ba7bd433377f2ea87fe6bc3eb99231cd2fe761
1 parent 2f6be19 commit 35d5884

File tree

26 files changed

+1095
-167
lines changed

26 files changed

+1095
-167
lines changed

fabric-chaincode-docker/Dockerfile

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,24 @@ RUN mkdir -p /root/chaincode-java/chaincode/build/out
2828
RUN chmod +x /root/chaincode-java/start
2929
RUN chmod +x /root/chaincode-java/build.sh
3030

31-
# Start build shim jars
31+
# Build protos and shim jar and installing them to maven local and gradle cache
3232
WORKDIR /root/chaincode-java/shim-src
33-
RUN gradle clean
34-
35-
# Building protobuf jar and installing it to maven local and gradle cache
36-
WORKDIR /root/chaincode-java/shim-src/fabric-chaincode-protos
37-
RUN gradle clean build install publishToMavenLocal -x test
38-
# Installing all jar dependencies to maven local
33+
RUN gradle \
34+
clean \
35+
fabric-chaincode-protos:build \
36+
fabric-chaincode-protos:install \
37+
fabric-chaincode-protos:publishToMavenLocal \
38+
fabric-chaincode-shim:build \
39+
fabric-chaincode-shim:install \
40+
fabric-chaincode-shim:publishToMavenLocal \
41+
-x javadoc \
42+
-x test
43+
44+
# Installing all protos jar dependencies to maven local
3945
WORKDIR /root/chaincode-java/shim-src/fabric-chaincode-protos/build/publications/protosJar/
4046
RUN mvn -f pom-default.xml compile
4147

42-
# Building shim jar and installing it to maven local and gradle cache
43-
WORKDIR /root/chaincode-java/shim-src/fabric-chaincode-shim
44-
RUN gradle clean build install publishToMavenLocal -x test
45-
# Installing all jar dependencies to maven local
48+
# Installing all shim jar dependencies to maven local
4649
WORKDIR /root/chaincode-java/shim-src/fabric-chaincode-shim/build/publications/shimJar/
4750
RUN mvn -f pom-default.xml compile
4851

@@ -53,15 +56,6 @@ WORKDIR /root/chaincode-java/example-src/fabric-chaincode-example-maven
5356
RUN mvn compile package
5457
WORKDIR /root/chaincode-java
5558

56-
# Adding shim 1.3.0 jar
57-
WORKDIR /tmp
58-
RUN wget https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.3.0/fabric-chaincode-shim-1.3.0.pom
59-
RUN wget https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.3.0/fabric-chaincode-shim-1.3.0.jar
60-
RUN wget https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-chaincode-java/fabric-chaincode-protos/1.3.0/fabric-chaincode-protos-1.3.0.pom
61-
RUN wget https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-chaincode-java/fabric-chaincode-protos/1.3.0/fabric-chaincode-protos-1.3.0.jar
62-
RUN mvn install::install-file -Dfile=fabric-chaincode-protos-1.3.0.jar -DpomFile=fabric-chaincode-protos-1.3.0.pom
63-
RUN mvn install::install-file -Dfile=fabric-chaincode-shim-1.3.0.jar -DpomFile=fabric-chaincode-shim-1.3.0.pom
64-
6559
#Removing non-needed sources
6660
WORKDIR /root/chaincode-java
6761
RUN rm -rf example-src

fabric-chaincode-docker/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ buildscript {
1313
mavenCentral()
1414
}
1515
dependencies {
16-
classpath 'com.bmuschko:gradle-docker-plugin:3.2.6'
16+
classpath 'com.bmuschko:gradle-docker-plugin:4.10.0'
1717
}
1818
}
1919

fabric-chaincode-docker/build.sh

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
INPUT_DIR=/chaincode/input
5+
OUTPUT_DIR=/chaincode/output
6+
JARS=$(find ${INPUT_DIR} -name ".jar" | paste -s -d ":" -)
7+
NUM_JARS=$(find ${INPUT_DIR} -name "*.jar" | wc -l)
28

39
buildGradle() {
410
cd "$1" > /dev/null
511
echo "Gradle build"
6-
gradle build shadowJar
12+
if [ -f ./gradlew ]; then
13+
chmod +x ./gradlew
14+
./gradlew build shadowJar
15+
else
16+
gradle build shadowJar
17+
fi
718
retval=$?
819
if [ $retval -ne 0 ]; then
920
exit $retval
@@ -13,6 +24,7 @@ buildGradle() {
1324
if [ $retval -ne 0 ]; then
1425
exit $retval
1526
fi
27+
touch $2/.uberjar
1628
cd "$SAVED" >/dev/null
1729
}
1830

@@ -29,60 +41,25 @@ buildMaven() {
2941
if [ $retval -ne 0 ]; then
3042
exit $retval
3143
fi
44+
touch $2/.uberjar
3245
cd "$SAVED" >/dev/null
3346
}
3447

35-
# Attempt to set APP_HOME
36-
# Resolve links: $0 may be a link
37-
PRG="$0"
38-
# Need this for relative symlinks.
39-
while [ -h "$PRG" ] ; do
40-
ls=`ls -ld "$PRG"`
41-
link=`expr "$ls" : '.*-> \(.*\)$'`
42-
if expr "$link" : '/.*' > /dev/null; then
43-
PRG="$link"
44-
else
45-
PRG=`dirname "$PRG"`"/$link"
48+
for DIR in ${INPUT_DIR} ${INPUT_DIR}/src; do
49+
if [ -f ${DIR}/build.gradle -o -f ${DIR}/build.gradle.kts ]; then
50+
buildGradle ${DIR} ${OUTPUT_DIR}
51+
exit 0
52+
elif [ -f ${DIR}/pom.xml ]; then
53+
buildMaven ${DIR} ${OUTPUT_DIR}
54+
exit 0
4655
fi
4756
done
48-
SAVED="`pwd`"
49-
cd "`dirname \"$PRG\"`" >/dev/null
50-
APP_HOME="`pwd -P`"
51-
cd "$SAVED" >/dev/null
52-
53-
APP_NAME="build.sh"
54-
APP_BASE_NAME=`basename "$0"`
55-
56-
if [ -d "/chaincode/output" ]
57-
then
58-
rm -rf /chaincode/output/*
59-
else
60-
mkdir -p /chaincode/output/
61-
fi
62-
63-
if [ -d "${APP_HOME}/chaincode/build/out" ]
64-
then
65-
rm -rf ${APP_HOME}/chaincode/build/out/*
66-
else
67-
mkdir -p ${APP_HOME}/chaincode/build/out
68-
fi
6957

70-
71-
if [ -f "/chaincode/input/src/build.gradle" ]
72-
then
73-
buildGradle /chaincode/input/src/ /chaincode/output/
74-
elif [ -f "/chaincode/input/build.gradle" ]
75-
then
76-
buildGradle /chaincode/input/ /chaincode/output/
77-
elif [ -f "/chaincode/input/src/pom.xml" ]
78-
then
79-
buildMaven /chaincode/input/src/ /chaincode/output/
80-
elif [ -f "/chaincode/input/pom.xml" ]
81-
then
82-
buildMaven /chaincode/input/ /chaincode/output/
83-
else
84-
>&2 echo "Not build.gralde nor pom.xml found in chaincode source, don't know how to build chaincode"
58+
if [ ${NUM_JARS} -eq 0 ]; then
59+
>&2 echo "Not build.gradle nor pom.xml found in chaincode source, don't know how to build chaincode"
8560
>&2 echo "Project folder content:"
86-
>&2 find /chaincode/input/src/ -name "*" -exec ls -ld '{}' \;
61+
>&2 find ${INPUT_DIR} -name "*" -exec ls -ld '{}' \;
8762
exit 255
88-
fi
63+
else
64+
cd ${INPUT_DIR} && tar cf - $(find . -name "*.jar") | (cd ${OUTPUT_DIR} && tar xvf -)
65+
fi

fabric-chaincode-docker/start

Lines changed: 16 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,19 @@
11
#!/usr/bin/env bash
2-
3-
# Attempt to set APP_HOME
4-
# Resolve links: $0 may be a link
5-
PRG="$0"
6-
# Need this for relative symlinks.
7-
while [ -h "$PRG" ] ; do
8-
ls=`ls -ld "$PRG"`
9-
link=`expr "$ls" : '.*-> \(.*\)$'`
10-
if expr "$link" : '/.*' > /dev/null; then
11-
PRG="$link"
12-
else
13-
PRG=`dirname "$PRG"`"/$link"
14-
fi
15-
done
16-
SAVED="`pwd`"
17-
cd "`dirname \"$PRG\"`" >/dev/null
18-
APP_HOME="`pwd -P`"
19-
cd "$SAVED" >/dev/null
20-
21-
APP_NAME="start"
22-
APP_BASE_NAME=`basename "$0"`
23-
24-
# Use the maximum available, or set MAX_FD != -1 to use that value.
25-
MAX_FD="maximum"
26-
27-
warn () {
28-
echo "$*"
29-
}
30-
31-
die () {
32-
echo
33-
echo "$*"
34-
echo
35-
exit 1
36-
}
37-
38-
# Determine the Java command to use to start the JVM.
39-
if [ -n "$JAVA_HOME" ] ; then
40-
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
41-
# IBM's JDK on AIX uses strange locations for the executables
42-
JAVACMD="$JAVA_HOME/jre/sh/java"
43-
else
44-
JAVACMD="$JAVA_HOME/bin/java"
45-
fi
46-
if [ ! -x "$JAVACMD" ] ; then
47-
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
48-
49-
Please set the JAVA_HOME variable in your environment to match the
50-
location of your Java installation."
2+
set -ex
3+
4+
ROOT_DIR=/root/chaincode-java
5+
LIB_DIR=${ROOT_DIR}/lib
6+
CHAINCODE_DIR=${ROOT_DIR}/chaincode
7+
LIB_JARS=$(find ${LIB_DIR} -name "*.jar" | paste -s -d ":" -)
8+
CHAINCODE_JARS=$(find ${CHAINCODE_DIR} -name "*.jar" | paste -s -d ":" -)
9+
NUM_CHAINCODE_JARS=$(find ${CHAINCODE_DIR} -name "*.jar" | wc -l)
10+
11+
if [ -f ${CHAINCODE_DIR}/.uberjar ]; then
12+
if [ ${NUM_CHAINCODE_JARS} -ne 1 ]; then
13+
>&2 echo "Cannot start uber JAR as more than one JAR file was found in the chaincode directory"
14+
exit 255
5115
fi
16+
exec java -jar ${CHAINCODE_JARS} "$@"
5217
else
53-
JAVACMD="java"
54-
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
55-
56-
Please set the JAVA_HOME variable in your environment to match the
57-
location of your Java installation."
58-
fi
59-
60-
# Escape application args
61-
save () {
62-
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
63-
echo " "
64-
}
65-
APP_ARGS=$(save "$@")
66-
67-
exec "$JAVACMD" -jar $APP_HOME/chaincode/chaincode.jar "$@"
68-
69-
18+
exec java -cp ${CHAINCODE_JARS}:${LIB_JARS} org.hyperledger.fabric.contract.ContractRouter "$@"
19+
fi
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
group 'org.hyperledger.fabric-chaincode-java'
6+
version '1.0-SNAPSHOT'
7+
8+
sourceCompatibility = 1.8
9+
10+
repositories {
11+
mavenLocal()
12+
mavenCentral()
13+
}
14+
15+
dependencies {
16+
compile project(':fabric-chaincode-shim')
17+
testCompile group: 'junit', name: 'junit', version: '4.12'
18+
}
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)