From eb5b888d97bac739483cf951778da9c6e660b202 Mon Sep 17 00:00:00 2001 From: Etienne Perot Date: Mon, 6 Mar 2023 12:40:57 -0800 Subject: [PATCH] BuildKite: Print Docker daemon configuration whenever it is modified/reloaded. Also don't completely remove the `runtimes` object from the JSON configuration during `post-command`; instead, replace it with an empty one. Reloading Docker versions with an empty one is apparently different than reloading it with no `runtimes` at all. PiperOrigin-RevId: 514494269 --- .buildkite/hooks/post-command | 4 +++- .buildkite/hooks/pre-command | 14 ++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.buildkite/hooks/post-command b/.buildkite/hooks/post-command index 88bbbb49f..ec991c575 100644 --- a/.buildkite/hooks/post-command +++ b/.buildkite/hooks/post-command @@ -87,9 +87,11 @@ if [[ "${BUILDKITE_PIPELINE_INSTALL_RUNTIME:-}" == "true" ]]; then '(if has("runtimes") then .runtimes else {} end) | length' \ < /etc/docker/daemon.json)" if [[ "$num_docker_runtimes" -gt 0 ]]; then - cat /etc/docker/daemon.json | jq 'del(.runtimes)' \ + cat /etc/docker/daemon.json | jq '.runtimes = {}' \ | sudo tee /etc/docker/daemon.json.tmp sudo mv /etc/docker/daemon.json.tmp /etc/docker/daemon.json + echo 'Removed all Docker runtimes; reloading Docker daemon with this new configuration:' >&2 + cat /etc/docker/daemon.json >&2 bash -c "$DOCKER_RELOAD_COMMAND" fi fi diff --git a/.buildkite/hooks/pre-command b/.buildkite/hooks/pre-command index 0d2fc101e..c79bc3a25 100644 --- a/.buildkite/hooks/pre-command +++ b/.buildkite/hooks/pre-command @@ -49,7 +49,9 @@ fi if [[ "${BUILDKITE_PIPELINE_INSTALL_RUNTIME:-}" == "true" ]]; then # Ensure Docker has experimental enabled, install runtimes. - HAD_EXPERIMENTAL="$(docker version --format='{{.Server.Experimental}}')" + echo 'Current Docker daemon configuration:' >&2 + cat /etc/docker/daemon.json >&2 + HAD_EXPERIMENTAL="$(cat /etc/docker/daemon.json | jq '.experimental')" if [[ -n "${STAGED_BINARIES:-}" ]]; then # Used `runsc` from STAGED_BINARIES instead of building it from scratch. export BUILDKITE_STAGED_BINARIES_DIRECTORY="$(mktemp -d)" @@ -57,20 +59,24 @@ if [[ "${BUILDKITE_PIPELINE_INSTALL_RUNTIME:-}" == "true" ]]; then | tar -C "$BUILDKITE_STAGED_BINARIES_DIRECTORY" -zxvf - runsc chmod +x "$BUILDKITE_STAGED_BINARIES_DIRECTORY/runsc" sudo "$BUILDKITE_STAGED_BINARIES_DIRECTORY/runsc" install \ - --experimental=true --runtime="${RUNTIME}" \ - -- "${RUNTIME_ARGS:-}" + --experimental=true --runtime="${RUNTIME}" \ + -- "${RUNTIME_ARGS:-}" else make sudo TARGETS=//runsc:runsc \ ARGS="install --experimental=true --runtime=${RUNTIME} -- ${RUNTIME_ARGS:-}" fi - if [[ "$HAD_EXPERIMENTAL" == false ]]; then + if [[ "$HAD_EXPERIMENTAL" != true ]]; then # WARNING: We may be running in a container when this command executes. # This only makes sense if Docker's `live-restore` feature is enabled. + echo 'Restarting Docker daemon with this new configuration:' >&2 + cat /etc/docker/daemon.json >&2 sudo systemctl restart docker else # If experimental-ness was already enabled, we don't need to restart, as the # only thing we modified is the list of runtimes, which can be reloaded with # just a SIGHUP. + echo 'Reloading Docker daemon with this new configuration:' >&2 + cat /etc/docker/daemon.json >&2 bash -c "$DOCKER_RELOAD_COMMAND" fi fi