Skip to content

Commit e5520bb

Browse files
authored
improve cleanup handling & fix CI (#37)
* improve cleanup * update * improve cleanup * update * update * update * try to make fail * update
1 parent d12c53a commit e5520bb

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
runs-on: ubuntu-latest
2525
steps:
2626
- uses: actions/checkout@v4
27-
- uses: bazelbuild/setup-bazelisk@95c9bf48d0c570bb3e28e57108f3450cd67c1a44 # v2.0.0
27+
- uses: bazel-contrib/setup-bazel@0.18.0
2828
- run: bazel build //...
2929
- run: cd examples && bazel build //...
3030
- run: cd examples && bazel test //...

docker_compose_test/docker_compose_test.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,29 @@ if [ $? -eq 0 ]; then
5353
docker_compose_bin="docker-compose"
5454
fi
5555

56-
# bring up compose file & get exit status-code from the integration test container
56+
cleanup() {
57+
echo "Cleaning up docker-compose resources..."
58+
docker_compose_down_cmd="$docker_compose_bin -f $ABSOLUTE_COMPOSE_FILE_PATH down --volumes --remove-orphans"
59+
echo "running: $docker_compose_down_cmd"
60+
echo "$docker_compose_down_cmd" | bash
61+
}
62+
63+
# Ensure cleanup runs on EXIT (covers normal exit, errors, and signals).
64+
# SIGTERM: sent by Bazel on test timeout or cancellation.
65+
# SIGINT: sent on Ctrl+C.
66+
trap cleanup EXIT
67+
68+
# bring up compose file & get exit status-code from the integration test container.
5769
docker_compose_up_cmd="$docker_compose_bin -f $ABSOLUTE_COMPOSE_FILE_PATH up --exit-code-from $DOCKER_COMPOSE_TEST_CONTAINER $EXTRA_DOCKER_COMPOSE_UP_ARGS"
5870
echo "running: $docker_compose_up_cmd"
5971
echo "$docker_compose_up_cmd" | bash
6072
result=$?
6173

62-
$docker_compose_bin -f $ABSOLUTE_COMPOSE_FILE_PATH down
74+
# Figure out the exit code of the test container incase it never actually started.
75+
EXIT_CODE=$(docker inspect $(docker compose -f $ABSOLUTE_COMPOSE_FILE_PATH ps -qa $DOCKER_COMPOSE_TEST_CONTAINER) --format='{{.State.ExitCode}}' 2>/dev/null)
76+
if [ "$EXIT_CODE" != "0" ] || [ -z "$EXIT_CODE" ]; then
77+
echo "Error: $DOCKER_COMPOSE_TEST_CONTAINER container failed or never started!"
78+
exit 1
79+
fi
6380

6481
exit $result

0 commit comments

Comments
 (0)