Skip to content

Commit

Permalink
extra docker compose up args (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
kriscfoster authored Mar 21, 2024
1 parent 49eca8a commit 0e7a17e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 6 additions & 3 deletions docker_compose/docker_compose_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [],
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -132,20 +134,21 @@ 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,
**kwargs,
)


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):
Expand Down
4 changes: 3 additions & 1 deletion docker_compose/docker_compose_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion examples/pre-compose-up-script-test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

0 comments on commit 0e7a17e

Please sign in to comment.