Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from jordansissel:master #1

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,67 @@
## Usage

```
% heroku create --stack cedar --buildpack https://github.com/jordansissel/heroku-buildpack-meteor.git
% heroku create --buildpack https://github.com/jordansissel/heroku-buildpack-meteor.git
```

## Example

Create a sample app with 'meteor'

```
% meteor create --example wordplay
wordplay: created.
% meteor create --example todos
todos: created.

To run your new app:
cd wordplay
cd todos
meteor
```

Put it in git.

```
% cd wordplay
% cd todos
% git init
Initialized empty Git repository in /tmp/a/wordplay/.git/
Initialized empty Git repository in /tmp/a/todos/.git/
% git add .
% git commit -m "Sample wordplay app!"
% git commit -m "Sample todos app!"
```

Create your heroku app

```
% heroku create --stack cedar --buildpack https://github.com/jordansissel/heroku-buildpack-meteor.git
% heroku create --buildpack https://github.com/jordansissel/heroku-buildpack-meteor.git
```

Configure your ROOT_URL setting
Or if your Heroku app already exists

```
% heroku buildpacks:set https://github.com/jordansissel/heroku-buildpack-meteor.git
```

Configure your plugins & settings

```
% heroku addons:create mongolab:sandbox # optional: use whatever mongo provider you prefer
% heroku config:add MONGO_URL=<insert_value_of_MONGOLAB_URI_here>
% heroku config:add ROOT_URL=<insert_url_created_above_here>
```

Add [session affinity](https://devcenter.heroku.com/articles/session-affinity) so your app will still work with more than one dyno
```
% heroku labs:enable http-session-affinity
```

Optional step, if you are using a ```settings.json``` file to configure your Meteor application

```
% heroku config:add METEOR_SETTINGS="$(cat settings.json)"
```

Deploy it

```
% git push heroku
% git push heroku master
```

Enjoy!
81 changes: 81 additions & 0 deletions bin/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
error() {
echo " ! $*" >&2
exit 1
}

head() {
echo ""
echo "-----> $*"
}

debug() {
# Uncomment this when you need to debug things during the build
# echo "DEBUG $*"
: # null command to prevent bash syntax error when not using
}

info() {
#echo "`date +\"%M:%S\"` $*"
echo " $*"
}

build_failed() {
head "Build failed"
}

protip() {
tip=$1
url=$2
echo
echo "PRO TIP: $tip" | indent
echo "See ${url:-https://devcenter.heroku.com/articles/nodejs-support}" | indent
}

file_contents() {
if test -f $1; then
echo "$(cat $1)"
else
echo ""
fi
}

package_json() {
if test -f $build_dir/package.json; then
local result="$(cat $build_dir/package.json | $bp_dir/vendor/jq -r $1)"
if [ "$result" == "null" ]; then echo ""
else echo "$result"
fi
else
echo ""
fi
}

# sed -l basically makes sed replace and buffer through stdin to stdout
# so you get updates while the command runs and dont wait for the end
# e.g. npm install | indent
indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries
*) sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data
esac
}

cat_npm_debug_log() {
test -f $build_dir/npm-debug.log && cat $build_dir/npm-debug.log
}

export_env_dir() {
env_dir=$1
if [ -d "$env_dir" ]; then
whitelist_regex=${2:-''}
blacklist_regex=${3:-'^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH)$'}
if [ -d "$env_dir" ]; then
for e in $(ls $env_dir); do
echo "$e" | grep -E "$whitelist_regex" | grep -qvE "$blacklist_regex" &&
export "$e=$(cat $env_dir/$e)"
:
done
fi
fi
}
65 changes: 18 additions & 47 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -1,52 +1,23 @@
#!/bin/sh
#!/usr/bin/env bash
# USAGE: bin/compile <build-dir> <cache-dir> <env-dir>

BUILD_DIR=$1
CACHE_DIR=$2
METEOR_HOME=$BUILD_DIR/.meteor/local
PATH=$METEOR_HOME/usr/bin:$METEOR_HOME/usr/lib/meteor/bin:$PATH
bp_dir=$(cd $(dirname $0); cd ..; pwd)

# Unfortunately heroku buildpacks don't let you pass parameters
# to this script, so if you want to change the version of meteor,
# you'll have to fork and hard-code this.
METEOR_VERSION=0.5.9
# Load some convenience functions like status(), echo(), and indent()
source $bp_dir/bin/common.sh

