Welcome to mirror list, hosted at ThFree Co, Russian Federation.

docker.sh « test « node-gyp « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 67014209d000385e57dee181857dc5aabb221479 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash

#set -e

test_node_versions="6.17.0 8.15.1 10.15.3 11.12.0"

myuid=$(id -u)
mygid=$(id -g)
__dirname="$(CDPATH= cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
dot_node_gyp=${__dirname}/.node-gyp/

# borrows from https://github.com/rvagg/dnt/

# Simple setup function for a container:
#  setup_container(image id, base image, commands to run to set up)
setup_container() {
  local container_id="$1"
  local base_container="$2"
  local run_cmd="$3"

  # Does this image exist? If yes, ignore
  docker inspect "$container_id" &> /dev/null
  if [[ $? -eq 0 ]]; then
    echo "Found existing container [$container_id]"
  else
    # No such image, so make it
    echo "Did not find container [$container_id], creating..."
    docker run -i $base_container /bin/bash -c "$run_cmd"
    sleep 2
    docker commit $(docker ps -l -q) $container_id
  fi
}

# Run tests inside each of the versioned containers, copy cwd into npm's copy of node-gyp
# so it'll be invoked by npm when a compile is needed
#  run_tests(version, test-commands)
run_tests() {
  local version="$1"
  local run_cmd="$2"

  run_cmd="rsync -aAXx --delete --exclude .git --exclude build /node-gyp-src/ /usr/lib/node_modules/npm/node_modules/node-gyp/;
    /bin/su -s /bin/bash node-gyp -c 'cd && ${run_cmd}'"

  rm -rf $dot_node_gyp
  mkdir $dot_node_gyp

  docker run \
    --rm -i \
    -v ~/.npm/:/node-gyp/.npm/ \
    -v ${dot_node_gyp}:/node-gyp/.node-gyp/ \
    -v $(pwd):/node-gyp-src/:ro \
    node-gyp-test/${version} /bin/bash -c "${run_cmd}"
}

# A base image with build tools and a user account
setup_container "node-gyp-test/base" "ubuntu:14.04" "
  adduser --gecos node-gyp --home /node-gyp/ --disabled-login node-gyp --uid $myuid &&
  echo "node-gyp:node-gyp" | chpasswd &&
  apt-get update &&
  apt-get install -y build-essential python git rsync curl
"

# An image on top of the base containing clones of repos we want to use for testing
setup_container "node-gyp-test/clones" "node-gyp-test/base" "
  cd /node-gyp/ && git clone https://github.com/justmoon/node-bignum.git &&
  cd /node-gyp/ && git clone https://github.com/bnoordhuis/node-buffertools.git &&
  chown -R node-gyp.node-gyp /node-gyp/
"

# An image for each of the node versions we want to test with that version installed and the latest npm
for v in $test_node_versions; do
  setup_container "node-gyp-test/${v}" "node-gyp-test/clones" "
    curl -sL https://nodejs.org/dist/v${v}/node-v${v}-linux-x64.tar.gz | tar -zxv --strip-components=1 -C /usr/ &&
    npm install npm@latest -g &&
    node -v && npm -v
  "
done

# Test use of --target=x.y.z to compile against alternate versions
test_download_node_version() {
  local run_with_ver="$1"
  local expected_dir="$2"
  local expected_ver="$3"
  run_tests $run_with_ver "cd node-buffertools && npm install --loglevel=info --target=${expected_ver}"
  local node_ver=$(cat "${dot_node_gyp}${expected_dir}/node_version.h" | grep '#define NODE_\w*_VERSION [0-9]*$')
  node_ver=$(echo $node_ver | sed 's/#define NODE_[A-Z]*_VERSION //g' | sed 's/ /./g')
  if [ "X$(echo $node_ver)" != "X${expected_ver}" ]; then
    echo "Did not download v${expected_ver} using --target, instead got: $(echo $node_ver)"
    exit 1
  fi
  echo "Verified correct download of [v${node_ver}]"
}

test_download_node_version "0.12.7" "0.10.30/src" "0.10.30"
# should download the headers file
test_download_node_version "4.3.0" "4.3.0/include/node" "4.3.0"
test_download_node_version "5.6.0" "5.6.0/include/node" "5.6.0"

# TODO: test --dist-url by starting up a localhost server and serving up tarballs

# testing --dist-url, using simple-proxy.js to make localhost work as a distribution
# point for tarballs
# we can test whether it uses the proxy because after 2 connections the proxy will
# die and therefore should not be running at the end of the test, `nc` can tell us this
run_tests "0.12.7" "
  (node /node-gyp-src/test/simple-proxy.js 8080 /boombar/ https://nodejs.org/dist/ &) &&
  cd node-buffertools &&
  NODEJS_ORG_MIRROR=http://localhost:8080/boombar/ /node-gyp-src/bin/node-gyp.js --loglevel=info rebuild &&
  nc -z localhost 8080 && echo -e \"\\n\\n\\033[31mFAILED TO USE LOCAL PROXY\\033[39m\\n\\n\"
"

rm -rf $dot_node_gyp