Deploy Meteor 2.1 IBM Cloud Foundry

I’ve been trying to deploy to IBM Cloud Foundry for some time. Using Mongo and passing some Settings in METEOR_SETTINGS. Someone managed to put together a script to create a build and deploy pipeline.

shell build

PATH=$METEOR_HOME/usr/bin:$METEOR_HOME/usr/lib/meteor/bin:PATH 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 } status() { echo "-----> "
install_meteor() {
status “Installing Meteor (ignore any warnings about launcher scripts)”
export PATH=/usr/bin:$PATH # necessary for install script to run from URL
curl | sh
status “Updating PATH with Meteor”
build() {
status “Building meteor bundle”
meteor npm install
meteor build $ARCHIVE_DIR --directory --server-only --architecture os.linux.x86_64
status “Installing dependencies”
cd $ARCHIVE_DIR/bundle/programs/server/
npm install
cd …/…/
chmod -R +w+x *
status “Build complete”

It works correctly.

Now in the deployment pipeline, I don’t know if it’s correct, but I can’t implement it

shell pipeline deploy


Grab jq path for later and set execute permission

DIR=( cd "( dirname “${BASH_SOURCE[0]}” )" && pwd )
chmod +x $jq

Source code is located in the ‘bundle’ directory - let’s go there

cd bundle

Create a basic package file - we just need the meteor-node-stubs package

cat <<-JSON > package.json
“name”: “bundle”,
“version”: “1.0.0”,
“main”: “main.js”,
“dependencies”: {
“meteor-node-stubs”: “^0.2.11”
“scripts”: {
“start”: “node main.js”

Push to Bluemix but don’t start just yet…

cf push “${CF_APP}” --no-start -b nodejs_buildpack -m 256M --no-manifest

Bind the MongoDB service

- MONGO_SERVICE environment variable is required

if [ -z “{MONGO_SERVICE}" ]; then echo "Set the MONGO_SERVICE environment variable to the name of the MongoDB service" exit 1 else cf bind-service "{CF_APP}” “${MONGO_SERVICE}”

Grab the application guid for later

GUID=cf curl /v2/apps?q=name:${CF_APP} | $jq -r '.resources[0].metadata.guid'

Set the MongoDB URL

- assumes the Bluemix provided “compose-for-mongodb” service is used

MONGO_URL=cf curl /v2/apps/${GUID}/env | $jq -r '.system_env_json.VCAP_SERVICES["compose-for-mongodb"][0].credentials.uri'
cf set-env “{CF_APP}" MONGO_URL "{MONGO_URL}”

Set the Root URL

ROOT_URL=cf curl /v2/apps/${GUID}/env | $jq -r '.application_env_json.VCAP_APPLICATION.uris[0]'
ROOT_URL=“https://ROOT_URL" cf set-env "{CF_APP}” ROOT_URL “${ROOT_URL}”

Restage and start

cf restage “{CF_APP}" cf start "{CF_APP}”