Skip to content

Commit

Permalink
Add a Dockerfile
Browse files Browse the repository at this point in the history
see #140
  • Loading branch information
bertfrees committed Nov 27, 2017
2 parents e3304a0 + c946f36 commit 326176e
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 202 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
@@ -0,0 +1,7 @@
.git
.gitignore

.dockerignore
Dockerfile

target
22 changes: 22 additions & 0 deletions Dockerfile
@@ -0,0 +1,22 @@
# Use a multistage build to first build the pipeline using maven. Then
# copy the artifacts into a final image which exposes the port and
# starts the pipeline.

# Build the pipeline first
FROM maven:3.5-jdk-8 as builder
ADD . /usr/src/daisy-pipeline2
WORKDIR /usr/src/daisy-pipeline2
RUN mvn clean package

# then use the build artifacts to create an image where the pipeline is installed
FROM openjdk:8-jre
LABEL maintainer="DAISY Consortium (http://www.daisy.org/)"
COPY --from=builder /usr/src/daisy-pipeline2/target/pipeline2-*_linux/daisy-pipeline /opt/daisy-pipeline2
ENV PIPELINE2_LOCAL=false \
PIPELINE2_AUTH=true \
PIPELINE2_WS_AUTHENTICATION_KEY=clientid \
PIPELINE2_WS_AUTHENTICATION_SECRET=sekret
EXPOSE 8181
# for the healthcheck use PIPELINE2_HOST if defined. Otherwise use localhost
HEALTHCHECK --interval=30s --timeout=10s --start-period=1m CMD curl --fail http://${PIPELINE2_WS_HOST-localhost}:${PIPELINE2_WS_PORT:-8181}/${PIPELINE2_WS_PATH:-ws}/alive || exit 1
ENTRYPOINT ["/opt/daisy-pipeline2/bin/pipeline2"]
9 changes: 9 additions & 0 deletions Dockerfile.without_builder
@@ -0,0 +1,9 @@
FROM openjdk:8-jre
LABEL maintainer="DAISY Consortium (http://www.daisy.org/)"
ADD target/pipeline2-*_linux/daisy-pipeline /opt/daisy-pipeline2
ENV PIPELINE2_LOCAL=false \
PIPELINE2_AUTH=true \
PIPELINE2_WS_AUTHENTICATION_KEY=clientid \
PIPELINE2_WS_AUTHENTICATION_SECRET=sekret
EXPOSE 8181
ENTRYPOINT ["/opt/daisy-pipeline2/bin/pipeline2"]
15 changes: 15 additions & 0 deletions Makefile
@@ -0,0 +1,15 @@
help :
echo "make docker:" >&2
echo " Build a Docker image" >&2
echo "make check-docker:" >&2
echo " Test the Docker image" >&2

docker :
gtar -cz \
target/pipeline2-*_linux \
Dockerfile.without_builder \
--transform='s/Dockerfile.without_builder/Dockerfile/' \
| docker build -t daisyorg/pipeline2 -

check-docker :
bash src/test/resources/test-docker-image.sh
98 changes: 1 addition & 97 deletions pom.xml
Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>org.daisy.pipeline</groupId>
<artifactId>framework-bom</artifactId>
<version>1.10.4</version>
<version>1.10.5-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -2821,102 +2821,6 @@ rm -rf /opt/daisy-pipeline2/cli
</build>
</profile>

