From 0e0b300a1ce42e21d0cefbe2f159005d398c7ff3 Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Thu, 3 Feb 2022 14:42:37 -0500 Subject: [PATCH] Fix `make BIND_DIR=. DOCKER_SYSTEMD=1 shell` Signed-off-by: Cory Snider --- Dockerfile | 3 --- hack/dind-systemd | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100755 hack/dind-systemd diff --git a/Dockerfile b/Dockerfile index feb14a0932..edb50a73a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -386,9 +386,6 @@ RUN --mount=type=cache,sharing=locked,id=moby-dev-aptlib,target=/var/lib/apt \ dbus-user-session \ systemd \ systemd-sysv -RUN mkdir -p hack \ - && curl -o hack/dind-systemd https://raw.githubusercontent.com/AkihiroSuda/containerized-systemd/b70bac0daeea120456764248164c21684ade7d0d/docker-entrypoint.sh \ - && chmod +x hack/dind-systemd ENTRYPOINT ["hack/dind-systemd"] FROM dev-systemd-${SYSTEMD} AS dev diff --git a/hack/dind-systemd b/hack/dind-systemd new file mode 100755 index 0000000000..27e07badd3 --- /dev/null +++ b/hack/dind-systemd @@ -0,0 +1,62 @@ +#!/bin/bash +set -e +container=docker +export container + +if [ $# -eq 0 ]; then + echo >&2 'ERROR: No command specified. You probably want to run `journalctl -f`, or maybe `bash`?' + exit 1 +fi + +if [ ! -t 0 ]; then + echo >&2 'ERROR: TTY needs to be enabled (`docker run -t ...`).' + exit 1 +fi + +env > /etc/docker-entrypoint-env + +cat > /etc/systemd/system/docker-entrypoint.target << EOF +[Unit] +Description=the target for docker-entrypoint.service +Requires=docker-entrypoint.service systemd-logind.service systemd-user-sessions.service +EOF + +quoted_args="$(printf " %q" "${@}")" +echo "${quoted_args}" > /etc/docker-entrypoint-cmd + +cat > /etc/systemd/system/docker-entrypoint.service << EOF +[Unit] +Description=docker-entrypoint.service + +[Service] +ExecStart=/bin/bash -exc "source /etc/docker-entrypoint-cmd" +# EXIT_STATUS is either an exit code integer or a signal name string, see systemd.exec(5) +ExecStopPost=/bin/bash -ec "if echo \${EXIT_STATUS} | grep [A-Z] > /dev/null; then echo >&2 \"got signal \${EXIT_STATUS}\"; systemctl exit \$(( 128 + \$( kill -l \${EXIT_STATUS} ) )); else systemctl exit \${EXIT_STATUS}; fi" +StandardInput=tty-force +StandardOutput=inherit +StandardError=inherit +WorkingDirectory=$(pwd) +EnvironmentFile=/etc/docker-entrypoint-env + +[Install] +WantedBy=multi-user.target +EOF + +systemctl mask systemd-firstboot.service systemd-udevd.service +systemctl unmask systemd-logind +systemctl enable docker-entrypoint.service + +systemd= +if [ -x /lib/systemd/systemd ]; then + systemd=/lib/systemd/systemd +elif [ -x /usr/lib/systemd/systemd ]; then + systemd=/usr/lib/systemd/systemd +elif [ -x /sbin/init ]; then + systemd=/sbin/init +else + echo >&2 'ERROR: systemd is not installed' + exit 1 +fi +systemd_args="--show-status=false --unit=docker-entrypoint.target" +echo "$0: starting $systemd $systemd_args" +exec $systemd $systemd_args