Last active
February 20, 2018 14:17
-
-
Save DMeechan/dc0cf5a5072d5ebd3eb34a21377694d2 to your computer and use it in GitHub Desktop.
IBM Cloud Meteor 1.6 Deploy Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# See guide here: | |
# https://gist.github.com/DMeechan/25469e18ea9fde342540752002a17d64 | |
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 "-----> $*" | |
} | |
# Grab jq path for later and set execute permission | |
status "Grabbing jq file path" | |
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | |
# jq=$DIR/jq | |
jq=$DIR/bin/jq | |
chmod +x $jq | |
# Source code is located in the 'bundle' directory - let's go there | |
cd bundle | |
# Create a basic package file | |
# We might just need the meteor-node-stubs package, I'm not sure | |
# Becasuse there was conflicting advice online | |
# So I added in a couple of extra ones that seem to be key | |
# NOTE: Remember to update your target node and npm versions below (lines 52 & 53) | |
# And check that the Node.js buildpack you're using supports the Node version you specify below (!!) | |
status "Creating package.json" | |
cat <<-JSON > package.json | |
{ | |
"name": "bundle", | |
"version": "1.0.0", | |
"main": "main.js", | |
"dependencies": { | |
"@babel/runtime": "^7.0.0-beta.40", | |
"autoprefixer": "^6.4.1", | |
"babel-runtime": "^6.26.0", | |
"bcrypt": "^1.0.3", | |
"faker": "^3.0.1", | |
"meteor-node-stubs": "^0.3.2" | |
}, | |
"scripts": { | |
"start": "node main.js" | |
}, | |
"engines": { | |
"node": "^8.2.1", | |
"npm": "^5.6.0" | |
} | |
} | |
JSON | |
cfPushNoStart() { | |
# Push to Bluemix but don't start just yet... | |
status "Pushing to Bluemix (in no-start mode for now)" | |
cf push "${CF_APP}" --no-start -b nodejs_buildpack -m 256M --no-manifest | |
} | |
# Bind the MongoDB service | |
bindMongoDBService() { | |
# - MONGO_SERVICE environment variable is required | |
status "Binding MongoDB service" | |
if [ -z "${MONGO_SERVICE}" ]; then | |
status "Warning: set the MONGO_SERVICE environment variable to the name of the MongoDB service" | |
exit 1 | |
else | |
cf bind-service "${CF_APP}" "${MONGO_SERVICE}" | |
fi | |
} | |
setRequiredMeteorEnvVariables() { | |
# Grab the application guid for later | |
status "Grabbing application guid" | |
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 | |
status "Setting env variable: Mongo_URL" | |
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" | |
status "Setting env variable: ROOT_URL" | |
cf set-env "${CF_APP}" ROOT_URL "${ROOT_URL}" | |
status "Note: be sure to set any environment variables you want to use (see comments for more info)" | |
} | |
setMeteorSettings() { | |
# Set METEOR_SETTINGS env variable | |
status "Setting env variable: METEOR_SETTINGS" | |
cf set-env "${CF_APP}" METEOR_SETTINGS "${METEOR_SETTINGS}" | |
} | |
# # # | |
# To set the environment variables you want to use: | |
# You'll need to first set them both in *Environment Variables* tab of the build | |
# And then in this deploy script using cf set-env, as shown with METEOR_SETTING above | |
# # # | |
cfRestage() { | |
# Restage and start | |
status "Restaging cf app" | |
cf restage "${CF_APP}" | |
} | |
cfStart() { | |
status "Starting cf app" | |
cf start "${CF_APP}" | |
} | |
cfPushNoStart | |
bindMongoDBService | |
setRequiredMeteorEnvVariables | |
# Un-comment the line below (123) if you want to use the METER_SETTINGS env variable! | |
# setMeteorSettings | |
cfRestage | |
cfStart | |
# I found restaging failed for me after I started using METER_SETTINGS | |
# So on mine I commented out 'cfRestage' (line 123) | |
# So yours is failing or env variables aren't working | |
# Try commenting out the restage line above (line 123) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment