Open
Description
This proposal aims to enrich the developer experience of imagetest_harness_docker
module.
Abstract
By extending the capabilities of imagetest_harness_docker
to handle multiple variables, we eliminate the need to manually write docker container run <ARGS>
in each test script. Additionally, running the tests within the same network removes the necessity to execute networking-related tests in a separate container, which currently requires passing --network container:"${CONTAINER_NAME}"
.
Current Flow
resource "imagetest_harness_docker" "docker" {
name = "test"
inventory = data.imagetest_inventory.this
mounts = [{
source = path.module
destination = "/tests"
}]
envs = {
IMAGE_NAME : var.digest
}
}
Then we need to run the container inside the test script first:
0. Add required tools
apk add curl jq nodejs npm
1. Run the container first
docker run \
-d --rm \
-p 8080:8080 \
-p 9090:9090 \
-e FOO=BAR \
--name "${CONTAINER_NAME}" \
"${IMAGE_NAME}"
2. If you need to access ports, you need to set network
curl() {
docker run --network container:"${CONTAINER_NAME}" curl "$@"
}
- Run tests
curl http://localhost:8080/health | jq -e '.status == "UP"'
curl http://localhost:9090/health | jq -e '.status == "UP"'
docker run --network container:"${CONTAINER_NAME}" node bash -c "/usr/local/bin/npm install -g tool && tool --address localhost:9090 status"
Proposed Flow
Expose some variables to pass docker container run
:
resource "imagetest_harness_docker" "docker" {
...
ports = [8080, 9090]
read_only = true
platform = ["linux/x86_64"]
...
}
In the test script:
- Required testing tools are provided by default, so we don't need to
apk add
for common tools. imagetest_harness_docker
will run the container by exposing the ports, etc.- Wait until container to be running state
- We can able to run network-related tests without needing to execute them inside a container using
--network container:"${CONTAINER_NAME}"
.
resource "imagetest_feature" "docker" {
name = "camunda-zeebe-docker-test"
harness = imagetest_harness_docker.docker
steps = [{
name = "Smoke test"
cmd = <<EOF
curl http://localhost:8080/health | jq -e '.status == "UP"'
curl http://localhost:9090/health | jq -e '.status == "UP"'
npm install -g tool && tool --address localhost:9090 status"
EOF
}]
}
Current Behavior
curl: (7) Failed to connect to localhost port 8080 after 0 ms: Could not connect to server
curl: (7) Failed to connect to localhost port 9090 after 0 ms: Could not connect to server
Metadata
Metadata
Assignees
Labels
No labels