Deploy a Meteor Application in Under 1 Minute

by Puja Abbassi on Jun 26, 2015

<span id="hs_cos_wrapper_name" class="hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_text" style="" data-hs-cos-general-type="meta_field" data-hs-cos-type="text" >Deploy a Meteor Application in Under 1 Minute</span>

Recently, we had someone on Twitter asking us if we support Meteor. As we were not sure, I thought challenge accepted we could just try it out. And it was easier than I thought. If you’re really in a hurry here’s the 1 minute quick fix:


Prerequisites



Quick Steps


  1. Get the swarm.json and save it to your local directory.
  2. Edit the swarm.json to reflect your Meteor project’s GitHub URL1 and desired domain.
  3. swarm up
  4. Profit

Finding the Right Docker Image


Now keep in mind I’m not a developer per se and have never even looked at Meteor beyond the above-linked website. As I wanted to prove that it works as quickly as possible, I started in what sounds like a reverse order. I started with a Docker image for deploying the application. After some looking around and searching the Docker Hub I found what seems to be by far the most used Docker image for Meteor deployments. It has over 400K downloads, which is quite an accomplishment by itself, and a regularly maintained GitHub repository showing what the team is working on. It is currently based on ubuntu:trusty, but there’s already a branch that tries porting it to the much smaller Alpine Linux.

Some of its notable features (and you can tell me or better even the maintainers of the image if you need more) are

  • Meteor 1.x package/bundle support
  • The ability to pull in a Git-based repository + branch/tag (including SSH)
  • The ability to pull in a Bundle via URL
  • Support for docker-linked MongoDB or external MongoDB via URL
  • Non-root location of Meteor tree; the script will search for the first .meteor directory
  • PhantomJS pre-installed to support spiderable package

Testing It Locally


First I wanted to get it running locally using Docker Compose, so we know it really works. That was actually pretty straight forward.

Here is the docker-compose.yml file:

meteor:
  image: ulexus/meteor
  ports:
   - "80:80"
  links:
   - mongo
  environment:
   - REPO=https://github.com/Differential/meteor-boilerplate
   - ROOT_URL=http://192.168.59.103
mongo:
  image: mongo
  ports:
  - "27017:27017"

The meteor component just needs to know the port it exposes, that it’s linked to a MongoDB component called mongo and some additional environment variables first to get some code into the container and second to tell the container where it will be available to the outside. Here I’m currently using my local boot2docker IP as I’m on a Mac. The mongo component runs a simple MongoDB using the official image from the Docker Hub.

The part where it comes to getting writing some Meteor code to run in that container was actually not trivial for me, because, as I mentioned above, I’ve never worked with Meteor before. Luckily, I found a nice boilerplate Meteor application on GitHub that could be easily pulled into the container by the above-mentioned image.

Now a simple docker-compose up and the Meteor application is running. Be sure to replace the ROOT_URL environment variable with the IP of your docker host (mine runs in boot2docker, so it’s http://192.168.59.103).


Deploying to Production


Now that we have it running with Docker Compose, it’s a very small step to getting it deployed to production, once you have a Giant Swarm account. You just need to translate your docker-compose.yml into a swarm.json. You can use CYtoSJ for that, a little command line tool. However, for such a short file it’s also quite simple to write it yourself:

{
  "name": "meteor-test",
  "components": {
    "meteor-test": {
      "image": "ulexus/meteor",
      "ports": [
        80
      ],
      "env": [
        "REPO=https://github.com/Differential/meteor-boilerplate",
        "ROOT_URL=http://meteor-puja.gigantic.io"
      ],
      "domains": {
        "80/tcp": [
          "meteor-puja.gigantic.io"
        ]
      },
      "links": [
        {
          "component": "mongo",
          "target_port": "27017/tcp"
        }
      ]
    },
    "mongo": {
      "image": "mongo",
      "ports": [
        27017
      ]
    }
  }
}

The only small thing that changed is that our application now gets a real domain, which we have to define and then also give to Meteor through the environment variable. Everything else is pretty straight forward. A simple swarm up and it’s deployed and running under your desired domain.

Now, if you want to deploy your own Meteor application in this way, it’s 3 easy steps:

  1. Get the swarm.json and save it to your local directory.
  2. Edit the swarm.json to reflect your Meteor project’s GitHub URL1 and desired domain.
  3. swarm up
  4. Profit

Voilá, you have just deployed your Meteor application to production (or testing/staging). If everything goes right, this process shouldn’t take you more than 1 minute. If you think that’s cool, but you don’t have a Giant Swarm account, yet, be sure to request an invite. If you need help with using the image, you can find all details in the according GitHub repo. And if you have anything else you want to tell us, feel free to comment below or contact us directly.

  1. You can add an SSH-key or a custom (non-GitHub) Bundle-URL through the other environment variables detailed on the image’s Docker Hub page.  2