Skip to content

Commit

Permalink
feat: use imagetest for JDK/JRE (#2476)
Browse files Browse the repository at this point in the history
* feat: use imagetest for JDK/JRE

Bump the imagetest provider to v0.0.15 and use it to run tests against the JDK
and JRE images.

Signed-off-by: Mauren Berti <[email protected]>

* chore(jre): migrate version test to imagetest

Signed-off-by: Mauren Berti <[email protected]>

---------

Signed-off-by: Mauren Berti <[email protected]>
  • Loading branch information
stormqueen1990 authored Apr 10, 2024
1 parent 28e36de commit d659aa2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 52 deletions.
12 changes: 6 additions & 6 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 0 additions & 28 deletions images/jre/tests/02-hello-world.sh

This file was deleted.

89 changes: 71 additions & 18 deletions images/jre/tests/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
oci = { source = "chainguard-dev/oci" }
imagetest = { source = "chainguard-dev/imagetest" }
}
}

Expand All @@ -25,24 +26,76 @@ variable "sdk-image" {
default = "cgr.dev/chainguard/jdk"
}

data "oci_exec_test" "version" {
digest = var.digest
script = "docker run --rm --entrypoint /usr/bin/java $IMAGE_NAME -version"
data "imagetest_inventory" "this" {}

resource "imagetest_container_volume" "volume" {
name = "scratch-volume"
inventory = data.imagetest_inventory.this
}

data "oci_exec_test" "hello-world" {
digest = var.digest
script = "${path.module}/02-hello-world.sh"
env {
name = "SDK_IMAGE"
value = var.sdk-image
}
env {
name = "JAVA_SOURCE_VERSION"
value = var.java-source-version
}
env {
name = "JAVA_TARGET_VERSION"
value = var.java-target-version
resource "imagetest_harness_docker" "this" {
name = "jre"
inventory = data.imagetest_inventory.this

volumes = [
{
source = imagetest_container_volume.volume
destination = "/data"
}
]

mounts = [
{
source = path.module
destination = "/tests"
}
]

envs = {
"SDK_IMAGE" : var.sdk-image
"IMAGE_NAME" : var.digest
"JAVA_SOURCE_VERSION" : var.java-source-version
"JAVA_TARGET_VERSION" : var.java-target-version
"VOLUME_NAME" : imagetest_container_volume.volume.id
}
}

resource "imagetest_feature" "basic" {
name = "basic test"
harness = imagetest_harness_docker.this

steps = [
{
name = "Version check"
cmd = <<EOT
docker run --rm --entrypoint /usr/bin/java $IMAGE_NAME -version
EOT
},
{
name = "Prepare permissions and copy files"
cmd = <<EOT
chmod 777 /data
cp -r /tests/* /data
ls -al /data
EOT
},
{
name = "Run tests"
cmd = <<EOT
# Compile the .java file into a .class file
docker run --rm \
-v $VOLUME_NAME:/data \
--workdir /data \
--entrypoint /usr/bin/javac "$SDK_IMAGE" \
-source $JAVA_SOURCE_VERSION -target $JAVA_TARGET_VERSION \
HelloWorld.java
# Now we have the .class file, run it to test our JRE.
docker run --rm \
-v $VOLUME_NAME:/data \
--workdir /data \
--entrypoint /usr/bin/java "$IMAGE_NAME" HelloWorld
EOT
}
]
}

0 comments on commit d659aa2

Please sign in to comment.