Skip to content

Commit

Permalink
Merge pull request #367 from derms/dev
Browse files Browse the repository at this point in the history
added examples for ml-gradle and docker-compose
  • Loading branch information
rjrudin authored Aug 28, 2018
2 parents 9f00f1a + f7b794a commit 088416a
Show file tree
Hide file tree
Showing 39 changed files with 2,154 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/docker-projects/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Overview
---------

Sample projects using docker-compose with a custom Dockerfile for MarkLogic.

Easiest way to get started using these examples is to clone the ml-gradle repository and copy your desired project to your workspace directory

Unless otherwise specified, the target platform for the docker images is linux. Note that on mac's you can use linux images on the docker native macOS virtualization. However with windows, you need to run a linux vm.
21 changes: 21 additions & 0 deletions examples/docker-projects/single-node-with-nifi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# Created by https://www.gitignore.io/api/gradle

### Gradle ###
.gradle
/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties


# End of https://www.gitignore.io/api/gradle
65 changes: 65 additions & 0 deletions examples/docker-projects/single-node-with-nifi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Overview
---------

NOTE: WIP

Project will create (in docker)

* A single MarkLogic node
* A nifi instance with the MarkLogic nar files
* A local directory (./logs) that will contain the logs of the MarkLogic container and nifi image
* A data mount (/data) in the nifi container that corresponds to the local project directory (./data)
* This is useful when you want to read files from a processor in nifi

Admin account is
* Username: admin
* Password: admin

Prerequisites
-------------

1. docker toolkit installed
2. Java 8 installed
3. Following ports available -
* 8000-8050
* 8080
* 8443
* 10000

Installation steps (once off)
-----------------------------

1. Download MarkLogic-9.0-5.x86_64.rpm (or any other MarkLogic v9 rpm) and copy it to src/main/docker/marklogic
2. Execute (this will download all required docker dependencies to build marklogic image)
```
docker-compose build
```
3. Execute (this will download all required gradle dependencies)
```
./gradlew build
```
___

Docker Setup (including mlDeploy)
-------------
1. ./gradlew mlDockerDeploy

Docker Start
-------------
1. ./gradlew mlDockerStart

Docker Stop
-------------
1. ./gradlew mlDockerStop

Docker TearDown
-------------
1. ./gradlew mlDockerTeardown


___


Customisations
-------------
If you want to include the MarkLogic Converters rpm in the image, you can. You just need to modify the MarkLogic Dockerfile as specified in the comments of the Dockerfile itself
33 changes: 33 additions & 0 deletions examples/docker-projects/single-node-with-nifi/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
// gradle -PenvironmentName=x ...
id 'net.saliman.properties' version '1.4.6'
id "com.marklogic.ml-gradle" version "3.8.2"
id 'com.avast.gradle.docker-compose' version "0.6.11"
}
dockerCompose {
waitForTcpPorts = false
}

task mlDockerSetupNode(dependsOn:composeUp) {
doLast {
sleep(5 * 1000) //ensure node is up
exec {
commandLine 'docker', 'exec', 'node1.single', 'init-marklogic'
}
}
}

mlDeploy.shouldRunAfter mlDockerSetupNode

task mlDockerDeploy(dependsOn:[mlDockerSetupNode,mlDeploy])

task mlDockerStart(dependsOn:composeUp)

task mlDockerStop(type:Exec) {
commandLine "docker-compose", "stop"
}

task mlDockerTeardown(dependsOn:composeDown) {
//remove logs directory
delete 'logs'
}
33 changes: 33 additions & 0 deletions examples/docker-projects/single-node-with-nifi/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3'
services:
node1:
build: "./src/main/docker/marklogic"
image: "marklogic:latest"
ports:
# choose what ports you want to expose (at least 8000 8001 8002)
- "8000-8050:8000-8050"
hostname: "node1.single"
container_name: "node1.single"
volumes:
- ./logs/node1:/var/opt/MarkLogic/Logs

nifi:
build: "./src/main/docker/nifi"
image: "marklogic-nifi:latest"
ports:
- "8080:8080"
- "8443:8443"
- "10000:10000"
hostname: "nifi.single"
container_name: "nifi.single"
volumes:
- ./data:/data
- ./logs/nifi:/opt/nifi/nifi-1.7.0/logs

# optionally specify the subnet
networks:
default:
driver: bridge
ipam:
config:
- subnet: 172.66.0.0/16
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mlAppName=sample-single-node-app

mlRestPort=8003
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
172 changes: 172 additions & 0 deletions examples/docker-projects/single-node-with-nifi/gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn () {
echo "$*"
}

die () {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
Loading

0 comments on commit 088416a

Please sign in to comment.