Debian Codegraph @

engine/hack/make/.integration-daemon-start

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # see test-integration for example usage of this script
4
5 base="$ABS_DEST/.."
6 export PATH="$base/dynbinary-daemon:$base/binary-daemon:$PATH"
7
8 if [ -z "$TEST_CLIENT_BINARY" ]; then
9 export TEST_CLIENT_BINARY=docker
10 fi
11 if [ -n "$DOCKER_CLI_PATH" ]; then
12 # /usr/local/cli is a bind mount to the base dir of DOCKER_CLI_PATH (if used)
13 export TEST_CLIENT_BINARY=/usr/local/cli/$(basename "$DOCKER_CLI_PATH")
14 fi
15
16 echo "Using test binary $TEST_CLIENT_BINARY"
17 if ! command -v "$TEST_CLIENT_BINARY" &> /dev/null; then
18 echo >&2 'error: missing test client $TEST_CLIENT_BINARY'
19 false
20 fi
21
22 # This is a temporary hack for split-binary mode. It can be removed once
23 # https://github.com/docker/docker/pull/22134 is merged into docker master
24 if [ "$(go env GOOS)" = 'windows' ]; then
25 return
26 fi
27
28 if [ -z "$DOCKER_TEST_HOST" ]; then
29 if docker version &> /dev/null; then
30 echo >&2 'skipping daemon start, since daemon appears to be already started'
31 return
32 fi
33 fi
34
35 if ! command -v dockerd &> /dev/null; then
36 echo >&2 'error: binary-daemon or dynbinary-daemon must be run before .integration-daemon-start'
37 false
38 fi
39
40 # intentionally open a couple bogus file descriptors to help test that they get scrubbed in containers
41 exec 41>&1 42>&2
42
43 export DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-vfs}
44 export DOCKER_USERLANDPROXY=${DOCKER_USERLANDPROXY:-true}
45
46 # example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G"
47 storage_params=""
48 if [ -n "$DOCKER_STORAGE_OPTS" ]; then
49 IFS=','
50 for i in ${DOCKER_STORAGE_OPTS}; do
51 storage_params="--storage-opt $i $storage_params"
52 done
53 unset IFS
54 fi
55
56 # example usage: DOCKER_REMAP_ROOT=default
57 extra_params=""
58 if [ "$DOCKER_REMAP_ROOT" ]; then
59 extra_params="--userns-remap $DOCKER_REMAP_ROOT"
60 fi
61
62 # example usage: DOCKER_EXPERIMENTAL=1
63 if [ "$DOCKER_EXPERIMENTAL" ]; then
64 echo >&2 '# DOCKER_EXPERIMENTAL is set: starting daemon with experimental features enabled! '
65 extra_params="$extra_params --experimental"
66 fi
67
68 dockerd="dockerd"
69
70 if [ -n "$DOCKER_ROOTLESS" ]; then
71 if [ -z "$TEST_SKIP_INTEGRATION_CLI" ]; then
72 echo >&2 '# DOCKER_ROOTLESS requires TEST_SKIP_INTEGRATION_CLI to be set'
73 exit 1
74 fi
75 user="unprivilegeduser"
76 uid=$(id -u $user)
77 # shellcheck disable=SC2174
78 mkdir -p -m 700 "/tmp/docker-${uid}"
79 chown "$user" "/tmp/docker-${uid}"
80 chmod -R o+w "$DEST"
81 # The rootless daemon won't be able to load modules for tests that need them, so do it here.
82 # There's no modprobe in the dev container, so https://x.com/lucabruno/status/902934379835662336
83 ip link show br_netfilter || true
84 dockerd="sudo -u $user -E -E XDG_RUNTIME_DIR=/tmp/docker-${uid} -E HOME=/home/${user} -E PATH=$PATH -- dockerd-rootless.sh"
85 fi
86
87 if [ -z "$DOCKER_TEST_HOST" ]; then
88 # Start apparmor if it is enabled
89 if [ -e "/sys/module/apparmor/parameters/enabled" ] && [ "$(cat /sys/module/apparmor/parameters/enabled)" == "Y" ]; then
90 # reset container variable so apparmor profile is applied to process
91 # see https://github.com/docker/libcontainer/blob/master/apparmor/apparmor.go#L16
92 export container=""
93 (
94 [ -n "$TESTDEBUG" ] && set -x
95 /etc/init.d/apparmor start
96 )
97 fi
98
99 if [ -n "${DOCKER_ROOTLESS}" ]; then
100 # "pwd" tricks to make sure $DEST is an absolute path, not a relative one
101 export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock"
102 else
103 # Put socket in /run because:
104 # 1. That's the normal place for such things
105 # 2. When running on Docker For Mac, if you need to run tests with the bundles dir mounted (e.g. to poke through test artifacts).
106 # the socket will not work because it will be over osxfs.
107 mkdir -p /run/docker
108 sock_dir=$(mktemp -d -p /run/docker)
109 chmod 0755 "$sock_dir"
110 export DOCKER_HOST="unix://${sock_dir}/docker.sock"
111 fi
112 (
113 echo "Starting dockerd"
114 [ -n "$TESTDEBUG" ] && set -x
115 exec \
116 ${dockerd} --debug \
117 --host "$DOCKER_HOST" \
118 --storage-driver "$DOCKER_GRAPHDRIVER" \
119 --pidfile "$DEST/docker.pid" \
120 --userland-proxy="$DOCKER_USERLANDPROXY" \
121 ${storage_params} \
122 ${extra_params} \
123 &> "$DEST/docker.log"
124 ) &
125 else
126 export DOCKER_HOST="$DOCKER_TEST_HOST"
127 fi
128
129 # give it a little time to come up so it's "ready"
130 tries=60
131 echo "INFO: Waiting for daemon to start..."
132 while ! ${TEST_CLIENT_BINARY} version &> /dev/null; do
133 ((tries--))
134 if [ $tries -le 0 ]; then
135 printf "\n"
136 if [ -z "$DOCKER_HOST" ]; then
137 echo >&2 "error: daemon failed to start"
138 echo >&2 " check $DEST/docker.log for details"
139 else
140 echo >&2 "error: daemon at $DOCKER_HOST fails to '$TEST_CLIENT_BINARY version':"
141 ${TEST_CLIENT_BINARY} version >&2 || true
142 # Additional Windows CI debugging as this is a common error as of
143 # January 2016
144 if [ "$(go env GOOS)" = 'windows' ]; then
145 echo >&2 "Container log below:"
146 echo >&2 "---"
147 # Important - use the docker on the CI host, not the one built locally
148 # which is currently in our path.
149 ! /c/bin/docker -H=$MAIN_DOCKER_HOST logs docker-$COMMITHASH
150 echo >&2 "---"
151 fi
152 fi
153 false
154 fi
155 printf "."
156 sleep 2
157 done
158 printf "\n"