Deploying with Meteor Up (MUP)
We would be remiss if we didn't add one final method of deploying Meteor apps to a production server. This method is called Meteor Up (MUP). Using a fairly simple configuration file, MUP vastly simplifies the server deployment process. And until we get to see what Galaxy (Meteor's deployment platform) looks like, MUP is the easiest way to deploy to a custom environment. This recipe will show you how to deploy your app to a custom server using Meteor Up.
Getting ready
To complete this recipe, you will need a working Meteor application. It doesn't need to be fancy, but it does need to be functional so you can see whether it was installed properly on your server at a glance.
How to do it…
MUP is installed via npm. It needs to be installed globally, so we will use the -g
argument. To deploy your app to a custom server using MUP, perform the following steps:
- To install MUP, open a terminal window and execute the following command:
$ npm install -g mup
This will take a bit to install, but once complete, you'll be ready to configure and use MUP to deploy your application.
- To run
mup init
, navigate to the root folder of your project in a terminal window and enter the following command:$ mup init
You will receive a message similar to the following:
Empty Project Initialized!
This process will create two files in your project's root folder. We don't need to worry about the first file (
settings.json
). We will configure our app using the second file, namedmup.json
. - Now, we'll configure
mup.json
. Open the[project root]/mup.json
file in an editor. The top part of the file will have our remote server information. It should look similar to the following lines of code:"servers": [ { "host": "hostname", "username": "root", "password": "password" // or pem file (ssh based authentication) //"pem": "~/.ssh/id_rsa" } ],
The
host
property will be the name of the server you will be accessing via SSH/SCP. If our server name wasmy-production-server.com
, the host property would look similar to the following:"host": "my-production-server.com",
The
username
andpassword
properties are the user/pass combination you would use if you were tossh
into the remote server.The next four properties help us to configure our server. If we want MUP to install Mongo, Node, or PhantomJS (all necessary to deploy via MUP), we can specify the code as follows:
"setupMongo": true, "setupNode": true, "nodeVersion": "0.10.33", "setupPhantom": true,
Tip
As of the printing of this book, the latest stable Node version is
0.10.33
. You may want to check this and modify thenodeVersion
property as appropriate.If Mongo/Node/PhantomJS is already installed, you can change the preceding properties to
false
(which will speed up your deployment).Next, we specify specify what we want our app to be called. This is done by modifying the
appName
property:"appName": "[your-app-name-here]",
We need to specify the folder on our local machine where our to-be-deployed app is located. This is determined in the
app
property:"app": "/path/to/the/app",
The last property we need to set is
env
. This instructs Node whichROOT_URL
andPORT
to run our Meteor application from. If, for example, we were redirecting incoming HTTP traffic to a localhost, onport 1337
(which is done using a reverse-proxy, such asnginx
, or a virtual host, such asapache
), ourenv
configuration would look like the following code:"env": { "ROOT_URL": "http://localhost", "PORT": 1337 },
- Now let's configure our remote server with
mup setup
. In the terminal window, navigate to your project's root folder and enter the following command:$ mup setup
This will install MongoDB, Node, and PhantomJS on the remote server. It will also configure our remote server environment and install some helper npm packages, such as
upstart
. - Let's deploy our app with
mup deploy
. Once themup setup
command is complete, we'll be ready to deploy our app. Execute the following command in the terminal window:$ mup deploy
MUP will bundle your app locally, upload the build, configure the requisite npm packages on the remote server, and then serve up your app. As it runs through this process, MUP will give you status updates in the terminal.
Once complete, your app should be up and running. Test it out by either visiting your external URL (for example, http://my-custom-server.com
) or by logging in to a remote server via SSH
, and testing the build with a curl
command on the localhost (for example, curl http://localhost:3000
).
You may have a bit of troubleshooting to do to make sure your virtual host or reverse-proxy is configured properly, but after some small adjustments, you'll find that, at present, MUP is definitely the best way to deploy to a custom server.
How it works…
MUP takes all the steps we would normally have to implement manually (as in the Deploying to a custom hosted environment recipe in this chapter) and implements them automatically. There are three main parts to pulling this off successfully.
First, MUP creates a default configuration file when we execute the mup init
command. We edit the newly created file with all the settings to install the right software on the remote server, configure environment variables, and upload our production build.
Second, we use mup install
to install all the needed software on the remote server, as specified in the mup.json
configuration file.
Lastly, our application is bundled, uploaded, extracted, initialized with environment variables, and set to run on the remote server. This is all accomplished with the mup deploy
command.
MUP performs these tasks based on the configuration file we edited.
Tip
There are many additional settings we can configure and some great features of MUP that we can explore by visiting the MUP repo, which is found at https://github.com/arunoda/meteor-up.
See also
- The Deploying to a custom hosted environment recipe in this chapter