<profile>
<id>webui</id>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.daisy.pipeline</groupId>
<artifactId>webui-desktop</artifactId>
<version>1.8.1</version>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>target/webui</outputDirectory>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>dist-webui-mac</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>false</attach>
<descriptors>
<descriptor>src/main/assembly/webui-mac.xml</descriptor>
</descriptors>
<filters>
<filter>src/main/assembly/dist.properties</filter>
<filter>src/main/assembly/dist-nix.properties</filter>
</filters>
<appendAssemblyId>false</appendAssemblyId>
<finalName>pipeline2-${project.version}-webui_mac</finalName>
</configuration>
</execution>
<execution>
<id>dist-webui-linux</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>false</attach>
<descriptors>
<descriptor>src/main/assembly/webui-linux.xml</descriptor>
</descriptors>
<filters>
<filter>src/main/assembly/dist.properties</filter>
<filter>src/main/assembly/dist-nix.properties</filter>
</filters>
<appendAssemblyId>false</appendAssemblyId>
<finalName>pipeline2-${project.version}-webui_linux</finalName>
</configuration>
</execution>
<execution>
<id>dist-webui-win</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>false</attach>
<descriptors>
<descriptor>src/main/assembly/webui-win.xml</descriptor>
</descriptors>
<filters>
<filter>src/main/assembly/dist.properties</filter>
<filter>src/main/assembly/dist-win.properties</filter>
</filters>
<appendAssemblyId>false</appendAssemblyId>
<finalName>pipeline2-${project.version}-webui_windows</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

</profiles>
<repositories>
<!--
Expand Down
31 changes: 0 additions & 31 deletions src/main/assembly/components/webui.xml

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/assembly/webui-linux.xml

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/assembly/webui-mac.xml

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/assembly/webui-win.xml

This file was deleted.

5 changes: 3 additions & 2 deletions src/main/deb/etc/default/daisy-pipeline2
@@ -1,7 +1,8 @@
# Configuration file for /etc/init.d/daisy-pipeline2

# Execute pipeline in remote mode
#REMOTE=true
# Execute pipeline in remote mode and with authentication
#export PIPELINE2_WS_LOCALFS=true
#export PIPELINE2_WS_AUTHENTICATION=false

# Java heap size
#export JAVA_MIN_MEM=256M
Expand Down
5 changes: 0 additions & 5 deletions src/main/deb/etc/init.d/daisy-pipeline2
Expand Up @@ -27,11 +27,6 @@ SCRIPTNAME=/etc/init.d/$NAME
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Set daemon argument list
if [ "$REMOTE" = "true" ]; then
DAEMON_ARGS="remote"
fi

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

Expand Down
33 changes: 14 additions & 19 deletions src/main/resources/bin/pipeline2
Expand Up @@ -354,24 +354,11 @@ init() {
}

