Skip to content

A runner shim for launching container images with bazel's `rules_itest`

License

Notifications You must be signed in to change notification settings

jaqx0r/itestcontainer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

itestcontainer

itestcontainer is a runner shim invoked by rules_itest's itest_service as an exe to launch a container image as the system under test.

Example:

load("@rules_img//img:image.bzl", "image_manifest")
load("@rules_img//img:load.bzl", "image_load")
load("@rules_itest//:itest.bzl", "itest_service", "itest_task")

platform(
    name = "host_docker_platform",
    constraint_values = ["@platforms//os:linux"],  # linux OS inside docker host
    parents = ["@platforms//host"],  # use host CPU
)

# Construct a Postgresql for the container host
image_manifest(
    name = "pg_image",
    base = "@postgresql",
    platform = ":host_docker_platform",
)

# An executable target to load the image into the container host
image_load(
    name = "load_pg_image",
    image = ":pg_image",
    tag = "pg_image:latest",
)

# A task that invokes the previous executable target
itest_task(
    name = "load_pg_image_task",
    testonly = True,
    exe = ":load_pg_image",
)

# The service under test, which depends on the load task to load the image, and then invokes `itestcontainer` to run the image with the provided options.
itest_service(
    name = "sut",
    testonly = True,
    args = [
        # Name of the image to start
        "--name=pg_image:latest",
        # Environment variables to pass through to the container
        "--env=POSTGRES_USER,POSTGRES_PASSWORD,POSTGRES_DB",
        # Ports to expose from the container
        "--ports=$${@@//:sut:db}:5432"
        # --labels
        # --volume
    ],
    env = {
        "POSTGRES_USER": "postgres",
        "POSTGRES_PASSWORD": "postgres",
        "POSTGRES_DB": "postgres",
    },
    exe = "@com_github_jaqx0r_itestcontainer//:itestcontainer",
    named_ports = [
        "db",
    ],
    deps = [":load_pg_image_task"],
)

Use the Go Tools Pattern to include itestcontainer into your dependencies.

See test/tools.go and the rest of the test directory for a full example.

About

A runner shim for launching container images with bazel's `rules_itest`

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •