Skip to content

Commit 365a98d

Browse files
authored
Ability to run JAVA_HOME binaries inside test (#24)
* java home binaries * update * update * update * update * update * ls * update * update * update
1 parent 961a0fe commit 365a98d

File tree

9 files changed

+34
-15
lines changed

9 files changed

+34
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
bazel-*
2+
.ijwb

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ junit_docker_compose_test(
9494
test_srcs = glob(["**/*Test.java"]),
9595
test_deps = ["@maven//:org_junit_jupiter_junit_jupiter_api"],
9696
classpath_jars = ["@maven//:org_junit_platform_junit_platform_console_standalone"],
97-
test_image_base = "@distroless_java",
97+
test_image_base = "@openjdk",
9898
)
9999
```
100100

docker_compose_test/test_container_entrypoint.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
echo "[DEBUG] JAVA_HOME before discovery logic: $JAVA_HOME"
17+
1618
# if JAVA_HOME is not set, just default to /usr (works if /usr/bin/java exists)
1719
if [[ -z "$JAVA_HOME" ]]; then
18-
JAVA_HOME="/usr"
20+
export JAVA_HOME="/usr"
1921
# this is used if JAVA_HOME contains an * (if version changes regularly this can be useful)
20-
elif [[ "$JAVA_HOME" == *"\*"* ]]; then
21-
JAVA_HOME=$(find $JAVA_HOME -maxdepth 1 | head -n 1)
22+
elif echo "$JAVA_HOME" | grep '*' > /dev/null; then
23+
export JAVA_HOME=$(find $JAVA_HOME -maxdepth 1 | head -n 1)
2224
fi
2325

26+
echo "[DEBUG] JAVA_HOME after discovery logic: $JAVA_HOME"
27+
export PATH=$JAVA_HOME/bin:$PATH
28+
echo "[DEBUG] PATH: $PATH"
29+
2430
TEST_UBER_JAR=$(find ./ -maxdepth 1 -name '*_uber_jar_deploy.jar')
2531
JUNIT_PLATFORM_CONSOLE_STANDALONE_JAR=$(find ./ -maxdepth 1 -name '*junit-platform-console-standalone*.jar')
2632

examples/.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
common --test_output=errors
2+
common --verbose_explanations

examples/WORKSPACE

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ oci_register_toolchains(
5050
load("@rules_oci//oci:pull.bzl", "oci_pull")
5151

5252
oci_pull(
53-
name = "distroless_java",
54-
# tag = "debug", # debug distroless image can be debugged with --entrypoint "/busybox/sh"
55-
digest = "sha256:73c3687a9d7277f480a560ae380ba16acbe8eb5a0f459560b4466bb71e6288a1",
56-
image = "gcr.io/distroless/java17",
53+
name = "openjdk",
54+
digest = "sha256:29c44ad7bb159a29a4458b74e8d37c1995cb8dc32abdd35e6d3e3d493e682d10",
55+
image = "openjdk",
56+
platforms = [
57+
"linux/amd64",
58+
"linux/arm64/v8",
59+
],
5760
)
5861

5962
oci_pull(

examples/junit-image-test/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ junit_docker_compose_test(
2222
test_srcs = glob(["**/*Test.java"]),
2323
test_deps = ["@maven//:org_junit_jupiter_junit_jupiter_api"],
2424
classpath_jars = ["@maven//:org_junit_platform_junit_platform_console_standalone"],
25-
test_image_base = "@distroless_java",
25+
test_image_base = "@openjdk",
2626
)

examples/junit-image-test/HelloTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@
1818
package com.salesforce.rules_docker_compose_test.HelloTest;
1919

2020
import org.junit.jupiter.api.Test;
21-
import static org.junit.jupiter.api.Assertions.assertTrue;
21+
import java.io.IOException;
2222

23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
2325

2426
class HelloTest {
2527

2628
@Test
27-
void helloWorldContainsHello() {
29+
void helloWorldContainsHello() throws IOException, InterruptedException {
30+
// Testing that the $JAVA_HOME/bin binaries are available
31+
ProcessBuilder processBuilder = new ProcessBuilder(new String[]{"sh", "-c", "jstat --help"});
32+
Process process = processBuilder.start();
33+
int exitValue = process.waitFor();
34+
assertEquals(0, exitValue);
2835
assertTrue("Hello World!".contains("Hello"));
2936
}
30-
}
37+
}

examples/junit-image-test/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
services:
1717
test_container:
1818
image: junit-image-test:test_container
19-
entrypoint: ["/busybox/sh", "./test_container_entrypoint.sh"]
19+
entrypoint: ["/bin/bash", "./test_container_entrypoint.sh"]
2020
environment:
21-
- JAVA_HOME=/usr/
21+
- JAVA_HOME=/usr/local/openjdk-*

examples/locally-built-image-test/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pkg_tar(
2525

2626
oci_image(
2727
name = "java_image",
28-
base = "@distroless_java",
28+
base = "@openjdk",
2929
tars = [
3030
":files",
3131
],

0 commit comments

Comments
 (0)