2022-08-02 20:45:02 -06:00
#!/bin/bash
2022-11-01 20:30:10 +09:00
source logger.sh
source graceful-stop.sh
trap graceful_stop TERM
2022-08-02 20:45:02 -06:00
log.notice "Writing out Docker config file"
/bin/bash <<SCRIPT
if [ ! -f /home/runner/.config/docker/daemon.json ] ; then
echo "{}" > /home/runner/.config/docker/daemon.json
fi
if [ -n " ${ MTU } " ] ; then
jq " .\"mtu\" = ${ MTU } " /home/runner/.config/docker/daemon.json > /tmp/.daemon.json && mv /tmp/.daemon.json /home/runner/.config/docker/daemon.json
2022-10-13 09:04:56 +09:00
# See https://docs.docker.com/engine/security/rootless/ and https://github.com/docker/engine/blob/8955d8da8951695a98eb7e15bead19d402c6eb27/contrib/dockerd-rootless.sh#L13
2022-11-04 06:29:03 +09:00
echo " DOCKERD_ROOTLESS_ROOTLESSKIT_MTU= ${ MTU } " | sudo tee -a /etc/environment
2022-08-02 20:45:02 -06:00
fi
2022-11-05 06:46:32 +01:00
if [ -n " ${ DOCKER_DEFAULT_ADDRESS_POOL_BASE } " ] && [ -n " ${ DOCKER_DEFAULT_ADDRESS_POOL_SIZE } " ] ; then
jq " .\"default-address-pools\" = [{\"base\": \" ${ DOCKER_DEFAULT_ADDRESS_POOL_BASE } \", \"size\": ${ DOCKER_DEFAULT_ADDRESS_POOL_SIZE } }] " /home/runner/.config/docker/daemon.json > /tmp/.daemon.json && mv /tmp/.daemon.json /home/runner/.config/docker/daemon.json
fi
2022-08-02 20:45:02 -06:00
if [ -n " ${ DOCKER_REGISTRY_MIRROR } " ] ; then
jq " .\"registry-mirrors\"[0] = \" ${ DOCKER_REGISTRY_MIRROR } \" " /home/runner/.config/docker/daemon.json > /tmp/.daemon.json && mv /tmp/.daemon.json /home/runner/.config/docker/daemon.json
fi
SCRIPT
2022-11-04 06:46:21 +09:00
if [ -d /home/runner/.local ] ; then
if [ ! -d /home/runner/.local/share ] ; then
log.notice " Creating /home/runner/.local/share owned by runner:runner \
so that rootless dockerd will not fail with a permission error when creating /home/runner/.local/share/docker"
sudo mkdir /home/runner/.local/share
sudo chmod 755 /home/runner/.local/share
sudo chown runner:runner /home/runner/.local/share
fi
fi
2022-08-02 20:45:02 -06:00
log.notice "Starting Docker (rootless)"
2022-11-01 20:30:10 +09:00
dumb-init bash <<'SCRIPT' &
# Note that we don't want dockerd to be terminated before the runner agent,
# because it defeats the goal of the runner agent graceful stop logic implemenbed above.
# We can't rely on e.g. `dumb-init --single-child` for that, because with `--single-child` we can't even trap SIGTERM
# for not only dockerd but also the runner agent.
2022-11-04 06:28:47 +09:00
/home/runner/bin/dockerd-rootless.sh --config-file /home/runner/.config/docker/daemon.json &
2022-08-02 20:45:02 -06:00
2022-11-01 20:30:10 +09:00
startup.sh
SCRIPT
RUNNER_INIT_PID = $!
log.notice " Runner init started with pid $RUNNER_INIT_PID "
wait $RUNNER_INIT_PID
log.notice "Runner init exited. Exiting this process with code 0 so that the container and the pod is GC'ed Kubernetes soon."
trap - TERM