docker.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/bin/bash
  2. #set -e
  3. test_node_versions="0.8.28 0.10.40 0.12.7 4.3.0 5.6.0"
  4. test_iojs_versions="1.8.4 2.4.0 3.3.0"
  5. myuid=$(id -u)
  6. mygid=$(id -g)
  7. __dirname="$(CDPATH= cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  8. dot_node_gyp=${__dirname}/.node-gyp/
  9. # borrows from https://github.com/rvagg/dnt/
  10. # Simple setup function for a container:
  11. # setup_container(image id, base image, commands to run to set up)
  12. setup_container() {
  13. local container_id="$1"
  14. local base_container="$2"
  15. local run_cmd="$3"
  16. # Does this image exist? If yes, ignore
  17. docker inspect "$container_id" &> /dev/null
  18. if [[ $? -eq 0 ]]; then
  19. echo "Found existing container [$container_id]"
  20. else
  21. # No such image, so make it
  22. echo "Did not find container [$container_id], creating..."
  23. docker run -i $base_container /bin/bash -c "$run_cmd"
  24. sleep 2
  25. docker commit $(docker ps -l -q) $container_id
  26. fi
  27. }
  28. # Run tests inside each of the versioned containers, copy cwd into npm's copy of node-gyp
  29. # so it'll be invoked by npm when a compile is needed
  30. # run_tests(version, test-commands)
  31. run_tests() {
  32. local version="$1"
  33. local run_cmd="$2"
  34. run_cmd="rsync -aAXx --delete --exclude .git --exclude build /node-gyp-src/ /usr/lib/node_modules/npm/node_modules/node-gyp/;
  35. /bin/su -s /bin/bash node-gyp -c 'cd && ${run_cmd}'"
  36. rm -rf $dot_node_gyp
  37. mkdir $dot_node_gyp
  38. docker run \
  39. --rm -i \
  40. -v ~/.npm/:/node-gyp/.npm/ \
  41. -v ${dot_node_gyp}:/node-gyp/.node-gyp/ \
  42. -v $(pwd):/node-gyp-src/:ro \
  43. node-gyp-test/${version} /bin/bash -c "${run_cmd}"
  44. }
  45. # A base image with build tools and a user account
  46. setup_container "node-gyp-test/base" "ubuntu:14.04" "
  47. adduser --gecos node-gyp --home /node-gyp/ --disabled-login node-gyp --uid $myuid &&
  48. echo "node-gyp:node-gyp" | chpasswd &&
  49. apt-get update &&
  50. apt-get install -y build-essential python git rsync curl
  51. "
  52. # An image on top of the base containing clones of repos we want to use for testing
  53. setup_container "node-gyp-test/clones" "node-gyp-test/base" "
  54. cd /node-gyp/ && git clone https://github.com/justmoon/node-bignum.git &&
  55. cd /node-gyp/ && git clone https://github.com/bnoordhuis/node-buffertools.git &&
  56. chown -R node-gyp.node-gyp /node-gyp/
  57. "
  58. # An image for each of the node versions we want to test with that version installed and the latest npm
  59. for v in $test_node_versions; do
  60. setup_container "node-gyp-test/${v}" "node-gyp-test/clones" "
  61. curl -sL https://nodejs.org/dist/v${v}/node-v${v}-linux-x64.tar.gz | tar -zxv --strip-components=1 -C /usr/ &&
  62. npm install npm@latest -g &&
  63. node -v && npm -v
  64. "
  65. done
  66. # An image for each of the io.js versions we want to test with that version installed and the latest npm
  67. for v in $test_iojs_versions; do
  68. setup_container "node-gyp-test/${v}" "node-gyp-test/clones" "
  69. curl -sL https://iojs.org/dist/v${v}/iojs-v${v}-linux-x64.tar.gz | tar -zxv --strip-components=1 -C /usr/ &&
  70. npm install npm@latest -g &&
  71. node -v && npm -v
  72. "
  73. done
  74. # Run the tests for all of the test images we've created,
  75. # we should see node-gyp doing its download, configure and run thing
  76. # _NOTE: bignum doesn't compile on 0.8 currently so it'll fail for that version only_
  77. for v in $test_node_versions $test_iojs_versions; do
  78. run_tests $v "
  79. cd node-buffertools && npm install --loglevel=info && npm test && cd
  80. "
  81. # removed for now, too noisy: cd node-bignum && npm install --loglevel=info && npm test
  82. done
  83. # Test use of --target=x.y.z to compile against alternate versions
  84. test_download_node_version() {
  85. local run_with_ver="$1"
  86. local expected_dir="$2"
  87. local expected_ver="$3"
  88. run_tests $run_with_ver "cd node-buffertools && npm install --loglevel=info --target=${expected_ver}"
  89. local node_ver=$(cat "${dot_node_gyp}${expected_dir}/node_version.h" | grep '#define NODE_\w*_VERSION [0-9]*$')
  90. node_ver=$(echo $node_ver | sed 's/#define NODE_[A-Z]*_VERSION //g' | sed 's/ /./g')
  91. if [ "X$(echo $node_ver)" != "X${expected_ver}" ]; then
  92. echo "Did not download v${expected_ver} using --target, instead got: $(echo $node_ver)"
  93. exit 1
  94. fi
  95. echo "Verified correct download of [v${node_ver}]"
  96. }
  97. test_download_node_version "0.12.7" "0.10.30/src" "0.10.30"
  98. test_download_node_version "3.3.0" "iojs-1.8.4/src" "1.8.4"
  99. # should download the headers file
  100. test_download_node_version "3.3.0" "iojs-3.3.0/include/node" "3.3.0"
  101. test_download_node_version "4.3.0" "4.3.0/include/node" "4.3.0"
  102. test_download_node_version "5.6.0" "5.6.0/include/node" "5.6.0"
  103. # TODO: test --dist-url by starting up a localhost server and serving up tarballs
  104. # testing --dist-url, using simple-proxy.js to make localhost work as a distribution
  105. # point for tarballs
  106. # we can test whether it uses the proxy because after 2 connections the proxy will
  107. # die and therefore should not be running at the end of the test, `nc` can tell us this
  108. run_tests "3.3.0" "
  109. (node /node-gyp-src/test/simple-proxy.js 8080 /foobar/ https://iojs.org/dist/ &) &&
  110. cd node-buffertools &&
  111. /node-gyp-src/bin/node-gyp.js --loglevel=info --dist-url=http://localhost:8080/foobar/ rebuild &&
  112. nc -z localhost 8080 && echo -e \"\\n\\n\\033[31mFAILED TO USE LOCAL PROXY\\033[39m\\n\\n\"
  113. "
  114. # REMOVE after next semver-major
  115. run_tests "3.3.0" "
  116. (node /node-gyp-src/test/simple-proxy.js 8080 /doobar/ https://iojs.org/dist/ &) &&
  117. cd node-buffertools &&
  118. NVM_IOJS_ORG_MIRROR=http://localhost:8080/doobar/ /node-gyp-src/bin/node-gyp.js --loglevel=info rebuild &&
  119. nc -z localhost 8080 && echo -e \"\\n\\n\\033[31mFAILED TO USE LOCAL PROXY\\033[39m\\n\\n\"
  120. "
  121. # REMOVE after next semver-major
  122. run_tests "0.12.7" "
  123. (node /node-gyp-src/test/simple-proxy.js 8080 /boombar/ https://nodejs.org/dist/ &) &&
  124. cd node-buffertools &&
  125. NVM_NODEJS_ORG_MIRROR=http://localhost:8080/boombar/ /node-gyp-src/bin/node-gyp.js --loglevel=info rebuild &&
  126. nc -z localhost 8080 && echo -e \"\\n\\n\\033[31mFAILED TO USE LOCAL PROXY\\033[39m\\n\\n\"
  127. "
  128. run_tests "3.3.0" "
  129. (node /node-gyp-src/test/simple-proxy.js 8080 /doobar/ https://iojs.org/dist/ &) &&
  130. cd node-buffertools &&
  131. IOJS_ORG_MIRROR=http://localhost:8080/doobar/ /node-gyp-src/bin/node-gyp.js --loglevel=info rebuild &&
  132. nc -z localhost 8080 && echo -e \"\\n\\n\\033[31mFAILED TO USE LOCAL PROXY\\033[39m\\n\\n\"
  133. "
  134. run_tests "0.12.7" "
  135. (node /node-gyp-src/test/simple-proxy.js 8080 /boombar/ https://nodejs.org/dist/ &) &&
  136. cd node-buffertools &&
  137. NODEJS_ORG_MIRROR=http://localhost:8080/boombar/ /node-gyp-src/bin/node-gyp.js --loglevel=info rebuild &&
  138. nc -z localhost 8080 && echo -e \"\\n\\n\\033[31mFAILED TO USE LOCAL PROXY\\033[39m\\n\\n\"
  139. "
  140. rm -rf $dot_node_gyp