Huge thanks to Peter Tuton for his article on Medium. This is based on his work, with some minor modifications to resolve some errors I encountered.
-
Download jq 1.5 for Linux from here
-
Put the jq file in the
bin
folder in your Meteor project (create thebin
folder if it doesn't already exist) -
Rename the jq file to
jq
(no file extension) -
Create a
Compose for MongoDB
database on IBM Cloud -
Ensure your Meteor project is running the latest version (I'm using 1.6.1 for this)
-
Create a 'Continuous Delivery' service here
-
Click
Create Toolchain
here -
Build your own toolchain
-
Add a Tool
-
GitHub
(for IBMers: chooseGitHub Enterprise Whitewater
to use IBM's internal GitHub Enterprise) -
Add a Tool
-
Delivery Pipeline
-
Click on the delivery pipeline you created
-
Click
Add Stage
and name itBuild
-
Choose
Git repository
as your input type, and ensure the correct Git repository and branch are selected -
Set the Stage Trigger to
Run jobs whenever a change is pushed to Git
-
Switch to the
Jobs
tab -
Add Job
=>Build
-
Builder type:
Shell script
-
Paste the script from build.sh into
Build script
-
Enter
build
in 'Build archive directory' -
Click
Save
!
-
Click
Add Stage
and name itDeploy
-
In the 'Input' tab, set the following:
- Input type:
Build artifacts
- Stage:
Build
- Job:
Build
- Stage trigger:
Run jobs when the previous stage is completed
-
Switch to the
Jobs
tab -
Add Job
=>Deploy
-
Select your region, organisation, and space
-
Enter your application name
-
Paste the script from deploy.sh into
Deploy script
-
Switch to the
Environment Properties
tab -
Add property
=>Text property
-
On the left, enter:
MONGO_SERVICE
-
On the right, enter the name of your IBM Cloud MongoDB database (example:
meteor-tutorial-db
) -
(Optional) If you want to set any additional env variables, like METEOR_SETTINGS, then scroll down and follow the mini-guide at the end of the page, and then come back here.
-
Click
Save
!
-
Click the play button in the top-right of the Build stage
-
Now go grab a coffee and come back in 10 or 15 mins. When you get back, hopefully both stages will be green and you'll have a Meteor server up and running!
If you run into difficulties, try opening up your Meteor project in Terminal and entering:
meteor node --version
meteor npm --version
This will tell you what NPM and Node.js versions Meteor is. In your deploy script (see deploy.sh
for my example), find "node"
and "npm"
(probably on lines 52 and 53).
First, change the NPM version in your deploy script to match the NPM version that your Meteor project is using.
The CloudFoundry buildpacks that IBM Cloud uses to deploy these Node servers do not support all versions of Node. So you've got to make sure you enter a Node.js version that is supported by the buildpack you're using. Otherwise it will crash an give a very unhelpfulerror message.
Now, here's where it gets weird. IBM Cloud doesn't always use the latest buildpack version. As of writing, the latest buildpack is 1.6.17, but for some reason my server is using 1.6.4.
So you'll first need to check which buildpack you're using. To do this, you need to make sure your deploy script reaches the cf start
stage. If it gets stuck on cf restage
like mine did, just comment out the restage part. Because when cf start
runs, it should say which buildpack version it's using, and it should also say if there's a version mismatch between your specified Node version and the buildpack's supported Node versions.
Next, go here, find your buildpack version in that list (you may need to visit page 2 or 3 to find it), and then look at which Node.js versions your buildpack supports.
Take whichever supported Node.js version is closest to the version your Meteor project is using, and enter it in deploy.sh
where it says engines: { "node": "ENTER VERSION HERE" }
(probably line 52) . Then copy over that script into your deploy stage in IBM Cloud and re-run the deploy stage.
Good luck!
If you use a settings.json file when you launch your Meteor server locally (using meteor --settings settings.json
), you'll need to do a bit of extra work to get your server working on IBM Cloud.
-
First off, open up the 'Environment Variables' tab of your Deploy stage
-
Add Property
-
Text property
-
Enter
METEOR_SETTING
on the left -
On the right, paste in the contents of your
settings.json
file. Note: if the formatting goes a bit weird, you may want to manually 'flatten' the file into a single line before pasting it (see example 1 below). -
Hit
Save
-
Cross your fingers and run the deploy stage!
BEFORE:
{
"keys": {
"foo": "bar",
"thing": "stuff"
}
}
AFTER:
{ "keys": { "foo": "bar", "thing": "stuff" } }