Skip to content
Newer
Older
100755 110 lines (87 sloc) 2.77 KB
8cfdd96 @ddollar init
ddollar authored May 18, 2011
1 #!/usr/bin/env bash
2 # bin/compile <build-dir> <cache-dir>
3
b68e8ef @ddollar first pass at vendoring on s3
ddollar authored Sep 16, 2011
4 mktmpdir() {
5 dir=$(mktemp -t node-$1-XXXX)
6 rm -rf $dir
7 mkdir -p $dir
8 echo $dir
9 }
10
e95624e @ddollar make indent an os-indepdent routine
ddollar authored Sep 23, 2011
11 function indent() {
12 c='s/^/ /'
13 case $(uname) in
14 Darwin) sed -l "$c";;
15 *) sed -u "$c";;
16 esac
17 }
18
df91075 @ddollar try new approach for node_modules cache
ddollar authored Jan 12, 2012
19 run_npm() {
20 command="$1"
21 HOME="$BUILD_DIR" $VENDORED_NODE/bin/node $VENDORED_NPM/cli.js $command 2>&1 | indent
22
23 if [ "${PIPESTATUS[*]}" != "0 0" ]; then
24 echo " ! Failed to $command dependencies with npm"
25 exit 1
26 fi
27 }
28
404494b @ddollar fix leaking GIT_DIR
ddollar authored Jan 10, 2012
29 # clean up leaking environment
30 unset GIT_DIR
31
8cfdd96 @ddollar init
ddollar authored May 18, 2011
32 # config
e2f391e @liquid Upgrades Node to version 0.6.13
authored Mar 15, 2012
33 NODE_VERSION="0.6.13"
693ceaa @liquid Upgrade NPM to version 1.1.0-2.
authored Jan 21, 2012
34 NPM_VERSION="1.1.0-2"
d994d99 @ddollar vendor scons
ddollar authored Jun 2, 2011
35 SCONS_VERSION="1.2.0"
f13ad4d @liquid Updates S3 bucket name.
authored Dec 2, 2011
36 S3_BUCKET="eclm-heroku-buildpack"
8cfdd96 @ddollar init
ddollar authored May 18, 2011
37
38 # parse and derive params
39 BUILD_DIR=$1
40 CACHE_DIR=$2
41 LP_DIR=`cd $(dirname $0); cd ..; pwd`
66cdced @ddollar debug
ddollar authored Jan 12, 2012
42 CACHE_STORE_DIR="$CACHE_DIR/node_modules/$NPM_VERSION"
43 CACHE_TARGET_DIR="$BUILD_DIR/node_modules"
8cfdd96 @ddollar init
ddollar authored May 18, 2011
44
b68e8ef @ddollar first pass at vendoring on s3
ddollar authored Sep 16, 2011
45 # s3 packages
c959174 @ddollar clean up aws config env vars
ddollar authored Oct 12, 2011
46 NODE_PACKAGE="http://${S3_BUCKET}.s3.amazonaws.com/nodejs-${NODE_VERSION}.tgz"
47 NPM_PACKAGE="http://${S3_BUCKET}.s3.amazonaws.com/npm-${NPM_VERSION}.tgz"
48 SCONS_PACKAGE="http://${S3_BUCKET}.s3.amazonaws.com/scons-${SCONS_VERSION}.tgz"
b68e8ef @ddollar first pass at vendoring on s3
ddollar authored Sep 16, 2011
49
8cfdd96 @ddollar init
ddollar authored May 18, 2011
50 # vendor directories
b68e8ef @ddollar first pass at vendoring on s3
ddollar authored Sep 16, 2011
51 VENDORED_NODE="$(mktmpdir node)"
52 VENDORED_NPM="$(mktmpdir npm)"
53 VENDORED_SCONS="$(mktmpdir scons)"
54
55 # download and unpack packages
56 echo "-----> Fetching Node.js binaries"
57 mkdir -p $VENDORED_NODE && curl $NODE_PACKAGE -s -o - | tar xzf - -C $VENDORED_NODE
58 mkdir -p $VENDORED_NPM && curl $NPM_PACKAGE -s -o - | tar xzf - -C $VENDORED_NPM
59 mkdir -p $VENDORED_SCONS && curl $SCONS_PACKAGE -s -o - | tar xzf - -C $VENDORED_SCONS
8cfdd96 @ddollar init
ddollar authored May 18, 2011
60
cfbd4c0 @ddollar more descriptive
ddollar authored Sep 16, 2011
61 # vendor node into the slug
8cfdd96 @ddollar init
ddollar authored May 18, 2011
62 PATH="$BUILD_DIR/bin:$PATH"
63 echo "-----> Vendoring node $NODE_VERSION"
64 mkdir -p "$BUILD_DIR/bin"
b68e8ef @ddollar first pass at vendoring on s3
ddollar authored Sep 16, 2011
65 cp "$VENDORED_NODE/bin/node" "$BUILD_DIR/bin/node"
8cfdd96 @ddollar init
ddollar authored May 18, 2011
66
d994d99 @ddollar vendor scons
ddollar authored Jun 2, 2011
67 # setting up paths for building
b68e8ef @ddollar first pass at vendoring on s3
ddollar authored Sep 16, 2011
68 PATH="$VENDORED_SCONS:$VENDORED_NODE/bin:$PATH"
6a0dbfb @ddollar try both paths
ddollar authored Jun 2, 2011
69 INCLUDE_PATH="$VENDORED_NODE/include"
70 export CPATH="$INCLUDE_PATH"
71 export CPPPATH="$INCLUDE_PATH"
d994d99 @ddollar vendor scons
ddollar authored Jun 2, 2011
72
8cfdd96 @ddollar init
ddollar authored May 18, 2011
73 # unpack existing cache
74 if [ -d $CACHE_STORE_DIR ]; then
df91075 @ddollar try new approach for node_modules cache
ddollar authored Jan 13, 2012
75
4743894 @ddollar remove debug
ddollar authored Jan 12, 2012
76 # generate a place to put node_modules
df91075 @ddollar try new approach for node_modules cache
ddollar authored Jan 13, 2012
77 TEMP_NODE_MODULES_DIR=$(mktmpdir node_modules)
78
79 # move existing node_modules out of the way
66cdced @ddollar debug
ddollar authored Jan 13, 2012
80 if [ -d $CACHE_TARGET_DIR ]; then
df91075 @ddollar try new approach for node_modules cache
ddollar authored Jan 13, 2012
81 mv $CACHE_TARGET_DIR $TEMP_NODE_MODULES_DIR/
82 fi
83
4743894 @ddollar remove debug
ddollar authored Jan 13, 2012
84 # copy the cached node_modules in
aa480b1 @ddollar better npm support
ddollar authored Jan 11, 2012
85 mkdir -p $CACHE_TARGET_DIR
86 cp -R $CACHE_STORE_DIR/* $CACHE_TARGET_DIR/
df91075 @ddollar try new approach for node_modules cache
ddollar authored Jan 13, 2012
87
88 # move existing node_modules back into place
89 if [ -d $TEMP_NODE_MODULES_DIR/node_modules ]; then
90 cp -R $TEMP_NODE_MODULES_DIR/node_modules/* $CACHE_TARGET_DIR/
91 fi
4743894 @ddollar remove debug
ddollar authored Jan 13, 2012
92
8cfdd96 @ddollar init
ddollar authored May 18, 2011
93 fi
94
95 # install dependencies with npm
96 echo "-----> Installing dependencies with npm $NPM_VERSION"
aa480b1 @ddollar better npm support
ddollar authored Jan 11, 2012
97
8cfdd96 @ddollar init
ddollar authored May 18, 2011
98 cd $BUILD_DIR
df91075 @ddollar try new approach for node_modules cache
ddollar authored Jan 13, 2012
99 run_npm install
100 run_npm rebuild
aa480b1 @ddollar better npm support
ddollar authored Jan 11, 2012
101
df91075 @ddollar try new approach for node_modules cache
ddollar authored Jan 13, 2012
102 echo "Dependencies installed" | indent
8cfdd96 @ddollar init
ddollar authored May 18, 2011
103
104 # repack cache with new assets
e63f8b3 @ddollar only try to store node_modules if it exists
ddollar authored May 30, 2011
105 if [ -d $CACHE_TARGET_DIR ]; then
106 rm -rf $CACHE_STORE_DIR
107 mkdir -p $(dirname $CACHE_STORE_DIR)
108 cp -a $CACHE_TARGET_DIR $CACHE_STORE_DIR
109 fi
Something went wrong with that request. Please try again.