Skip to content

Commit

Permalink
first pass at vendoring on s3
Browse files Browse the repository at this point in the history
  • Loading branch information
ddollar committed Sep 16, 2011
1 parent 0a0d748 commit b68e8ef
Show file tree
Hide file tree
Showing 1,446 changed files with 865 additions and 158,452 deletions.
28 changes: 23 additions & 5 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
# fail fast
set -e

mktmpdir() {
dir=$(mktemp -t node-$1-XXXX)
rm -rf $dir
mkdir -p $dir
echo $dir
}

# config
NODE_VERSION="0.4.7"
NPM_VERSION="1.0.27"
Expand All @@ -16,19 +23,30 @@ LP_DIR=`cd $(dirname $0); cd ..; pwd`
CACHE_STORE_DIR=$CACHE_DIR"/node_modules/$NPM_VERSION"
CACHE_TARGET_DIR=$BUILD_DIR"/node_modules"

# s3 packages
NODE_PACKAGE="http://language-pack-nodejs.s3.amazonaws.com/nodejs-${NODE_VERSION}.tgz"
NPM_PACKAGE="http://language-pack-nodejs.s3.amazonaws.com/npm-${NPM_VERSION}.tgz"
SCONS_PACKAGE="http://language-pack-nodejs.s3.amazonaws.com/scons-${SCONS_VERSION}.tgz"

# vendor directories
VENDORED_NODE="$LP_DIR/vendor/node/node-$NODE_VERSION"
VENDORED_NPM="$LP_DIR/vendor/npm/npm-$NPM_VERSION"
VENDORED_NODE="$(mktmpdir node)"
VENDORED_NPM="$(mktmpdir npm)"
VENDORED_SCONS="$(mktmpdir scons)"

# download and unpack packages
echo "-----> Fetching Node.js binaries"
mkdir -p $VENDORED_NODE && curl $NODE_PACKAGE -s -o - | tar xzf - -C $VENDORED_NODE
mkdir -p $VENDORED_NPM && curl $NPM_PACKAGE -s -o - | tar xzf - -C $VENDORED_NPM
mkdir -p $VENDORED_SCONS && curl $SCONS_PACKAGE -s -o - | tar xzf - -C $VENDORED_SCONS

# vendor node
PATH="$BUILD_DIR/bin:$PATH"
echo "-----> Vendoring node $NODE_VERSION"
mkdir -p "$BUILD_DIR/bin"
cp "$VENDORED_NODE/node" "$BUILD_DIR/bin/node"
cp "$VENDORED_NODE/bin/node" "$BUILD_DIR/bin/node"

# setting up paths for building
PATH="$LP_DIR/vendor/scons/scons-${SCONS_VERSION}:$PATH"
PATH="$VENDORED_NODE:$PATH"
PATH="$VENDORED_SCONS:$VENDORED_NODE/bin:$PATH"
INCLUDE_PATH="$VENDORED_NODE/include"
export CPATH="$INCLUDE_PATH"
export CPPPATH="$INCLUDE_PATH"
Expand Down
19 changes: 0 additions & 19 deletions support/download_npm

This file was deleted.

79 changes: 79 additions & 0 deletions support/hmac
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash
# Implement HMAC functionality on top of the OpenSSL digest functions.
# licensed under the terms of the GNU GPL v2
# Copyright 2007 Victor Lowther <[email protected]>

die() {
echo $*
exit 1
}

