Skip to content

Commit c191ceb

Browse files
avagingvisor-bot
authored andcommitted
buildkite: clean up docker containers from previous jobs
When buildkite cancels jobs, it doesn't run the post-coomand hook, so some docker containers can continue running. PiperOrigin-RevId: 721001481
1 parent ddebbe5 commit c191ceb

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

.buildkite/hooks/libhook

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# Copyright 2025 The gVisor Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
clear_docker_containers() {
18+
# Kill any running containers (clear state), except for "bootstrap".
19+
for id_and_name in $(docker ps --format='{{.ID}}/{{.Names}}'); do
20+
if [[ "$(echo "$id_and_name" | cut -d'/' -f2-)" == 'bootstrap' ]]; then
21+
continue
22+
fi
23+
timeout --kill-after=10s --preserve-status 30s \
24+
docker container kill "$(echo "$id_and_name" | cut -d'/' -f1)"
25+
done
26+
}

.buildkite/hooks/post-command

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
set -x
22

3+
source .buildkite/hooks/libhook
4+
35
# Clear any downloaded credentials.
46
rm -f repo.key
57

@@ -70,14 +72,7 @@ if test "${BUILDKITE_COMMAND_EXIT_STATUS}" -ne "0"; then
7072
sudo rm -rf "${HOME}/go"
7173
fi
7274

73-
# Kill any running containers (clear state), except for "bootstrap".
74-
for id_and_name in $(docker ps --format='{{.ID}}/{{.Names}}'); do
75-
if [[ "$(echo "$id_and_name" | cut -d'/' -f2-)" == 'bootstrap' ]]; then
76-
continue
77-
fi
78-
timeout --kill-after=10s --preserve-status 8s \
79-
docker container kill "$(echo "$id_and_name" | cut -d'/' -f1)"
80-
done
75+
clear_docker_containers
8176

8277
set -euo pipefail
8378

.buildkite/hooks/pre-command

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
set -euo pipefail
22

3+
source .buildkite/hooks/libhook
4+
5+
clear_docker_containers
6+
37
# Use a per-day bazel remote cache. As the cache object's TTL expires, they are
48
# deleted on an ongoing basis. Such partial deletion can break the cache state.
59
# Using per day cache will ensure that builds triggered on a certain day have

0 commit comments

Comments
 (0)