From 0e7a17e216a1b5fca84c0f7a42c68918f735a221 Mon Sep 17 00:00:00 2001 From: Kris foster Date: Thu, 21 Mar 2024 20:23:38 +0000 Subject: [PATCH] extra docker compose up args (#11) --- README.md | 4 ++++ docker_compose/docker_compose_test.bzl | 9 ++++++--- docker_compose/docker_compose_test.sh | 4 +++- examples/pre-compose-up-script-test/BUILD | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 832d01d..80f3e52 100644 --- a/README.md +++ b/README.md @@ -105,3 +105,7 @@ services: ## Pre compose up script Sometimes, you may need some logic to run before the compose test containers come up. You can use `pre_compose_up_script` for that purpose. See [examples/pre-compose-up-script-test](examples/pre-compose-up-script-test) for an example. + +## extra_docker_compose_up_args + +You can append extra arguments to the `docker compose up` command using `extra_docker_compose_up_args`. See [examples/pre-compose-up-script-test](examples/pre-compose-up-script-test) for an example. diff --git a/docker_compose/docker_compose_test.bzl b/docker_compose/docker_compose_test.bzl index 4173d96..6b64a11 100644 --- a/docker_compose/docker_compose_test.bzl +++ b/docker_compose/docker_compose_test.bzl @@ -28,6 +28,7 @@ def docker_compose_test( docker_compose_file, docker_compose_test_container, pre_compose_up_script = "", + extra_docker_compose_up_args = "", local_image_targets = "", data = [], tags = [], @@ -40,7 +41,7 @@ def docker_compose_test( native.sh_test( name = name, srcs = ["@rules_docker_compose//docker_compose:docker_compose_test.sh"], - env = _get_env(docker_compose_file, local_image_targets, docker_compose_test_container, pre_compose_up_script), + env = _get_env(docker_compose_file, local_image_targets, docker_compose_test_container, pre_compose_up_script, extra_docker_compose_up_args), size = size, tags = tags, data = data, @@ -53,6 +54,7 @@ def junit_docker_compose_test( docker_compose_file, docker_compose_test_container, pre_compose_up_script = "", + extra_docker_compose_up_args = "", local_image_targets = "", classpath_jars = [], test_image_base = None, @@ -132,7 +134,7 @@ def junit_docker_compose_test( native.sh_test( name = name, srcs = ["@rules_docker_compose//docker_compose:docker_compose_test.sh"], - env = _get_env(docker_compose_file, local_image_targets, docker_compose_test_container, pre_compose_up_script), + env = _get_env(docker_compose_file, local_image_targets, docker_compose_test_container, pre_compose_up_script, extra_docker_compose_up_args), size = size, tags = tags, data = data, @@ -140,12 +142,13 @@ def junit_docker_compose_test( ) -def _get_env(docker_compose_file, local_image_targets, docker_compose_test_container, pre_compose_up_script): +def _get_env(docker_compose_file, local_image_targets, docker_compose_test_container, pre_compose_up_script, extra_docker_compose_up_args): env = { "WORKSPACE_PATH": BUILD_WORKSPACE_DIRECTORY, "DOCKER_COMPOSE_FILE": "$(location " + docker_compose_file + ")", "LOCAL_IMAGE_TARGETS": local_image_targets.replace(":", "/"), "DOCKER_COMPOSE_TEST_CONTAINER": docker_compose_test_container, + "EXTRA_DOCKER_COMPOSE_UP_ARGS": extra_docker_compose_up_args, } if len(pre_compose_up_script): diff --git a/docker_compose/docker_compose_test.sh b/docker_compose/docker_compose_test.sh index c22c153..bea6f83 100755 --- a/docker_compose/docker_compose_test.sh +++ b/docker_compose/docker_compose_test.sh @@ -48,7 +48,9 @@ fi ABSOLUTE_COMPOSE_FILE_PATH=$WORKSPACE_PATH/$DOCKER_COMPOSE_FILE # bring up compose file & get exit status-code from the integration test container -docker-compose -f $ABSOLUTE_COMPOSE_FILE_PATH up --exit-code-from $DOCKER_COMPOSE_TEST_CONTAINER +docker_compose_up_cmd="docker-compose -f $ABSOLUTE_COMPOSE_FILE_PATH up --exit-code-from $DOCKER_COMPOSE_TEST_CONTAINER $EXTRA_DOCKER_COMPOSE_UP_ARGS" +echo "running: $docker_compose_up_cmd" +echo "$docker_compose_up_cmd" | bash result=$? docker-compose -f $ABSOLUTE_COMPOSE_FILE_PATH down exit $result diff --git a/examples/pre-compose-up-script-test/BUILD b/examples/pre-compose-up-script-test/BUILD index c983eb7..7766881 100644 --- a/examples/pre-compose-up-script-test/BUILD +++ b/examples/pre-compose-up-script-test/BUILD @@ -19,5 +19,6 @@ docker_compose_test( name = "pre-compose-up-script-test", docker_compose_file = ":docker-compose.yml", docker_compose_test_container = "test_container", - pre_compose_up_script = ":src/test/resources/setup_test.sh" + pre_compose_up_script = ":src/test/resources/setup_test.sh", + extra_docker_compose_up_args = "--no-color", )