gVisor Makefile: Make bazel-shutdown target more robust.

It is possible that `docker exec` gets stuck when the container stops
existing. This change uses `timeout` to ensure that this cannot stay the
case for more than a timeout. It also tries to shut down the container in
other ways, and instead verifies that the container no longer exists at the
end of it.

PiperOrigin-RevId: 462725292
This commit is contained in:
Etienne Perot
2022-07-22 16:15:43 -07:00
committed by gVisor bot
parent bf4d27a6ca
commit 227b963b2f
+13 -1
View File
@@ -185,12 +185,24 @@ endif
# container in order to perform work via the bazel client.
ifeq ($(DOCKER_BUILD),true)
wrapper = docker exec $(DOCKER_EXEC_OPTIONS) $(DOCKER_NAME) $(1)
wrapper_timeout = timeout $(1) docker exec $(DOCKER_EXEC_OPTIONS) $(DOCKER_NAME) $(2)
else
wrapper = $(1)
wrapper_timeout = timeout $(1) $(2)
endif
bazel-shutdown: ## Shuts down a running bazel server.
@$(call wrapper,$(BAZEL) shutdown)
@$(call wrapper_timeout,--signal=KILL 30s,$(BAZEL) shutdown) || true
ifeq ($(DOCKER_BUILD),true)
# Docker can bug out and get stuck in `docker exec` despite the container
# already having been terminated. So this uses multiple ways to try to get the
# container to exit, and ignores which ones work and which ones don't.
# Instead, it just checks that the container no longer exists by the end of it.
@timeout --signal=KILL 10s docker wait $(DOCKER_NAME) 2>/dev/null || true
@docker stop --time=10 $(DOCKER_NAME) 2>/dev/null || true
# Double check that the container isn't running.
@bash -c "! docker inspect $(DOCKER_NAME) &>/dev/null"
endif
.PHONY: bazel-shutdown
bazel-alias: ## Emits an alias that can be used within the shell.