Deploying Meteor 1.3.2.4 with mupx

Deploying meteor has been made simple and easy with mupx, but there are a couple pitfalls which can snag you.

In this guide we will try to outline the best ways to deploy your app easily and trouble free.

What's Mupx?

Simply put - it's the best way to get your meteor app online!

Deploy and provision a server in minutes with this easy to use, command line based tool.

You can check out it's github project here if you want to dig into the code a bit.

To summarize the mupx software works a lot like meteor deploy does. You can now provision a docker docklet which has a mongo and nginx configured for your meteor application and then bundle your meteor application for production in one tool; the mighty powerful mupx is an essential piece of the meteor developers toolkit.

Via specifying ssh credentials to your production server inside a local mup.json file that is generated by mupx you will be able to deploy, restart, check status or migrate your meteor apps without much stress at all.

For long time Meteor users: If you have deployed previously using upstart or a nginx proxy pass configuration, mupx will take over these methods and provide you will a fully comprehensive solution. Start with a blank server image first to avoid conflict with previous installations if using these older methods of deployment

Supported Platforms

Ubuntu 14+ is required to use mupx and Node version 0.10.40 is what was used in this guide alongside [email protected]

Check your node version with

node -v  

Meteor version is within .meteor/release

Check your ubuntu version with lsb_release -a or print the file /etc/lsb-release using commands more or cat.

$ lsb_release -a
No LSB modules are available.  
Distributor ID:    Ubuntu  
Description:    Ubuntu 14.10  
Release:    14.10  
Codename:    utopic  

Getting mupx

npm install -g mupx  

Once you have mupx installed you can add it to an existing project, or create a new project via mupx init

Add mupx to your existing Meteor project

cd meteor-project  
mupx init  

Create a mupx project

mkdir ~/my-meteor-deployment  
cd ~/my-meteor-deployment  
mupx init  

This will create 2 files in the project:

  • mup.json - A mupx configuration file
  • settings.json - Settings for Meteor's settings API

Looking at mup.json it is easy to follow as it is heavily commented

Example mup.json configuration

{
  // Server authentication info
  "servers": [
    {
      "host": "hostname",
      "username": "root",
      "password": "password",
      // or pem file (ssh based authentication)
      // WARNING: Keys protected by a passphrase are not supported
      //"pem": "~/.ssh/id_rsa"
      // Also, for non-standard ssh port use this
      //"sshOptions": { "port" : 49154 },
      // server specific environment variables
      "env": {}
    }
  ],

  // Install MongoDB on the server. Does not destroy the local MongoDB on future setups
  "setupMongo": true,

  // Application name (no spaces).
  "appName": "myAppname",

  // Location of app (local directory). This can reference '~' as the users home directory.
  // i.e., "app": "~/Meteor/my-app",
  // This is the same as the line below.
  "app": "/Users/my-username/Meteor/my-app",

  // Configure environment
  // ROOT_URL must be set to your correct domain (https or http)
  "env": {
    "PORT": 80,
    "ROOT_URL": "http://myapp.com",
    "MAIL_URL": "smtp://username:[email protected]:587",
    "MONGO_URL": "mongodb://127.0.0.1:27017/appName"
  },

  // Meteor Up checks if the app comes online just after the deployment.
  // Before mup checks that, it will wait for the number of seconds configured below.
  "deployCheckWaitTime": 1600,

  // show a progress bar while uploading.
  // Make it false when you deploy using a CI box.
  "enableUploadProgressBar": true
}

To setup your mup.json file correctly, ensure first you have a working ssh connection to the server you wish to deploy on.

Once the ssh connection has been established and tested, you can safely proceed to fill out the servers section at the top of the mup.json file.

Uncomment the lines for your rsa public/private key pair or if using a non-standard ssh port:

"pem": "~/.ssh/id_rsa",
"sshOptions": { "port" : 777 },

If you wish to specify the shell or any other server environment variables do so with the env key:

"env": { 
    "SHELL" : "/bin/zsh" , 
    "LANG"  : "en_GB.UTF-8"
}

Setting up the Server

Once you know the SSH is all good in mup.json you can setup the required dependencies on the server for mupx via running the following in the same directory as your mup.json

mupx setup  

This will setup the server for the mupx deployments. It will take around 2-5 minutes depending on the server's performance and network availability.

Avoiding possible problems

From several deployments what I have noticed is the mupx setup step will complete flawlessly when mongo is not installed on the server and setupMongo is true in the mup.json

Removing mongo

To do this if mongo is already installed on your Ubuntu 14+ distro simply run the following:

sudo apt-get purge mongodb*  
sudo apt-get autoremove  

Node Version

I have had no problems deploying with node 0.10.40 but I ran into some locale issues at time of writing with node 5+ but I believe in meteor 1.4 this will be resolved

Sudo Permissions

If your username is root or using AWS EC2, you don't need to follow these steps

If you receive this error do the following:

'sudo: no tty present and no askpass program specified'  
  1. Make sure your ssh key is in ~/.ssh/authorized_keys
  2. Add NOPASSWD to sudoers file as so
sudo visudo

# replace this line
%sudo  ALL=(ALL) ALL

# by this line
%sudo ALL=(ALL) NOPASSWD:ALL  

Deploying your app

Now the mupx setup has completed all we need to do is deploy our app like so

mupx deploy  

This will do the meteor bundle for us and is very similar to how meteor deploy works. It will take several minutes to complete.

Once the deployment is complete and the verification has passed your app will be live to the world.

Troubleshooting if it's not gone live

First check your server is reachable over port 80 with curl -v http://your-app.com

If it is not accessible configure your firewall (ufw by default on ubuntu) like so as root

sudo -i  
ufw default allow outgoing  
ufw allow http  

Ensure that port 80 is listed in ufw status more information here

ECS AWS users

Ensure the security group for your amazon AMI instance allows port 80 inside your instance dashboard.

Modifying the Live Database once Deployed

To access the live database once your app is deployed this can be done via logging into your server you specified in the mup.json and then into the docker setup on the server via

$ docker exec -it mongodb mongo <app-name>

Now if you wish to perform a meteor reset you can just drop the whole database and start over.

> db.dropDatabase()

Or if you wish to just drop a user maybe easier with

> db.users.remove ({ "_id": <the user id goes here>}, true)

A common pitfall of first time deployments is to log into the remote machine and attempt a meteor or mongo command and find the binaries not on the machine. This is because they are inside the docker container and need to be accessed via docker exec

Tom Whitbread

Read more posts by this author.

Subscribe to Meteor University

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!