check_deps() {
local res=0
while [ $# -ne 0 ]; do
which "${1}" >& /dev/null || { res=1; echo "${1} not found."; }
shift
done
(( res == 0 )) || die "aborting."
}

# write a byte (passed as hex) to stdout
write_byte() {
# $1 = byte to write
printf "\\x$(printf "%x" ${1})"
}

# make an hmac pad out of a key.
# this is not the most secure way of doing it, but it is
# the most expedient.
make_hmac_pad() {
# using key in file $1 and byte in $2, create the appropriate hmac pad
# Pad keys out to $3 bytes
# if key is longer than $3, use hash $4 to hash the key first.
local x y a size remainder oifs
(( remainder = ${3} ))
# in case someone else was messing with IFS.
for x in $(echo -n "${1}" | od -v -t u1 | cut -b 9-);
do
write_byte $((${x} ^ ${2}))
(( remainder -= 1 ))
done
for ((y=0; remainder - y ;y++)); do
write_byte $((0 ^ ${2}))
done
}

# utility functions for making hmac pads
hmac_ipad() {
make_hmac_pad "${1}" 0x36 ${2} "${3}"
}

hmac_opad() {
make_hmac_pad "${1}" 0x5c ${2} "${3}"
}

# hmac something
do_hmac() {
# $1 = algo to use. Must be one that openssl knows about
# $2 = keyfile to use
# $3 = file to hash. uses stdin if none is given.
# accepts input on stdin, leaves it on stdout.
# Output is binary, if you want something else pipe it accordingly.
local blocklen keysize x
case "${1}" in
sha) blocklen=64 ;;
sha1) blocklen=64 ;;
md5) blocklen=64 ;;
md4) blocklen=64 ;;
sha256) blocklen=64 ;;
sha512) blocklen=128 ;;
*) die "Unknown hash ${1} passed to hmac!" ;;
esac
cat <(hmac_ipad ${2} ${blocklen} "${1}") "${3:--}" | openssl dgst "-${1}" -binary | \
cat <(hmac_opad ${2} ${blocklen} "${1}") - | openssl dgst "-${1}" -binary
}

[[ ${1} ]] || die "Must pass the name of the hash function to use to ${0}".

check_deps od openssl
do_hmac "${@}"
51 changes: 51 additions & 0 deletions support/package_node
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh

set -e

node_version="$1"

if [ "$node_version" == "" ]; then
echo "usage: $0 VERSION"
exit 1
fi

if [ "$S3_ACCESS_KEY_ID" == "" ]; then
echo "must set S3_ACCESS_KEY_ID"
exit 1
fi

if [ "$S3_SECRET_ACCESS_KEY" == "" ]; then
echo "must set S3_SECRET_ACCESS_KEY"
exit 1
fi

basedir="$( cd -P "$( dirname "$0" )" && pwd )"

# make a temp directory
tempdir="$( mktemp -t node_XXXX )"
rm -rf $tempdir
mkdir -p $tempdir

cd $tempdir &&

# download and extract node
curl http://nodejs.org/dist/node-v${node_version}.tar.gz -o node.tgz &&
tar xzvf node.tgz &&

cd node-v${node_version} &&

# build and package nodejs for heroku
heroku make -v -o $tempdir/node-${node_version}.tgz &&

# upload nodejs to s3
$basedir/s3 put language-pack-nodejs \
nodejs-${node_version}.tgz $tempdir/node-${node_version}.tgz &&

# package scons
scons_version=$(ls tools/scons | grep "scons-local" | cut -d- -f3) &&
cd tools/scons &&
tar czvf $tempdir/scons-${scons_version}.tgz * &&

# upload scons to s3
$basedir/s3 put language-pack-nodejs \
scons-${scons_version}.tgz $tempdir/scons-${scons_version}.tgz
36 changes: 36 additions & 0 deletions support/package_npm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

set -e

npm_version="$1"

if [ "$npm_version" == "" ]; then
echo "usage: $0 VERSION"
exit 1
fi

basedir="$( cd -P "$( dirname "$0" )" && pwd )"

# make a temp directory
tempdir="$( mktemp -t node_XXXX )"
rm -rf $tempdir
mkdir -p $tempdir

cd $tempdir &&

# download npm
git clone https://github.com/isaacs/npm.git &&

cd npm &&

# grab the right version
git checkout v${node_version} &&
git submodule update --init --recursive &&
find . -name ".git" -exec rm -rf {} \;

# package it up
tar czvf $tempdir/npm-${npm_version}.tgz *

# upload npm to s3
$basedir/s3 put language-pack-nodejs \
npm-${npm_version}.tgz $tempdir/npm-${npm_version}.tgz
Loading

0 comments on commit b68e8ef

Please sign in to comment.