-
Notifications
You must be signed in to change notification settings - Fork 5
/
action.yaml
79 lines (78 loc) · 2.65 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: Rootless Docker
author: Kurt von Laven
description: Run Docker in Rootless Mode to Prevent Permission Errors
branding:
icon: lock
color: blue
runs:
using: composite
steps:
- name: Check whether rootless Docker is already installed and/or in-use.
id: rootless-docker
run: |
in_use='false'
if docker context ls --format '{{ .Name }}' | grep --quiet '^rootless$'
then
installed='true'
if [[ "$(docker info --format '{{ .ClientInfo.Context }}')" == 'rootless' ]]
then
in_use='true'
fi
else
installed='false'
fi
echo "INSTALLED=$installed" >>"$GITHUB_OUTPUT"
echo "IN_USE=$in_use" >>"$GITHUB_OUTPUT"
shell: bash
- name: Stop rootful Docker daemon.
if: steps.rootless-docker.outputs.IN_USE != 'true'
run: sudo systemctl stop docker.service
shell: bash
- name: Install rootless Docker, start daemon, and wait until it's listening.
if: steps.rootless-docker.outputs.INSTALLED != 'true'
run: |
echo ~/bin >>"$GITHUB_PATH"
if [[ -z $XDG_RUNTIME_DIR ]]; then
XDG_RUNTIME_DIR=~/.docker/run
echo XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" >>"$GITHUB_ENV"
fi
function awaitDockerd() {
while IFS= read -r -t 60 line; do
echo "$line"
[[ "$line" = *"API listen on $XDG_RUNTIME_DIR/docker.sock"* ]] && return
done
echo 'Timed out waiting for Docker daemon to listen.' >&2
return 1
}
install_script_output="$(
curl \
--fail-with-body \
--silent \
--show-error \
--location https://get.docker.com/rootless |
sh
)"
echo "$install_script_output"
docker context use rootless
if (
grep --quiet 'systemd not detected, dockerd-rootless.sh needs to be started manually' \
<<<"$install_script_output"
); then
(PATH="/sbin:/usr/sbin:$PATH" dockerd-rootless.sh &) |&
awaitDockerd
fi
env:
FORCE_ROOTLESS_INSTALL: "1"
shell: bash
- name: Proxy bidirectionally between rootful and rootless Docker sockets.
if: steps.rootless-docker.outputs.IN_USE != 'true'
run: >
sudo systemd-run
--unit=docker-proxy.service
--description='Bidirectional proxy between rootful and rootless Docker sockets'
--service-type=exec
--property=Requires=docker.socket
--property=PrivateNetwork=true
--property=PrivateTmp=true
/lib/systemd/systemd-socket-proxyd "$XDG_RUNTIME_DIR/docker.sock"
shell: bash