Commit 8e650612 by Benedikt Ritter Committed by GitHub

Merge pull request #7 from luiscoms/feature/buildargs

Add buildargs
parents d3b702a1 65b00fc9
...@@ -55,6 +55,16 @@ $ curl 127.0.0.1:8080 ...@@ -55,6 +55,16 @@ $ curl 127.0.0.1:8080
application GIT repository. In case your application is located in a application GIT repository. In case your application is located in a
sub-folder, you can set this variable to a *./myapplication*. 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 ## 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: 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:
......
...@@ -6,10 +6,11 @@ echo "---> Installing application source" ...@@ -6,10 +6,11 @@ echo "---> Installing application source"
cp -Rf /tmp/src/. ./ cp -Rf /tmp/src/. ./
echo "---> Building Spring Boot application from source" echo "---> Building Spring Boot application from source"
echo "--> # MVN_ARGS = $MVN_ARGS"
if [ -f "mvnw" ]; then if [ -f "mvnw" ]; then
./mvnw clean install ./mvnw clean install $MVN_ARGS
else else
mvn clean install mvn clean install $MVN_ARGS
fi fi
# Fix source directory permissions # Fix source directory permissions
......
...@@ -2,5 +2,9 @@ ...@@ -2,5 +2,9 @@
set -e set -e
APP_TARGET=${APP_TARGET:-target}
echo "---> Starting Spring Boot application" 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`
...@@ -12,15 +12,23 @@ if [ $# -eq 0 ]; then ...@@ -12,15 +12,23 @@ if [ $# -eq 0 ]; then
echo "ERROR: No test project name has been passed." echo "ERROR: No test project name has been passed."
exit 1 exit 1
fi 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_project=${1}
test_dir="$(readlink -zf $(dirname "${BASH_SOURCE[0]}"))" test_dir="$($READLINK_EXEC -zf $(dirname "${0}"))"
image_dir=$(readlink -zf ${test_dir}/..) image_dir=$($READLINK_EXEC -zf ${test_dir}/..)
scripts_url="file://${image_dir}/.sti/bin" scripts_url="file://${image_dir}/.s2i/bin"
cid_file=$(mktemp -u --suffix=.cid) 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 # it from Docker hub
s2i_args="--force-pull=false" s2i_args="--force-pull=false --loglevel=2"
# Read exposed port from image meta data # Read exposed port from image meta data
test_port="$(docker inspect --format='{{range $key, $value := .ContainerConfig.ExposedPorts }}{{$key}}{{end}}' ${IMAGE_NAME} | sed 's/\/.*//')" test_port="$(docker inspect --format='{{range $key, $value := .ContainerConfig.ExposedPorts }}{{$key}}{{end}}' ${IMAGE_NAME} | sed 's/\/.*//')"
...@@ -38,11 +46,23 @@ container_exists() { ...@@ -38,11 +46,23 @@ container_exists() {
} }
container_ip() { container_ip() {
if (echo "$OSTYPE" | egrep -qs 'darwin'); then
docker-machine ip
else
docker inspect --format="{{ .NetworkSettings.IPAddress }}" $(cat $cid_file) 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() { 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() { prepare() {
...@@ -58,6 +78,7 @@ prepare() { ...@@ -58,6 +78,7 @@ prepare() {
git config user.email "build@localhost" && git config user.name "builder" git config user.email "build@localhost" && git config user.name "builder"
git add -A && git commit -m "Sample commit" git add -A && git commit -m "Sample commit"
popd >/dev/null popd >/dev/null
run_s2i_build
} }
run_test_application() { run_test_application() {
...@@ -80,7 +101,7 @@ cleanup() { ...@@ -80,7 +101,7 @@ cleanup() {
check_result() { check_result() {
local result="$1" local result="$1"
if [[ "$result" != "0" ]]; then if [[ "$result" != "0" ]]; then
info "TEST FAILED for ${test_project} (${result})" info "TEST FAILED for ${test_project} (exit code: ${result})"
cleanup cleanup
exit $result exit $result
fi fi
...@@ -101,7 +122,7 @@ wait_for_cid() { ...@@ -101,7 +122,7 @@ wait_for_cid() {
test_s2i_usage() { test_s2i_usage() {
info "Testing the 'sti usage' command" 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() { test_docker_run_usage() {
...@@ -110,13 +131,19 @@ test_docker_run_usage() { ...@@ -110,13 +131,19 @@ test_docker_run_usage() {
} }
test_connection() { 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 max_attempts=10
local sleep_time=1 local sleep_time=1
local attempt=1 local attempt=1
local result=1 local result=1
while [ $attempt -le $max_attempts ]; do 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=$? status=$?
if [ $status -eq 0 ]; then if [ $status -eq 0 ]; then
if [ $response_code -eq 200 ]; then if [ $response_code -eq 200 ]; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment