github.com/afbjorklund/moby@v20.10.5+incompatible/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/docker/docker/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  # Allow pushing manifest v2 schema 1 images, as they're used to push
    42  # images to our test-registries for testing _pulling_ schema 2v1 images.
    43  export DOCKER_ALLOW_SCHEMA1_PUSH_DONOTUSE=1
    44  export DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-vfs}
    45  export DOCKER_USERLANDPROXY=${DOCKER_USERLANDPROXY:-true}
    46  
    47  # example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G"
    48  storage_params=""
    49  if [ -n "$DOCKER_STORAGE_OPTS" ]; then
    50  	IFS=','
    51  	for i in ${DOCKER_STORAGE_OPTS}; do
    52  		storage_params="--storage-opt $i $storage_params"
    53  	done
    54  	unset IFS
    55  fi
    56  
    57  # example usage: DOCKER_REMAP_ROOT=default
    58  extra_params=""
    59  if [ "$DOCKER_REMAP_ROOT" ]; then
    60  	extra_params="--userns-remap $DOCKER_REMAP_ROOT"
    61  fi
    62  
    63  # example usage: DOCKER_EXPERIMENTAL=1
    64  if [ "$DOCKER_EXPERIMENTAL" ]; then
    65  	echo >&2 '# DOCKER_EXPERIMENTAL is set: starting daemon with experimental features enabled! '
    66  	extra_params="$extra_params --experimental"
    67  fi
    68  
    69  dockerd="dockerd"
    70  if [ -f "/sys/fs/cgroup/cgroup.controllers" ]; then
    71  	if [ -z "$TEST_SKIP_INTEGRATION_CLI" ]; then
    72  		echo >&2 '# cgroup v2 requires TEST_SKIP_INTEGRATION_CLI to be set'
    73  		exit 1
    74  	fi
    75  fi
    76  
    77  if [ -n "$DOCKER_ROOTLESS" ]; then
    78  	if [ -z "$TEST_SKIP_INTEGRATION_CLI" ]; then
    79  		echo >&2 '# DOCKER_ROOTLESS requires TEST_SKIP_INTEGRATION_CLI to be set'
    80  		exit 1
    81  	fi
    82  	ln -sf "$(command -v vpnkit."$(uname -m)")" /usr/local/bin/vpnkit
    83  	user="unprivilegeduser"
    84  	uid=$(id -u $user)
    85  	# shellcheck disable=SC2174
    86  	mkdir -p -m 700 "/tmp/docker-${uid}"
    87  	chown "$user" "/tmp/docker-${uid}"
    88  	chmod -R o+w "$DEST"
    89  	dockerd="sudo -u $user -E -E XDG_RUNTIME_DIR=/tmp/docker-${uid} -E HOME=/home/${user} -E PATH=$PATH -- dockerd-rootless.sh"
    90  fi
    91  
    92  if [ -z "$DOCKER_TEST_HOST" ]; then
    93  	# Start apparmor if it is enabled
    94  	if [ -e "/sys/module/apparmor/parameters/enabled" ] && [ "$(cat /sys/module/apparmor/parameters/enabled)" == "Y" ]; then
    95  		# reset container variable so apparmor profile is applied to process
    96  		# see https://github.com/docker/libcontainer/blob/master/apparmor/apparmor.go#L16
    97  		export container=""
    98  		(
    99  			[ -n "$TESTDEBUG" ] && set -x
   100  			/etc/init.d/apparmor start
   101  		)
   102  	fi
   103  
   104  	# "pwd" tricks to make sure $DEST is an absolute path, not a relative one
   105  	export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock"
   106  	(
   107  		echo "Starting dockerd"
   108  		[ -n "$TESTDEBUG" ] && set -x
   109  		exec \
   110  			${dockerd} --debug \
   111  			--host "$DOCKER_HOST" \
   112  			--storage-driver "$DOCKER_GRAPHDRIVER" \
   113  			--pidfile "$DEST/docker.pid" \
   114  			--userland-proxy="$DOCKER_USERLANDPROXY" \
   115  			${storage_params} \
   116  			${extra_params} \
   117  			&> "$DEST/docker.log"
   118  	) &
   119  else
   120  	export DOCKER_HOST="$DOCKER_TEST_HOST"
   121  fi
   122  
   123  # give it a little time to come up so it's "ready"
   124  tries=60
   125  echo "INFO: Waiting for daemon to start..."
   126  while ! ${TEST_CLIENT_BINARY} version &> /dev/null; do
   127  	((tries--))
   128  	if [ $tries -le 0 ]; then
   129  		printf "\n"
   130  		if [ -z "$DOCKER_HOST" ]; then
   131  			echo >&2 "error: daemon failed to start"
   132  			echo >&2 "  check $DEST/docker.log for details"
   133  		else
   134  			echo >&2 "error: daemon at $DOCKER_HOST fails to '$TEST_CLIENT_BINARY version':"
   135  			${TEST_CLIENT_BINARY} version >&2 || true
   136  			# Additional Windows CI debugging as this is a common error as of
   137  			# January 2016
   138  			if [ "$(go env GOOS)" = 'windows' ]; then
   139  				echo >&2 "Container log below:"
   140  				echo >&2 "---"
   141  				# Important - use the docker on the CI host, not the one built locally
   142  				# which is currently in our path.
   143  				! /c/bin/docker -H=$MAIN_DOCKER_HOST logs docker-$COMMITHASH
   144  				echo >&2 "---"
   145  			fi
   146  		fi
   147  		false
   148  	fi
   149  	printf "."
   150  	sleep 2
   151  done
   152  printf "\n"