Deploying a Meteor app on Google App Engine

While Meteor recently stopped their free hosting service [1], Google recently beta released App Engine that supports Node.js [2]. This short article guides you how to deploy a Meteor app on Google App Engine.

Prepare

Firstly, you need to setup Google Cloud Platform. Please see the quickstart. In short, you create and enable a Cloud Console project, and then download the Google Cloud SDK. This should be fairly easy by following the instruction. In addition, it will be required to activate API Manager at the console if this is your first time.

Secondly, configuring the permission is important. An easy way is to login yourself as an owner by:

gcloud login

Or, you can download key.json of a service account that has a proper permission, and activate it:

gcloud auth activate-service-account --key-file key.json

Finally, initialize gcloud:

gcloud init

Build

In your Meteor project directory, run the following command to build your app:

meteor build .deploy --directory

Then, create `package.json` in .deploy/bundle with the following content:

{
"private": true,
"scripts": {
"start": "node main.js",
"install": "(cd programs/server && npm install)"
},
"engines": {
"node": "0.10.43"
}
}

You also need to create `app.yaml` in the same directory with the following content:

runtime: nodejs
env: flex
threadsafe: true
automatic_scaling:
max_num_instances: 1
env_variables:
MONGO_URL: 'mongodb://[user]:[pass]@[host]:[port]/[db]'
ROOT_URL: 'https://...'
METEOR_SETTINGS: '{}'

Deploy

In .deploy/bundle, run the following command to deploy your app:

gcloud app deploy

That’s it! It takes a while, but when it’s done, you are all set.