Skip to content

Instantly share code, notes, and snippets.

@DMeechan
Last active February 20, 2018 14:18
Show Gist options
  • Save DMeechan/25469e18ea9fde342540752002a17d64 to your computer and use it in GitHub Desktop.
Save DMeechan/25469e18ea9fde342540752002a17d64 to your computer and use it in GitHub Desktop.
How to Deploy Meteor on IBM Cloud using DevOps Continuous Delivery Pipeline

How to Deploy Meteor 1.6 on IBM Cloud using DevOps Continuous Deployment Pipeline

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.

Prerequisites

  1. Download jq 1.5 for Linux from here

  2. Put the jq file in the bin folder in your Meteor project (create the binfolder if it doesn't already exist)

  3. Rename the jq file to jq (no file extension)

  4. Create a Compose for MongoDB database on IBM Cloud

  5. Ensure your Meteor project is running the latest version (I'm using 1.6.1 for this)

Setting up the Continuous Deployment Pipeline

Creating the toolchain

  1. Create a 'Continuous Delivery' service here

  2. Click Create Toolchain here

  3. Build your own toolchain

  4. Add a Tool

  5. GitHub (for IBMers: choose GitHub Enterprise Whitewater to use IBM's internal GitHub Enterprise)

  6. Add a Tool

  7. Delivery Pipeline

Configuring the delivery pipeline: Build stage

  1. Click on the delivery pipeline you created

  2. Click Add Stage and name it Build

  3. Choose Git repository as your input type, and ensure the correct Git repository and branch are selected

  4. Set the Stage Trigger to Run jobs whenever a change is pushed to Git

  5. Switch to the Jobs tab

  6. Add Job => Build

  7. Builder type: Shell script

  8. Paste the script from build.sh into Build script

  9. Enter build in 'Build archive directory'

  10. Click Save!

Configuring the delivery pipeline: Deploy stage

  1. Click Add Stage and name it Deploy

  2. 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
  1. Switch to the Jobs tab

  2. Add Job => Deploy

  3. Select your region, organisation, and space

  4. Enter your application name

  5. Paste the script from deploy.sh into Deploy script

  6. Switch to the Environment Properties tab

  7. Add property => Text property

  8. On the left, enter: MONGO_SERVICE

  9. On the right, enter the name of your IBM Cloud MongoDB database (example: meteor-tutorial-db)

  10. (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.

  11. Click Save!

Test it

  1. Click the play button in the top-right of the Build stage

  2. 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!

Debugging

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!

Adding Meteor Settings

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.

  1. First off, open up the 'Environment Variables' tab of your Deploy stage

  2. Add Property

  3. Text property

  4. Enter METEOR_SETTING on the left

  5. 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).

  6. Hit Save

  7. Cross your fingers and run the deploy stage!

Example 1 - JSON 'flattening'

BEFORE:

{
  "keys": {
    "foo": "bar",
    "thing": "stuff"
  }
}

AFTER:

{ "keys": { "foo": "bar", "thing": "stuff" } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment