diff --git a/README.md b/README.md index b61da3ac1f0aaa9ace964c90dd76fc162bee29f1..441c55f63050c9d33dc6920f0bc5f2e1e1e1b019 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,16 @@ $ curl 127.0.0.1:8080 application GIT repository. In case your application is located in a sub-folder, you can set this variable to a *./myapplication*. +* **APP_TARGET** (default: '') + + This variable specifies a relative location to your application binary inside the + container. + +* **MVN_ARGS** (default: '') + + This variable specifies the arguments for Maven inside the container. + + ## Contributing In order to test your changes to this STI image or to the STI scripts, you can use the `test/run` script. Before that, you have to build the 'candidate' image: diff --git a/s2i/bin/assemble b/s2i/bin/assemble index ec5642335fdcf4ff521b3c72e789fcc73da1a71a..8021fb50ca6fa37026baa405bce87f950583e7b0 100755 --- a/s2i/bin/assemble +++ b/s2i/bin/assemble @@ -6,10 +6,11 @@ echo "---> Installing application source" cp -Rf /tmp/src/. ./ echo "---> Building Spring Boot application from source" +echo "--> # MVN_ARGS = $MVN_ARGS" if [ -f "mvnw" ]; then - ./mvnw clean install + ./mvnw clean install $MVN_ARGS else - mvn clean install + mvn clean install $MVN_ARGS fi # Fix source directory permissions diff --git a/s2i/bin/run b/s2i/bin/run index a01a76a7776c0534f4a4db594c5576e774d77446..ab05eb0dddd90ae81fcbb62000ec35fd42f1835c 100755 --- a/s2i/bin/run +++ b/s2i/bin/run @@ -2,5 +2,9 @@ set -e +APP_TARGET=${APP_TARGET:-target} echo "---> Starting Spring Boot application" -java -jar `find target -name *.jar` +echo "--> # APP_TARGET = $APP_TARGET" +echo "--> # JAVA_OPTS = $JAVA_OPTS" +echo "---> Running application from jar ($(find $APP_TARGET -name *.jar)) ..." +java $JAVA_OPTS -jar `find $APP_TARGET -name *.jar` diff --git a/test/run b/test/run index b895f60c7e5dfd95dcb1f49fe3e8a653164fb4cf..e482e55043cd52f07e3964ec6f330e33ea2831e5 100755 --- a/test/run +++ b/test/run @@ -12,15 +12,23 @@ if [ $# -eq 0 ]; then echo "ERROR: No test project name has been passed." exit 1 fi + +# Determining system utility executables (darwin compatibility check) +READLINK_EXEC="readlink" +MKTEMP_EXEC="mktemp" +if (echo "$OSTYPE" | egrep -qs 'darwin'); then + ! type -a "greadlink" &>"/dev/null" || READLINK_EXEC="greadlink" + ! type -a "gmktemp" &>"/dev/null" || MKTEMP_EXEC="gmktemp" +fi test_project=${1} -test_dir="$(readlink -zf $(dirname "${BASH_SOURCE[0]}"))" -image_dir=$(readlink -zf ${test_dir}/..) -scripts_url="file://${image_dir}/.sti/bin" -cid_file=$(mktemp -u --suffix=.cid) +test_dir="$($READLINK_EXEC -zf $(dirname "${0}"))" +image_dir=$($READLINK_EXEC -zf ${test_dir}/..) +scripts_url="file://${image_dir}/.s2i/bin" +cid_file=$($MKTEMP_EXEC -u --suffix=.cid) -# Since we built the candidate image locally, we don't want S2I attempt to pull +# Since we built the candidate image locally, we don't want S2I to attempt to pull # it from Docker hub -s2i_args="--force-pull=false" +s2i_args="--force-pull=false --loglevel=2" # Read exposed port from image meta data test_port="$(docker inspect --format='{{range $key, $value := .ContainerConfig.ExposedPorts }}{{$key}}{{end}}' ${IMAGE_NAME} | sed 's/\/.*//')" @@ -38,11 +46,23 @@ container_exists() { } container_ip() { - docker inspect --format="{{ .NetworkSettings.IPAddress }}" $(cat $cid_file) + if (echo "$OSTYPE" | egrep -qs 'darwin'); then + docker-machine ip + else + docker inspect --format="{{ .NetworkSettings.IPAddress }}" $(cat $cid_file) + fi +} + +container_port() { + if (echo "$OSTYPE" | egrep -qs 'darwin'); then + docker inspect --format='{{(index (index .NetworkSettings.Ports "8080/tcp") 0).HostPort}}' $(cat $cid_file) + else + echo $test_port + fi } run_s2i_build() { - s2i build ${sti_args} file://${test_dir}/${test_project} ${IMAGE_NAME} ${IMAGE_NAME}-${test_project} + s2i build --incremental=true ${s2i_args} file://${test_dir}/${test_project} ${IMAGE_NAME} ${IMAGE_NAME}-${test_project} } prepare() { @@ -58,6 +78,7 @@ prepare() { git config user.email "build@localhost" && git config user.name "builder" git add -A && git commit -m "Sample commit" popd >/dev/null + run_s2i_build } run_test_application() { @@ -80,7 +101,7 @@ cleanup() { check_result() { local result="$1" if [[ "$result" != "0" ]]; then - info "TEST FAILED for ${test_project} (${result})" + info "TEST FAILED for ${test_project} (exit code: ${result})" cleanup exit $result fi @@ -101,7 +122,7 @@ wait_for_cid() { test_s2i_usage() { info "Testing the 'sti usage' command" - s2i usage ${sti_args} ${IMAGE_NAME} &>/dev/null + s2i usage ${s2i_args} ${IMAGE_NAME} &>/dev/null } test_docker_run_usage() { @@ -110,13 +131,19 @@ test_docker_run_usage() { } test_connection() { - info "Testing the HTTP connection (http://$(container_ip):${test_port})" + info "Testing the HTTP connection (http://$(container_ip):$(container_port))" local max_attempts=10 local sleep_time=1 local attempt=1 local result=1 while [ $attempt -le $max_attempts ]; do - response_code=$(curl -s -w %{http_code} -o /dev/null http://$(container_ip):${test_port}/) + info "Sending GET request to http://$(container_ip):$(container_port)/" + if (echo "$OSTYPE" | egrep -qs 'darwin'); then + echo "Warning for OSX users: if you can't access the container's IP ${container_ip} directly (because you use boot2docker for example)" + echo "you should run the curl command in a container, for example using:" + echo "docker run --rm -it sequenceiq/alpine-curl curl -s -w %{http_code} -o /dev/null http://$(container_ip):$(container_port)/" + fi + response_code=$(curl -s -w %{http_code} -o /dev/null http://$(container_ip):$(container_port)/) status=$? if [ $status -eq 0 ]; then if [ $response_code -eq 200 ]; then