Host Outerbridge via AWS

Launch EC2 Instance

This walkthrough will skip how to launch an EC2 instance. There's plenty of resources and tutorial on how to do that. In this case we are launching a EC2 instance with t2.micro.

After EC2 instance has successfully spinned up, SSH into EC2 instance.

Install Docker

  1. Apply pending updates using the yum command:

    sudo yum update
  2. Search for Docker package:

    sudo yum search docker
  3. Get version information:

    sudo yum info docker
  4. Install docker, run:

    sudo yum install docker
  5. Add group membership for the default ec2-user so you can run all docker commands without using the sudo command:

    sudo usermod -a -G docker ec2-user
    id ec2-user
    newgrp docker
  6. Install docker-compose:

    sudo yum install python3-pip
    sudo pip3 install docker-compose
  7. Enable docker service at AMI boot time:

    sudo systemctl enable docker.service
  8. Start the Docker service:

    sudo systemctl start docker.service

Install Git

sudo yum install git -y

Setup

  1. git clone https://github.com/Outerbridgeio/Outerbridge.git
  2. cd Outerbridge && cd docker
  3. docker-compose up -d
  4. App is now ready on port 3000.

  5. To view the app, create 2 new inbound rules on the EC2 instance. Custom TCP Port 3000 that allows anywhere to access.

  6. You can then view the app: "Your Public IPv4 DNS":3000. Example: http://ec2-18-222-246-22.eu-west-1.compute.amazonaws.com:3000

  7. You can bring the app down by:

    docker-compose stop
  8. You can pull from latest image by:

    docker pull outerbridgeio/outerbridge

Using NGINX

If you want to get rid of the :3000 on the url and have a custom domain, you can use NGINX to reverse proxy port 80 to 3000 So user will be able to open the app using your domain. Example: http://yourdomain.com.

  1. sudo amazon-linux-extras install -y nginx1
  2. nginx -v
  3. sudo systemctl start nginx
  4. sudo nano /etc/nginx/conf.d/outerbridge.conf
  5. Copy paste the following and change to your domain:

    server {
    listen 80;
    listen [::]:80;
    server_name yourdomain.com; #Example: demo.outerbridge.io
    location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_cache_bypass $http_upgrade;
    }
    }
  6. sudo systemctl restart nginx
  7. Go to your DNS provider, and add a new A record with IP address using Public IPv4 address from EC2 instance.

  8. You should now be able to open the app: http://yourdomain.com.

  9. You can proceed to delete the 2 custom ports 3000 TCP inbound rules. They won't be needed anymore.

Install Certbot to have HTTPS

If you like your app to have https://yourdomain.com. Here is how:

  1. sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  2. sudo yum-config-manager --enable epel
  3. sudo yum install certbot python2-certbot-nginx
  4. certbot --version
  5. sudo certbot --nginx
  6. If cert expired, simply renew:

    sudo certbot renew --dry-run
  7. You can now open the app: https://yourdomain.com.

Backup MongoDB

You can backup MongoDB database into S3 bucket. Here is the article that can be followed:

  1. sudo yum --enablerepo epel install s3cmd
  2. s3cmd --configure
  3. sudo nano mongo_backup.sh
  4. Copy paste and replace values:

    #!/bin/bash
    #Force file syncronization and lock writes
    mongo admin --eval "printjson(db.fsyncLock())"
    MONGODUMP_PATH="/usr/bin/mongodump"
    MONGO_DATABASE="dbname_here" #replace with your database name
    TIMESTAMP=`date +%F-%H%M`
    S3_BUCKET_NAME="bucketname_here" #replace with your bucket name on Amazon S3
    S3_BUCKET_PATH="mongodb-backups"
    # Create backup
    $MONGODUMP_PATH -d $MONGO_DATABASE
    # Add timestamp to backup
    mv dump mongodb-$HOSTNAME-$TIMESTAMP
    tar cf mongodb-$HOSTNAME-$TIMESTAMP.tar mongodb-$HOSTNAME-$TIMESTAMP
    # Upload to S3
    s3cmd put mongodb-$HOSTNAME-$TIMESTAMP.tar s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/mongodb-$HOSTNAME-$TIMESTAMP.tar
    #Unlock database writes
    mongo admin --eval "printjson(db.fsyncUnlock())"
    #Delete local files
    rm -rf mongodb-*
  5. bash mongo_backup.sh
  6. Go to S3 bucket, you should see a tar file.

  7. Setup cron

    crontab -e
  8. Copy paste:

    #1st of every month at 9 am
    00 09 1 * * /bin/bash /home/ec2-user/mongo_backup.sh