diff --git a/incubating/wrappers/s2i/java/Dockerfile.build b/incubating/wrappers/s2i/java/Dockerfile.build index 8fc95d3e1d..95da695fce 100644 --- a/incubating/wrappers/s2i/java/Dockerfile.build +++ b/incubating/wrappers/s2i/java/Dockerfile.build @@ -1,4 +1,5 @@ -FROM seldonio/core-builder:0.3 +ARG IMAGE_SOURCE=seldonio/core-builder:0.3 +FROM $IMAGE_SOURCE LABEL io.openshift.s2i.scripts-url="image:///s2i/bin" diff --git a/incubating/wrappers/s2i/java/Dockerfile.runtime b/incubating/wrappers/s2i/java/Dockerfile.runtime index d58e6236ad..e4f8d41b52 100644 --- a/incubating/wrappers/s2i/java/Dockerfile.runtime +++ b/incubating/wrappers/s2i/java/Dockerfile.runtime @@ -1,4 +1,5 @@ -FROM openjdk:8u131-jre-alpine +ARG IMAGE_SOURCE=openjdk:8u131-jre-alpine +FROM $IMAGE_SOURCE RUN apk update && apk add bash diff --git a/incubating/wrappers/s2i/java/bin/build.sh b/incubating/wrappers/s2i/java/bin/build.sh new file mode 100755 index 0000000000..760e3a83b5 --- /dev/null +++ b/incubating/wrappers/s2i/java/bin/build.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash +set -x + +# +# Print the usage and exit. +# +function usage () { + echo "Usage: $0 [OPTIONS] VERSION" + echo "\r\n" + echo "Options: " + echo " --build-source-image (OPTIONAL) override the build image source image" + echo " --build-runtime-image (OPTIONAL) override the runtime image source image" + exit 1 +} + +# Parse the arguments. +# loop until last - 1, we assume the last arg is the model name +while [[ $# -ge 2 ]] +do + key="$1" + case ${key} in + --build-source-image) + BUILD_SOURCE_IMAGE="$2" + shift # past key + shift # past value + ;; + --runtime-source-image) + RUNTIME_SOURCE_IMAGE="$2" + shift # past key + shift # past value + ;; + *) + usage + ;; +esac +done + +# assign last parameter to model +VERSION=${@:${#@}} +IMAGE_BUILD_BUILD_ARGS="" +IMAGE_RUNTIME_BUILD_ARGS="" + +# Validate the arguments. +if [[ -z "$VERSION" ]]; then + echo "Missing argument: VERSION." + usage +fi + +# Prepare Docker build args ( if supplied ) +if ! [[ -z "$BUILD_SOURCE_IMAGE" ]]; then + IMAGE_BUILD_BUILD_ARGS=$(echo "$IMAGE_BUILD_BUILD_ARGS --build-arg IMAGE_SOURCE=$BUILD_SOURCE_IMAGE" | awk '{$1=$1};1') +fi +if ! [[ -z "$RUNTIME_SOURCE_IMAGE" ]]; then + IMAGE_RUNTIME_BUILD_ARGS=$(echo "$IMAGE_RUNTIME_BUILD_ARGS --build-arg IMAGE_SOURCE=$RUNTIME_SOURCE_IMAGE" | awk '{$1=$1};1') +fi + +IMAGE_NAME_BUILD=docker.io/seldonio/seldon-core-s2i-java-build:${VERSION} +IMAGE_NAME_RUNTIME=docker.io/seldonio/seldon-core-s2i-java-runtime:${VERSION} + +echo "S2I build image: building..." +docker build \ + -f Dockerfile.build \ + -t ${IMAGE_NAME_BUILD} \ + ${IMAGE_BUILD_BUILD_ARGS} \ + . +echo "S2I build image: check Java version..." +docker run --entrypoint "/bin/bash" ${IMAGE_NAME_BUILD} "-c" "java --version" + +echo "S2I runtime image: building..." +docker build \ + -f Dockerfile.runtime \ + -t ${IMAGE_NAME_RUNTIME} \ + ${IMAGE_RUNTIME_BUILD_ARGS} \ + . +echo "S2I runtime image: check Java version..." +docker run --entrypoint "/bin/bash" ${IMAGE_NAME_RUNTIME} "-c" "java --version"