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