This repository has been archived by the owner on Dec 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cfn_build_node.sh
executable file
·74 lines (58 loc) · 2.11 KB
/
cfn_build_node.sh
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
#!/usr/bin/env bash
if [[ ${NODE_VERSION:-false} == false ]]; then
echo '${NODE_VERSION}' must be defined
exit 1
fi
NAME=${NAME:-""}
TRAVIS_JOB_ID=${TRAVIS_JOB_ID:-"localdev"}
COMMIT_MESSAGE=${COMMIT_MESSAGE:-"commit"}
GithubAccessToken=${GithubAccessToken:-"dummy"}
if [[ $NAME != "" ]]; then
S3_URL=${S3_URL}/${NAME}
fi
set -e -u
TMP=$(mktemp -d -t node-cpp11.XXXX )
CWD=$(pwd)
ConfigJSON="$TMP/$TRAVIS_JOB_ID-cfn.json"
UserData=$(node -e "
var userdata = '';
userdata += 'set NODE_VERSION=$NODE_VERSION\n';
userdata += 'set NAME=$NAME\n';
userdata += 'set S3_URL=$S3_URL\n;'
userdata += 'set BRANCH=$BRANCH\n';
userdata += 'set REPO=$REPO\n';
userdata += 'set AWS_ACCESS_KEY_ID=$BUILD_AWS_ACCESS_KEY_ID\n';
userdata += 'set AWS_SECRET_ACCESS_KEY=$BUILD_AWS_SECRET_ACCESS_KEY\n';
userdata += require('fs').readFileSync('$(dirname $0)/cfn_build_node.userdata.bat','utf8');
console.log(JSON.stringify(userdata));
")
echo "{
\"OS\": \"win2012-vs2015\",
\"InstanceType\": \"c3.4xlarge\",
\"GithubAccessToken\": \"$GithubAccessToken\",
\"UserData\": $UserData
}" >> $ConfigJSON
cd $TMP
# install node
mkdir -p $TMP
export PATH=$PATH:$TMP/bin
curl -s https://s3.amazonaws.com/mapbox/apps/install-node/v0.2.0/run | NV=0.10.33 NP=linux OD=$TMP sh
# install cfn-ci + cfn-config
npm install https://github.com/mapbox/cfn-ci/tarball/windows
npm install [email protected]
# create cfn stack for building
timeout 5000 $TMP/node_modules/.bin/cfn-create -f -r us-east-1 -n "travis-node-cpp11-$TRAVIS_JOB_ID" -t $TMP/node_modules/cfn-ci/cfn-win.template -c $ConfigJSON || echo "cfn-create failed, cleaning up ..." &
# Node builds can take a long time.
# Output for travis to chew on to avoid 10 min "no output" timeout.
while [ $(jobs | grep -v Done | grep cfn-create | wc -l) -gt 0 ]; do
sleep 60
echo " ..."
done
wait
if echo "$COMMIT_MESSAGE" | grep '\[publish debug\]' > /dev/null; then
echo "Commit includes [publish debug] skipping stack teardown."
else
$TMP/node_modules/.bin/cfn-delete -f -r us-east-1 -n "travis-node-cpp11-$TRAVIS_JOB_ID"
fi
cd $CWD
rm -rf $TMP