Skip to content

Instantly share code, notes, and snippets.

@99darwin
Created January 11, 2019 19:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 99darwin/cf037e9d74b955c51341b026d1ea1a3d to your computer and use it in GitHub Desktop.
Save 99darwin/cf037e9d74b955c51341b026d1ea1a3d to your computer and use it in GitHub Desktop.
Deploy Meteor App with MUP and Migrate Local MongoDB to Remote Server

Deploy Meteor app and migrate the built-in, local MongoDB to a remote server where the app is hosted.

It took me days to actually get this working, so I figured I would write out the steps I took to finally resolve the issue for my own assistance in the future and, hopefully, to help others who encounter this problem.

Create .deploy folder in your app's directory

cd .deploy
mup init

Configure the mup.js file to match your configuration. Here's an extremely basic example:

module.exports = {
  servers: {
    one: {
      // TODO: set host address, username, and authentication method
      host: 'remote_server_ip',
      username: 'root',
      pem: '~/.ssh/pem'
      // password: 'server-password'
      // or neither for authenticate from ssh-agent
    }
  },

  app: {
    // TODO: change app name and path
    name: 'your_apps_name',
    path: '../',

    servers: {
      one: {},
    },

    buildOptions: {
      serverOnly: true,
    },

    env: {
      // TODO: Change to your app's url
      // If you are using ssl, it needs to start with https://
      ROOT_URL: 'http://examplesub.domain.com',
      MONGO_URL: 'mongodb://mongodb:27017/meteor',
      MONGO_OPLOG_URL: 'mongodb://mongodb/local',
    },

    docker: {
      // change to 'abernix/meteord:base' if your app is using Meteor 1.4 - 1.5
      image: 'abernix/meteord:node-8.4.0-base',
      args: [
        '--link=mongodb:mongodb'
      ]
    },

    // Show progress bar while uploading bundle to server
    // You might need to disable it on CI servers
    enableUploadProgressBar: true
  },

  mongo: {
    version: '4.0.2',
    servers: {
      one: {}
    }
  },

  // (Optional)
  // Use the proxy to setup ssl or to route requests to the correct
  // app when there are several apps

  // proxy: {
  //   domains: 'mywebsite.com,www.mywebsite.com',

  //   ssl: {
  //     // Enable Let's Encrypt
  //     letsEncryptEmail: 'email@domain.com'
  //   }
  // }
};

Now backup the local database. *Note: Your app must be running, so start the Meteor server before performing the following actions

From your app's directory run mongodump -h 127.0.0.1 --port 3001 -d meteor -o ../dumpfile This creates a dump of the meteor database on directory above your project's root using the localhost connection on port 3001 (default)

Copy the local zip up the local dumpfile

cd ..
tar -czvf dumpfile.tar.gz dumpfile/meteor

Copy it to your remote server

scp -r dumpfile.tar.gz root@server_ip:~

SSH into your server

ssh root@server_ip

Unzip the database

tar -xzvf dumpfile.tar.gz

Copy the dumpfile into the docker container

docker cp dumpfile/meteor mongodb:dumpfile

Enter the bash shell of the docker container

docker exec -it mongodb bash

Restore the database and drop any irrelevant data that may already exist

mongorestore --drop -d APP_NAME dumpfile
@AfaaqSuhail
Copy link

Thanks. Very Helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment