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

imagetest_harness_docker: export configurable variables to start container and run tests in the same network #176

Open
Dentrax opened this issue Aug 26, 2024 · 0 comments

Comments

@Dentrax
Copy link

Dentrax commented Aug 26, 2024

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 "$@"
}
  1. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant