-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
variable.with.a.dot=value.foo | ||
a.dotted.value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# usage: ./image-name.sh librarytest/something some/image:some-tag | ||
# output: librarytest/something:some-image-some-tag | ||
|
||
base="$1"; shift | ||
tag="$1"; shift | ||
|
||
echo "$base:$(echo "$tag" | sed 's![:/]!-!g')" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" <<EOD | ||
FROM $jdk AS jdk | ||
WORKDIR /container | ||
COPY dir/container.java ./ | ||
RUN $javac ./container.java | ||
FROM $image | ||
COPY --from=jdk /container /container | ||
WORKDIR /container | ||
EOD | ||
|
||
docker run --rm -e "variable.with.a.dot=a.dotted.value" "$newImage" java -cp . container |