Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
gdams committed Nov 1, 2023
1 parent 7473dbd commit 5d2360f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .test/tests/dotted-environment-variables/container.java
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);
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
variable.with.a.dot=value.foo
a.dotted.value
10 changes: 10 additions & 0 deletions .test/tests/dotted-environment-variables/image-name.sh
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')"
51 changes: 46 additions & 5 deletions .test/tests/dotted-environment-variables/run.sh
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

0 comments on commit 5d2360f

Please sign in to comment.