run() {
if [ "x$PIPELINE2_AUTH" = "x" ]; then
PIPELINE2_AUTH="-Dorg.daisy.pipeline.ws.authentication=false"
export PIPELINE2_AUTH
else
PIPELINE2_AUTH="-Dorg.daisy.pipeline.ws.authentication=$PIPELINE2_AUTH"
export PIPELINE2_AUTH

fi
if [ "x$PIPELINE2_LOCAL" = "x" ]; then
PIPELINE2_LOCAL="-Dorg.daisy.pipeline.ws.localfs=true"
export PIPELINE2_LOCAL
else
PIPELINE2_LOCAL="-Dorg.daisy.pipeline.ws.localfs=$PIPELINE2_LOCAL"
export PIPELINE2_LOCAL
# set defaults
PIPELINE2_WS_LOCALFS=true
PIPELINE2_WS_AUTHENTICATION=false

fi
MAIN=org.apache.felix.main.Main
OPTS="$PIPELINE2_LOCAL $PIPELINE2_AUTH"
MODE=" -Dorg.daisy.pipeline.main.mode=webservice"

case "$1" in
Expand All @@ -383,11 +370,13 @@ run() {
# shift
# ;;
'remote')
OPTS="-Dorg.daisy.pipeline.ws.localfs=false -Dorg.daisy.pipeline.ws.authentication=true"
PIPELINE2_LOCALFS=false
PIPELINE2_AUTH=true
shift
;;
'local')
OPTS="-Dorg.daisy.pipeline.ws.localfs=true -Dorg.daisy.pipeline.ws.authentication=false"
PIPELINE2_LOCALFS=true
PIPELINE2_AUTH=false
shift
;;
'clean')
Expand Down Expand Up @@ -437,7 +426,13 @@ run() {
fi
cd "$PIPELINE2_BASE"
eval exec "\"$JAVA"\" "$JAVA_OPTS" -Djava.endorsed.dirs="\"${JAVA_ENDORSED_DIRS}"\" -Djava.ext.dirs="\"${JAVA_EXT_DIRS}"\" -Dorg.daisy.pipeline.home="\"$PIPELINE2_HOME"\" -Dorg.daisy.pipeline.base="\"$PIPELINE2_BASE"\" -Dorg.daisy.pipeline.data="\"$PIPELINE2_DATA"\" -Dfelix.config.properties="\"file:$PIPELINE2_HOME/etc/config.properties"\" -Dfelix.system.properties="\"file:$PIPELINE2_CONFIG/system.properties"\" $FELIX_OPTS $PIPELINE2_OPTS $OPTS $MODE -classpath "\"$CLASSPATH"\" $MAIN "\"$@"\"
export PIPELINE2_HOME
export PIPELINE2_BASE
export PIPELINE2_DATA
export PIPELINE2_WS_LOCALFS
export PIPELINE2_WS_AUTHENTICATION
eval exec "\"$JAVA"\" "$JAVA_OPTS" -Djava.endorsed.dirs="\"${JAVA_ENDORSED_DIRS}"\" -Djava.ext.dirs="\"${JAVA_EXT_DIRS}"\" -Dfelix.config.properties="\"file:$PIPELINE2_HOME/etc/config.properties"\" -Dfelix.system.properties="\"file:$PIPELINE2_CONFIG/system.properties"\" $FELIX_OPTS $MODE -classpath "\"$CLASSPATH"\" $MAIN "\"$@"\"
}
main() {
Expand Down
60 changes: 60 additions & 0 deletions src/test/resources/test-docker-image.sh
@@ -0,0 +1,60 @@
#!/usr/bin/env bash

# This test starts the pipeline inside a Docker container and then
# starts the dtbook-to-epub3 script using the cli inside a second
# container

set -e
cd $(dirname "$0")

# download test DTBook from https://github.com/daisy/pipeline-samples
DATA_DIR=../../../target/test-docker/data
mkdir -p $DATA_DIR
cd $DATA_DIR
DTBOOK=hauy_valid.xml
DATA=$(basename $DTBOOK).zip
rm -f $DATA
for f in \
$DTBOOK \
dtbook.2005.basic.css \
valentin.jpg
do
curl https://raw.githubusercontent.com/daisy/pipeline-samples/10bbb8e/dtbook/$f 2>/dev/null >$f
zip $DATA $f
done

CLIENTKEY=clientid
CLIENTSECRET=sekret
MOUNT_POINT=/mnt

# run the pipeline
docker run --name pipeline --detach \
-e PIPELINE2_WS_HOST=0.0.0.0 \
-e PIPELINE2_AUTH=true \
-e PIPELINE2_WS_AUTHENTICATION_KEY=$CLIENTKEY \
-e PIPELINE2_WS_AUTHENTICATION_SECRET=$CLIENTSECRET \
-p 8181:8181 daisyorg/pipeline2

# wait for the pipeline to start
sleep 5
while ! curl localhost:8181/ws/alive >/dev/null 2>/dev/null; do
echo "Waiting for web service to be up..." >&2
sleep 2
done

# run the cli
docker run --name cli --rm -it --link pipeline \
--entrypoint /opt/daisy-pipeline2/cli/dp2 \
--volume="$(pwd):$MOUNT_POINT:rw" \
daisyorg/pipeline2 \
--host http://pipeline \
--starting false \
--client_key $CLIENTKEY \
--client_secret $CLIENTSECRET \
dtbook-to-epub3 --source $DTBOOK --output $MOUNT_POINT --data $MOUNT_POINT/$DATA --persistent
# help dtbook-to-epub3
# dtbook-validator --input-dtbook $DTBOOK --output $MOUNT_POINT --data $MOUNT_POINT/$DATA

docker stop pipeline
docker rm pipeline

0 comments on commit 326176e

Please sign in to comment.