diff --git a/.test/tests/dotted-environment-variables/container.java b/.test/tests/dotted-environment-variables/container.java new file mode 100644 index 000000000..2a131b731 --- /dev/null +++ b/.test/tests/dotted-environment-variables/container.java @@ -0,0 +1,11 @@ +public class container { + /** + * Check if dotted env vars are supported. + */ + public static void main(String[] args) { + // get value of variable.with.a.dot and print it out + String value = System.getenv("variable.with.a.dot"); + System.out.println(value); + System.exit(0); + } +} \ No newline at end of file diff --git a/.test/tests/dotted-environment-variables/expected-std-out.txt b/.test/tests/dotted-environment-variables/expected-std-out.txt index 8dc3bdb62..f0a7151bb 100644 --- a/.test/tests/dotted-environment-variables/expected-std-out.txt +++ b/.test/tests/dotted-environment-variables/expected-std-out.txt @@ -1 +1 @@ -variable.with.a.dot=value.foo +a.dotted.value diff --git a/.test/tests/dotted-environment-variables/run.sh b/.test/tests/dotted-environment-variables/run.sh index d7478c36d..268a44e4f 100755 --- a/.test/tests/dotted-environment-variables/run.sh +++ b/.test/tests/dotted-environment-variables/run.sh @@ -1,8 +1,49 @@ -#!/bin/bash +#!/usr/bin/env bash -set -o pipefail +## Copied from https://github.com/docker-library/official-images/blob/master/test/tests/run-java-in-container.sh -CMD1=(env | grep variable.with.a.dot ) +set -Eeuo pipefail -# Test run 1: Expect dotted environment variables to be set correctly -docker run --rm -e "variable.with.a.dot=value.foo" "$1" $CMD1 +testDir="$(readlink -f "$(dirname "$BASH_SOURCE")")" +runDir="$(dirname "$(readlink -f "$BASH_SOURCE")")" + +image="$1" + +# do a little extra work to try and find a suitable JDK image (when "xyzjava:1.2.3-jre" first builds, "xyzjava:1.2.3-jdk" isn't published yet :D) +tryJdks=( + # ideally, we'd just swap the current JRE image to JDK, but that might not exist yet (see above) + "${image/jre/jdk}" +) +jdk= +for potentialJdk in "${tryJdks[@]}"; do + if docker run --rm --pull=missing "$potentialJdk" javac -help &> /dev/null; then + jdk="$potentialJdk" + break + fi +done +if [ -z "$jdk" ]; then + echo >&2 "error: failed to find a suitable JDK image for '$image'!" + exit 1 +fi +if [ "$jdk" != "${tryJdks[0]}" ]; then + echo >&2 "warning: using '$jdk' instead of '${tryJdks[0]}' (results may vary!)" +fi + +# if possible, use "--release" in case $jdk and $image have mismatching Java versions +javac='javac' +if docker run --rm "$jdk" javac --help 2>&1 | grep -q -- '--release'; then + javac='javac --release 8' +fi + +newImage="$("$runDir/image-name.sh" librarytest/java-hello-world "$image")" +"$runDir/docker-build.sh" "$testDir" "$newImage" <