Skip to content

Commit d295c96

Browse files
[FAB-9424] Adding docker build support
Adding javaenv docker build to project Including building protos jar and shim jar Installing newly build jars and their dependencies to gradle cache and maven local. Added example gradle and maven project to check if it possible to build those projects using installed jars Change-Id: I28560ea4c481b7afa484b3909d4b1206da47112d Signed-off-by: gennady <gennady@il.ibm.com>
1 parent 1cb0493 commit d295c96

File tree

11 files changed

+709
-0
lines changed

11 files changed

+709
-0
lines changed

fabric-chaincode-docker/Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
FROM hyperledger/fabric-baseimage:amd64-0.4.10
2+
RUN apt-get update
3+
RUN apt-get install zip -y
4+
RUN curl -s "https://get.sdkman.io" | bash
5+
6+
SHELL ["/bin/bash", "-c"]
7+
8+
# Install gradle and maven
9+
RUN source /root/.sdkman/bin/sdkman-init.sh; sdk install gradle 4.6
10+
RUN source /root/.sdkman/bin/sdkman-init.sh; sdk install maven 3.5.0
11+
12+
# Coping libs, scripts and sources
13+
ADD build/distributions/ /root/
14+
15+
#Creating folders structure
16+
RUN mkdir -p /root/chaincode-java/chaincode/src
17+
RUN mkdir -p /root/chaincode-java/chaincode/build/out
18+
RUN mkdir -p /chaincode/input
19+
RUN mkdir -p /chaincode/output
20+
21+
#Making scripts runnable
22+
RUN chmod +x /root/chaincode-java/start
23+
RUN chmod +x /root/chaincode-java/build.sh
24+
25+
# Start build shim jars
26+
WORKDIR /root/chaincode-java/shim-src
27+
RUN source /root/.sdkman/bin/sdkman-init.sh; gradle clean
28+
29+
# Building protobuf jar and installing it to maven local and gradle cache
30+
WORKDIR /root/chaincode-java/shim-src/fabric-chaincode-protos
31+
RUN source /root/.sdkman/bin/sdkman-init.sh; gradle clean build install publishToMavenLocal
32+
# Installing all jar dependencies to maven local
33+
WORKDIR /root/chaincode-java/shim-src/fabric-chaincode-protos/build/publications/protosJar/
34+
RUN source /root/.sdkman/bin/sdkman-init.sh; mvn -f pom-default.xml compile
35+
36+
# Building shim jar and installing it to maven local and gradle cache
37+
WORKDIR /root/chaincode-java/shim-src/fabric-chaincode-shim
38+
RUN source /root/.sdkman/bin/sdkman-init.sh; gradle clean build install publishToMavenLocal
39+
# Installing all jar dependencies to maven local
40+
WORKDIR /root/chaincode-java/shim-src/fabric-chaincode-shim/build/publications/shimJar/
41+
RUN source /root/.sdkman/bin/sdkman-init.sh; mvn -f pom-default.xml compile
42+
43+
# Sanity check and maven/gradle plugin installs - compiling sample chaincode - gradle and maven
44+
WORKDIR /root/chaincode-java/example-src/fabric-chaincode-example-gradle
45+
RUN source /root/.sdkman/bin/sdkman-init.sh; gradle build shadowJar
46+
WORKDIR /root/chaincode-java/example-src/fabric-chaincode-example-maven
47+
RUN source /root/.sdkman/bin/sdkman-init.sh; mvn compile package
48+
WORKDIR /root/chaincode-java
49+
50+
#Removing non-needed sources
51+
RUN rm -rf example-src/*
52+
RUN rm -rf shim-src
53+
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright IBM Corp. 2018 All Rights Reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
buildscript {
8+
repositories {
9+
jcenter()
10+
mavenCentral()
11+
}
12+
dependencies {
13+
classpath 'com.bmuschko:gradle-docker-plugin:3.2.6'
14+
}
15+
}
16+
17+
apply plugin: 'com.bmuschko.docker-remote-api'
18+
19+
import com.bmuschko.gradle.docker.tasks.image.*
20+
21+
task copyShimSrc(type: Copy) {
22+
from project(':fabric-chaincode-shim').getProjectDir()
23+
into('build/distributions/chaincode-java/shim-src/fabric-chaincode-shim/')
24+
}
25+
26+
task copyProtosSrc(type: Copy) {
27+
from project(':fabric-chaincode-protos').getProjectDir()
28+
into('build/distributions/chaincode-java/shim-src/fabric-chaincode-protos/')
29+
}
30+
31+
task copyBuildFile(type: Copy) {
32+
from project.getParent().file("build.gradle")
33+
into('build/distributions/chaincode-java/shim-src/')
34+
}
35+
36+
task copySettingsFile(type: Copy) {
37+
from project.getParent().file("settings.gradle")
38+
into('build/distributions/chaincode-java/shim-src/')
39+
}
40+
41+
task copyGradleExampleProject(type: Copy) {
42+
from project.getParent().file("fabric-chaincode-example-gradle")
43+
into('build/distributions/chaincode-java/example-src/fabric-chaincode-example-gradle')
44+
}
45+
46+
task copyMavenExampleProject(type: Copy) {
47+
from project.getParent().file("fabric-chaincode-example-maven")
48+
into('build/distributions/chaincode-java/example-src/fabric-chaincode-example-maven')
49+
}
50+
51+
task copyLib (type: Copy) {
52+
dependsOn ':fabric-chaincode-shim:build'
53+
from project(':fabric-chaincode-shim').configurations.runtime
54+
into('build/distributions/chaincode-java/lib')
55+
}
56+
57+
task copyShimJar(type: Copy) {
58+
dependsOn copyLib
59+
from project(':fabric-chaincode-shim').jar
60+
into('build/distributions/chaincode-java/lib')
61+
}
62+
63+
task copyStartScript(type: Copy) {
64+
dependsOn copyShimJar
65+
from ('start')
66+
into ('build/distributions/chaincode-java')
67+
}
68+
69+
task copyBuildScript(type: Copy) {
70+
dependsOn copyStartScript
71+
from ('build.sh')
72+
into ('build/distributions/chaincode-java')
73+
}
74+
75+
task buildImage(type: DockerBuildImage) {
76+
dependsOn copyBuildScript
77+
dependsOn copyShimSrc
78+
dependsOn copyProtosSrc
79+
dependsOn copyBuildFile
80+
dependsOn copySettingsFile
81+
dependsOn copyGradleExampleProject
82+
dependsOn copyMavenExampleProject
83+
inputDir = project.file('Dockerfile').parentFile
84+
tags = ['hyperledger/fabric-javaenv', 'hyperledger/fabric-javaenv:x86_64-latest', 'hyperledger/fabric-javaenv:x86_64-1.2.0', 'hyperledger/fabric-javaenv:amd64-1.2.0', 'hyperledger/fabric-javaenv:amd64-latest']
85+
}
86+

fabric-chaincode-docker/build.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
buildGradle() {
4+
cd "$1" > /dev/null
5+
echo "Gradle build"
6+
ls -l
7+
gradle build shadowJar
8+
cp build/libs/chaincode.jar $2
9+
cd "$SAVED" >/dev/null
10+
}
11+
12+
buildMaven() {
13+
cd "$1" > /dev/null
14+
echo "Maven build"
15+
ls -l
16+
mvn compile package
17+
cp target/chaincode.jar $2
18+
cd "$SAVED" >/dev/null
19+
}
20+
21+
source /root/.sdkman/bin/sdkman-init.sh
22+
23+
# Attempt to set APP_HOME
24+
# Resolve links: $0 may be a link
25+
PRG="$0"
26+
# Need this for relative symlinks.
27+
while [ -h "$PRG" ] ; do
28+
ls=`ls -ld "$PRG"`
29+
link=`expr "$ls" : '.*-> \(.*\)$'`
30+
if expr "$link" : '/.*' > /dev/null; then
31+
PRG="$link"
32+
else
33+
PRG=`dirname "$PRG"`"/$link"
34+
fi
35+
done
36+
SAVED="`pwd`"
37+
cd "`dirname \"$PRG\"`" >/dev/null
38+
APP_HOME="`pwd -P`"
39+
cd "$SAVED" >/dev/null
40+
41+
APP_NAME="build.sh"
42+
APP_BASE_NAME=`basename "$0"`
43+
44+
find /chaincode/input/
45+
46+
set -x
47+
48+
if [ -d "/chaincode/output" ]
49+
then
50+
rm -rf /chaincode/output/*
51+
else
52+
mkdir -p /chaincode/output/
53+
fi
54+
55+
if [ -d "${APP_HOME}/chaincode/build/out" ]
56+
then
57+
rm -rf ${APP_HOME}/chaincode/build/out/*
58+
else
59+
mkdir -p ${APP_HOME}/chaincode/build/out
60+
fi
61+
62+
63+
if [ -f "/chaincode/input/src/build.gradle" ]
64+
then
65+
buildGradle /chaincode/input/src/ /chaincode/output/
66+
else
67+
buildMaven /chaincode/input/src/ /chaincode/output/
68+
fi
69+
70+
set +x

fabric-chaincode-docker/start

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/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."
51+
fi
52+
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+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
plugins {
2+
id 'com.github.johnrengelman.shadow' version '2.0.3'
3+
id 'java'
4+
}
5+
6+
group 'org.hyperledger.fabric'
7+
version '1.0-SNAPSHOT'
8+
9+
sourceCompatibility = 1.8
10+
11+
repositories {
12+
mavenLocal()
13+
mavenCentral()
14+
}
15+
16+
dependencies {
17+
compile group: 'org.hyperledger.fabric', name: 'fabric-chaincode-shim', version: '1.2.0-SNAPSHOT'
18+
testCompile group: 'junit', name: 'junit', version: '4.12'
19+
}
20+
21+
shadowJar {
22+
baseName = 'chaincode'
23+
version = null
24+
classifier = null
25+
26+
manifest {
27+
attributes 'Main-Class': 'org.hyperledger.fabric.example.SimpleChaincode'
28+
}
29+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'fabric-chaincode-example-gradle'
2+

0 commit comments

Comments
 (0)