.integration-daemon-start 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/bin/env bash
  2. # see test-integration for example usage of this script
  3. base="$ABS_DEST/.."
  4. export PATH="$base/binary-daemon:$base/dynbinary-daemon:$PATH"
  5. export TEST_CLIENT_BINARY=docker
  6. # Do not bump this version! Integration tests should no longer rely on the docker cli, they should be
  7. # API tests instead. For the existing tests the scripts will use a frozen version of the docker cli
  8. # with a DOCKER_API_VERSION frozen to 1.30, which should ensure that the CI remains green at all times.
  9. export DOCKER_API_VERSION=1.30
  10. if [ -n "$DOCKER_CLI_PATH" ]; then
  11. export TEST_CLIENT_BINARY=/usr/local/cli/$(basename "$DOCKER_CLI_PATH")
  12. fi
  13. echo "Using test binary $TEST_CLIENT_BINARY"
  14. if ! command -v "$TEST_CLIENT_BINARY" &> /dev/null; then
  15. echo >&2 'error: missing test client $TEST_CLIENT_BINARY'
  16. false
  17. fi
  18. # This is a temporary hack for split-binary mode. It can be removed once
  19. # https://github.com/docker/docker/pull/22134 is merged into docker master
  20. if [ "$(go env GOOS)" = 'windows' ]; then
  21. return
  22. fi
  23. if [ -z "$DOCKER_TEST_HOST" ]; then
  24. if docker version &> /dev/null; then
  25. echo >&2 'skipping daemon start, since daemon appears to be already started'
  26. return
  27. fi
  28. fi
  29. if ! command -v dockerd &> /dev/null; then
  30. echo >&2 'error: binary-daemon or dynbinary-daemon must be run before .integration-daemon-start'
  31. false
  32. fi
  33. # intentionally open a couple bogus file descriptors to help test that they get scrubbed in containers
  34. exec 41>&1 42>&2
  35. export DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-vfs}
  36. export DOCKER_USERLANDPROXY=${DOCKER_USERLANDPROXY:-true}
  37. # example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G"
  38. storage_params=""
  39. if [ -n "$DOCKER_STORAGE_OPTS" ]; then
  40. IFS=','
  41. for i in ${DOCKER_STORAGE_OPTS}; do
  42. storage_params="--storage-opt $i $storage_params"
  43. done
  44. unset IFS
  45. fi
  46. # example usage: DOCKER_REMAP_ROOT=default
  47. extra_params=""
  48. if [ "$DOCKER_REMAP_ROOT" ]; then
  49. extra_params="--userns-remap $DOCKER_REMAP_ROOT"
  50. fi
  51. # example usage: DOCKER_EXPERIMENTAL=1
  52. if [ "$DOCKER_EXPERIMENTAL" ]; then
  53. echo >&2 '# DOCKER_EXPERIMENTAL is set: starting daemon with experimental features enabled! '
  54. extra_params="$extra_params --experimental"
  55. fi
  56. if [ -z "$DOCKER_TEST_HOST" ]; then
  57. # Start apparmor if it is enabled
  58. if [ -e "/sys/module/apparmor/parameters/enabled" ] && [ "$(cat /sys/module/apparmor/parameters/enabled)" == "Y" ]; then
  59. # reset container variable so apparmor profile is applied to process
  60. # see https://github.com/docker/libcontainer/blob/master/apparmor/apparmor.go#L16
  61. export container=""
  62. (
  63. [ -n "$TESTDEBUG" ] && set -x
  64. /etc/init.d/apparmor start
  65. )
  66. fi
  67. # "pwd" tricks to make sure $DEST is an absolute path, not a relative one
  68. export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock"
  69. (
  70. echo "Starting dockerd"
  71. [ -n "$TESTDEBUG" ] && set -x
  72. exec \
  73. dockerd --debug \
  74. --host "$DOCKER_HOST" \
  75. --storage-driver "$DOCKER_GRAPHDRIVER" \
  76. --pidfile "$DEST/docker.pid" \
  77. --userland-proxy="$DOCKER_USERLANDPROXY" \
  78. $storage_params \
  79. $extra_params \
  80. &> "$DEST/docker.log"
  81. ) &
  82. else
  83. export DOCKER_HOST="$DOCKER_TEST_HOST"
  84. fi
  85. # give it a little time to come up so it's "ready"
  86. tries=60
  87. echo "INFO: Waiting for daemon to start..."
  88. while ! $TEST_CLIENT_BINARY version &> /dev/null; do
  89. (( tries-- ))
  90. if [ $tries -le 0 ]; then
  91. printf "\n"
  92. if [ -z "$DOCKER_HOST" ]; then
  93. echo >&2 "error: daemon failed to start"
  94. echo >&2 " check $DEST/docker.log for details"
  95. else
  96. echo >&2 "error: daemon at $DOCKER_HOST fails to '$TEST_CLIENT_BINARY version':"
  97. $TEST_CLIENT_BINARY version >&2 || true
  98. # Additional Windows CI debugging as this is a common error as of
  99. # January 2016
  100. if [ "$(go env GOOS)" = 'windows' ]; then
  101. echo >&2 "Container log below:"
  102. echo >&2 "---"
  103. # Important - use the docker on the CI host, not the one built locally
  104. # which is currently in our path.
  105. ! /c/bin/docker -H=$MAIN_DOCKER_HOST logs docker-$COMMITHASH
  106. echo >&2 "---"
  107. fi
  108. fi
  109. false
  110. fi
  111. printf "."
  112. sleep 2
  113. done
  114. printf "\n"