Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: revert docker harness tests #2491

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .terraform.lock.hcl

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

41 changes: 6 additions & 35 deletions images/envoy-ratelimit/tests/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,16 @@ variable "digest" {

data "oci_string" "ref" { input = var.digest }

data "imagetest_inventory" "this" {}

resource "imagetest_harness_docker" "this" {
name = "envoy-ratelimit-container"
inventory = data.imagetest_inventory.this

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

envs = {
IMAGE_NAME : var.digest
}
# TODO: Convert this to imagetest_harness_container when ready
data "oci_exec_test" "runs" {
digest = var.digest
script = "${path.module}/runs.sh"
}

resource "imagetest_feature" "container_runs" {
name = "container runs"
description = "verifies that the envoy-ratelimit container runs"
harness = imagetest_harness_docker.this

steps = [
{
name = "Run test"
cmd = <<EOT
docker run --rm $IMAGE_NAME 2>&1 | grep "creating redis connection error"
EOT
}
]

labels = {
type = "container"
}
}
data "imagetest_inventory" "this" {}

resource "imagetest_harness_k3s" "this" {
name = "envoy-ratelimit-k3s"
name = "envoy-ratelimit"
inventory = data.imagetest_inventory.this

sandbox = {
Expand Down
7 changes: 7 additions & 0 deletions images/envoy-ratelimit/tests/runs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o errtrace -o pipefail -x

set +o pipefail # We expect the command to fail, but want its output anyway.

docker run --rm "${IMAGE_NAME}" 2>&1 | grep "creating redis connection error"
33 changes: 9 additions & 24 deletions images/external-secrets/tests/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,19 @@ data "oci_string" "ref" {
input = var.digest
}

data "imagetest_inventory" "this" {}

resource "imagetest_harness_docker" "this" {
name = "external-secrets-container"
inventory = data.imagetest_inventory.this

envs = {
IMAGE_NAME : var.digest
}
# TODO: Convert this to imagetest_harness_container when ready
data "oci_exec_test" "version" {
digest = var.digest
script = <<EOF
# We expect the command to fail, but want its output anyway.
( docker run --rm $IMAGE_NAME --help 2>&1 || true ) | grep external-secrets
EOF
}

resource "imagetest_feature" "this" {
harness = imagetest_harness_docker.this
name = "basic container test"
description = "basic container test to verify that things run as expected"

steps = [
{
name = "Run container"
cmd = <<EOT
docker run --rm $IMAGE_NAME --help 2>&1
EOT
}
]
}
data "imagetest_inventory" "this" {}

resource "imagetest_harness_k3s" "this" {
name = "external-secrets-k3s"
name = "external-secrets"
inventory = data.imagetest_inventory.this

sandbox = {
Expand Down
28 changes: 28 additions & 0 deletions images/jre/tests/02-hello-world.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o errtrace -o pipefail

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
TMP=$(mktemp -d)
JAVA_SOURCE_VERSION="${JAVA_SOURCE_VERSION:-8}"
JAVA_TARGET_VERSION="${JAVA_TARGET_VERSION:-8}"

function cleanup() {
rm -rf "${TMP}"
}
trap cleanup EXIT

cp "${SCRIPT_DIR}"/*.java "${TMP}"

# Make this writeable by the nonroot container user
chmod 777 "${TMP}"

docker run --rm -v "${TMP}:/tmp" \
`# Build using the latest JDK image` \
--entrypoint "javac" "${SDK_IMAGE}" \
`# Targeting Java 8 so that all our JREs can run the produced .class file` \
-source ${JAVA_SOURCE_VERSION} -target ${JAVA_TARGET_VERSION} \
/tmp/HelloWorld.java -d /tmp

# Now we have the .class file, run it to test our JRE.
docker run --rm -v "${TMP}:/tmp" --entrypoint "java" "${IMAGE_NAME}" -cp /tmp HelloWorld
89 changes: 18 additions & 71 deletions images/jre/tests/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
imagetest = { source = "chainguard-dev/imagetest" }
oci = { source = "chainguard-dev/oci" }
}
}

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

data "imagetest_inventory" "this" {}

resource "imagetest_container_volume" "volume" {
name = "scratch-volume"
inventory = data.imagetest_inventory.this
data "oci_exec_test" "version" {
digest = var.digest
script = "docker run --rm --entrypoint /usr/bin/java $IMAGE_NAME -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
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_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
}
]
}
Loading