From cf533616cb27a03bd75522d35a12eb0ab2e3abe9 Mon Sep 17 00:00:00 2001 From: Etienne Perot Date: Thu, 23 Jun 2022 16:21:38 -0700 Subject: [PATCH] BuildKite pre-command: Use alternate way to reload Docker when available. PiperOrigin-RevId: 456884864 --- .buildkite/hooks/pre-command | 23 +++++++++++++++++++---- Makefile | 7 +++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.buildkite/hooks/pre-command b/.buildkite/hooks/pre-command index c4f6da378..2e1dcc373 100644 --- a/.buildkite/hooks/pre-command +++ b/.buildkite/hooks/pre-command @@ -36,7 +36,15 @@ export TOTAL_PARTITIONS=${BUILDKITE_PARALLEL_JOB_COUNT:-1} export RUNTIME="buildkite_runtime_${BUILDKITE_BRANCH}-${BUILDKITE_BUILD_ID}" export RUNTIME="$(echo "$RUNTIME" | sed -r 's~[^-_a-z0-9]+~_~g')" -# Ensure Docker has experimental enabled. +# If running in a container, set the reload command appropriately. +if [[ -x /tmp/buildkite-reload-host-docker/reload ]]; then + export DOCKER_RELOAD_COMMAND='/tmp/buildkite-reload-host-docker/reload' +else + export DOCKER_RELOAD_COMMAND='sudo systemctl reload docker' +fi + +# Ensure Docker has experimental enabled, install runtimes. +HAD_EXPERIMENTAL="$(docker version --format='{{.Server.Experimental}}')" if [[ -n "${STAGED_BINARIES:-}" ]]; then # Used `runsc` from STAGED_BINARIES instead of building it from scratch. tmpdir="$(mktemp -d)" @@ -49,9 +57,16 @@ else make sudo TARGETS=//runsc:runsc \ ARGS="install --experimental=true --runtime=${RUNTIME} -- ${RUNTIME_ARGS:-}" fi -# WARNING: We may be running in a container when this command executes. -# This only makes sense if Docker's `live-restore` feature is enabled. -sudo systemctl restart docker +if [[ "$HAD_EXPERIMENTAL" == false ]]; 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. + 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. + bash -c "$DOCKER_RELOAD_COMMAND" +fi # Helper for benchmarks, based on the branch. if test "${BUILDKITE_BRANCH}" = "master"; then diff --git a/Makefile b/Makefile index cef1e8576..04ffe12f2 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,8 @@ endif ## RUNTIME_ARGS - Arguments passed to the runtime when installed. ## STAGED_BINARIES - A tarball of staged binaries. If this is set, then binaries ## will be installed from this staged bundle instead of built. -## +## DOCKER_RELOAD_COMMAND - The command to run to reload Docker. (default: sudo systemctl reload docker). + ifeq (,$(BRANCH_NAME)) RUNTIME := runsc RUNTIME_DIR := $(shell dirname $(shell mktemp -u))/$(RUNTIME) @@ -114,6 +115,7 @@ RUNTIME_BIN := $(RUNTIME_DIR)/runsc RUNTIME_LOG_DIR := $(RUNTIME_DIR)/logs RUNTIME_LOGS := $(RUNTIME_LOG_DIR)/runsc.log.%TEST%.%TIMESTAMP%.%COMMAND% RUNTIME_ARGS ?= +DOCKER_RELOAD_COMMAND ?= sudo systemctl reload docker ifeq ($(shell stat -f -c "%T" /sys/fs/cgroup 2>/dev/null),cgroup2fs) CGROUPV2 := true @@ -138,7 +140,8 @@ configure_noreload = \ sudo $(RUNTIME_BIN) install --experimental=true --runtime="$(1)" -- $(RUNTIME_ARGS) --debug-log "$(RUNTIME_LOGS)" $(2) && \ sudo rm -rf "$(RUNTIME_LOG_DIR)" && mkdir -p "$(RUNTIME_LOG_DIR)" reload_docker = \ - sudo systemctl reload docker && \ + $(call header,DOCKER RELOAD); \ + bash -xc "$(DOCKER_RELOAD_COMMAND)" && \ if test -f /etc/docker/daemon.json; then \ sudo chmod 0755 /etc/docker && \ sudo chmod 0644 /etc/docker/daemon.json; \