fetch_meteor() {
if [ -f "$METEOR_HOME/usr/bin/meteor" ] ; then
# Skip if meteor is already fetched
return
fi
# Move the Meteor's app source into a subdirectory
(
head "Moving app source into a subdirectory"
cd $1
mkdir ../app_src
# the shopt makes the * glob catch .files
shopt -s dotglob nullglob
mv * ../app_src
mv ../app_src ./app_src
)


PACKAGE=meteor_${METEOR_VERSION}-1_amd64.deb

echo "Fetching meteor deb package"
curl -o "$CACHE_DIR/$PACKAGE" "http://d3sqy0vbqsdhku.cloudfront.net/${PACKAGE}"

echo "Unpacking meteor"
[ ! -d "$METEOR_HOME" ] && mkdir -p "$METEOR_HOME"
ar p "$CACHE_DIR/$PACKAGE" data.tar.gz | tar -C "$METEOR_HOME" -zxf -
}

build() {
(
cd $BUILD_DIR
echo "Building meteor bundle"
meteor bundle $CACHE_DIR/bundle.tar.gz
mkdir -p $BUILD_DIR/.meteor/local/build
tar -zxf $CACHE_DIR/bundle.tar.gz --strip-components 1 -C $BUILD_DIR/.meteor/local/build
rm $CACHE_DIR/bundle.tar.gz
)
}

[ ! -d $BUILD_DIR ] && mkdir $BUILD_DIR
[ ! -d $CACHE_DIR ] && mkdir $CACHE_DIR

fetch_meteor
build

echo "Checking for post_compile script"
if [ -f $BUILD_DIR/bin/post_compile ] ; then
echo "-----> Running post_compile hook"
chmod +x $BUILD_DIR/bin/post_compile
$BUILD_DIR/bin/post_compile
fi
# Install node first, as a dependency, then install meteor & build app
$bp_dir/bin/compile_node "$1" "$2"
$bp_dir/bin/compile_meteor "$1" "$2"
81 changes: 81 additions & 0 deletions bin/compile_meteor
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash
# USAGE: bin/compile_meteor <build-dir> <cache-dir> <env-dir>

####### Configure environment

set -e # fail fast

###### NEEDED VARIABLES/DIRECTORIES

BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
APP_SOURCE=$BUILD_DIR/app_src
METEOR_HOME=$BUILD_DIR/.meteor_tool
PATH=$METEOR_HOME:$BUILD_DIR/.heroku/node/bin:$PATH
bp_dir=$(cd $(dirname $0); cd ..; pwd)

# Load some convenience functions like status(), echo(), and indent()
source $bp_dir/bin/common.sh

fetch_meteor() {
# We determine the desired Meteor version from .meteor/release
METEOR_VERSION=`cat "$APP_SOURCE/.meteor/release" | sed 's/METEOR@//'`

# if there are old cached versions, we should delete them
(
cd $CACHE_DIR
old_files=`find . -maxdepth 1 -name 'meteor-*.tar.gz' -not -name "meteor-$METEOR_VERSION.tar.gz"`
for f in $old_files; do rm $f; done
)

head "Fetching Meteor $METEOR_VERSION"
PACKAGE="$CACHE_DIR/meteor-$METEOR_VERSION.tar.gz"
TARBALL_URL="https://d3sqy0vbqsdhku.cloudfront.net/packages-bootstrap/${METEOR_VERSION}/meteor-bootstrap-os.linux.x86_64.tar.gz"
if [ ! -e "$PACKAGE" ]; then
curl -o "$PACKAGE" "$TARBALL_URL" | indent
else
info "Using cached Meteor $METEOR_VERSION"
fi

head "Unpacking Meteor $METEOR_VERSION"
tar -xzf "$PACKAGE" -C "$BUILD_DIR"
mv "$BUILD_DIR/.meteor" "$METEOR_HOME"
# bomb out if it didn't work, eg no net
[ ! -x "${METEOR_HOME}/meteor" ] && error "Install failed: No meteor bin found."
info "Meteor $METEOR_VERSION is installed"
}

build() {
(
head "Building Meteor App Bundle"
cd $APP_SOURCE
# can't build with these platforms enabled, it looks like
set +e # these next few are allowed to exit nonzero
grep -Fxq ios .meteor/platforms
if [ $? -eq 0 ]; then
meteor remove-platform ios 2>&1 | indent
fi
grep -Fxq android .meteor/platforms
if [ $? -eq 0 ]; then
meteor remove-platform android 2>&1 | indent
fi
set -e # back to failing if any command fails
meteor build ../build --directory 2>&1 | indent
head "Installing App's NPM Dependencies"
(cd ../build/bundle/programs/server && npm install 2>&1 | indent)
cd $BUILD_DIR && rm -rf $APP_SOURCE
)
}

[ ! -d $BUILD_DIR ] && mkdir $BUILD_DIR
[ ! -d $CACHE_DIR ] && mkdir $CACHE_DIR

fetch_meteor
build

if [ -f $BUILD_DIR/bin/post_compile ] ; then
head "Running post_compile hook"
chmod +x $BUILD_DIR/bin/post_compile
$BUILD_DIR/bin/post_compile
fi
Loading