Advanced Deployment

Introduction

This article is based upon this guide and the following method is only applicable to deployment on Heroku.

Prerequisites

First you will need to create a Heroku account, install gitandheroku-cli . Heroku provides an installation package that does this for you. Please follow the following guides on how to do so:

Signup for Heroku

Download and install Heroku CLI

Download and install git

Instructions to deploy QMethod App to Heroku

Creating Git Directory

Open a new command line window (or terminal) and cd into a directory to temporarily hold the files for your QMd app. Then run git clone -b https://github.com/CITS3200GroupD/QMethod.git

cd <path/to/your/directory>
git clone -b master https://github.com/CITS3200GroupD/QMethod.git
Cloning into 'QMd'...
remote: Counting objects: 2302, done.
remote: Compressing objects: 100% (427/427), done.
remote: Total 2302 (delta 324), reused 177 (delta 32), pack-reused 1828
Receiving objects: 100% (2302/2302), 2.11 MiB | 1.19 MiB/s, done.
Resolving deltas: 100% (890/890), done.
Checking out files: 100% (76/76), done.

Now cd QMethod into the newly created QMd folder for the next step.

path/to/dir> cd QMd
path/to/dir/QMd>

Setting up Heroku CLI

If you have not already, sign up for a heroku account and install the heroku CLI. Then, in the samw command line interface window you are already in, enter heroku --version to verify that you have heroku-cli installed.

heroku --version
heroku/7.0.0 (darwin-x64) node-v8.0.0

Next, enter heroku login and you will be prompted for your heroku account details.

heroku login
Enter your Heroku credentials.
Email: adam@example.com
Password (typing will be hidden):
Authentication successful.

(The CLI saves your email address and an API token to ~/.netrc for future use. For more information, see Heroku CLI Authentication.)

Now ensuring that your terminal window is open in the same path as the directory holding the QMethod source files, run heroku create <APP NAME>. (Replace APP NAME with the desired name of your application (will appera in url)).

You can use git remote -v to verify that this has been completed successfully.

heroku create qmd-test1app
Creating app... done, ⬢ thawing-inlet-61413
https://thawing-inlet-61413.herokuapp.com/ | https://git.heroku.com/qmd-test1app.git
git remote -v
heroku  https://git.heroku.com/qmd-test1app.git (fetch)
heroku  https://git.heroku.com/qmd-test1app.git (push)

We are now almost done with the setup for Heroku, and all we have to do is call git push heroku master to setup the front-end application.

If you do so you notice that the application will install and load as expected at first glance, however this will result in an error as we have yet to configure the remote mongoDB Database.

Thus before we push the files to Heroku we should create a remote database and link this to our heroku application.

Setting up your database

We will be hosting the data from our survey on a separate remote host. This can be done either through MongoDB Atlas or mLab.

Mongo Atlas

First, go to MongoDB Atlas and sign up for a free account. MongoDB Atlas is a Database as a Service provider that provides encrypted remote mongoDB instances, which we will use to store the survey recipient data, with free and paid tiers of service. MongoDB Atlas clusters make use of the General Purpose SSD (gp2) EBS volumes, with AES-256 encryption.. All communication to and from the server is also encrypted from MOTM attacks through the use of TLS/SSL socket security.

Next, select your server provider. It is recommended that you select the free AWS service tier (M0) with 512MB of storage. (This is in fact approximately enough for at least ~250,000 survey responses and thus should be sufficient even for live deployment.)

Now, after your cluster has finished initialising, go to the Security > MongoDB Users Tab and add a new user.

Enter a username (such as admin) and a password. This will be used by the application itself in a driver to access your database. Ensure that Read and Write access is checked. Please remember and copy down this password and save it for later, as you will need this information later.

Now go to the Security > IP Whitelist tab, and add a new IP Address.

You will want to repeat this process twice, as you will need to allow access firstly from your own IP address, as well as any IP address (for now). This is because the free version of the Heroku application uses a dynamic IP address which changes from time to time, whilst paid tiers of Heroku allow for a fixed static IP, which we can later add to the whitelist (whilst removing the 0.0.0.0/10 entry) for better security later on.

At this point, if you wish to connect to a desktop client for viewing your remote database data directly (not through the QMd application, you may install MongoDB Compass and follow the MongoDB Compass Install guide.

Now, go back to the Clusters > Overview page and click connect.

We will now need to generate the string for our application's mongoDB driver.

Copy this string to your clipboard. We will now be going back to our Heroku CLI terminal window and inputting this to link our database to our heroku application.

Generating Secure Elements

As we have a login gate, in addition to providing both a user/password pair that is valid to allow for administrator access to our application, as well as generate 2048 bit RSA-256 keys for the purposes of encryption and authentication of admin logins.

To generate the RSA keys, the easiest method would be to use an online RSA key generator such as JSEncrypt.

However, for better security, it is advisable to generate the RSA keys on your local machine using OpenSSL. Once installed, open a command line window and run the following code

openssl genrsa -out private.key openssl rsa -in private.key -pubout > public.key

In the root folder of your terminal window, two new files will be generated corresponding to the private and public keys. You may open these files with notepad and save them for later.

Back to Heroku

Now that our database has been fully setup, including a compass client for monitoring and viewing raw database data, we can now link our application to the mongoDB database.

heroku config:set MONGODB_URI=mongodb://<link you copied from above> PRIVATE_KEY=<private.key> PUBLIC_KEY=<public.key> ADMIN_LOGIN_NAME=<USERNAME> ADMIN_LOGIN_PASSWORD=<PASSWORD>

Now that the database has been linked, we can run git push heroku master. This will push the files to Heroku and deploy the application at the given URL. Open the URL in your browser. It may take some time to load as the server has to "wake up" first (free Heroku apps go to sleep after 30 minutes).

Custom Domain Names

https://devcenter.heroku.com/articles/custom-domains

By default, a Heroku app is available at its Heroku domain, which has the form [name of app].herokuapp.com. For example, an app named serene-example-4269 is hosted at serene-example-4269.herokuapp.com.

To make your app available at a non-Heroku domain (for example, www.yourcustomdomain.com), you add a custom domain to it.

You can add custom domains to any Heroku app for free (however the domain name itself will have to be paid for). For security purposes, you must verify your Heroku account to add domains to apps.

Heroku does not provide a domain registration service (for registering a custom domain name) or a DNS provider service (for hosting the DNS servers that point your custom domain name to your app).

Exporting Raw JSON data from Database

Compass allows you to export and import raw database information as a json. This may be useful to store data on your local machine instead of a remote instance.

Last updated