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
Apply pending updates using the yum command:
sudo yum updateSearch for Docker package:
sudo yum search dockerGet version information:
sudo yum info dockerInstall docker, run:
sudo yum install dockerAdd 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-userid ec2-usernewgrp dockerInstall docker-compose:
sudo yum install python3-pipsudo pip3 install docker-composeEnable docker service at AMI boot time:
sudo systemctl enable docker.serviceStart the Docker service:
sudo systemctl start docker.service
Install Git
sudo yum install git -y
Setup
- git clone https://github.com/Outerbridgeio/Outerbridge.git
- cd Outerbridge && cd docker
- docker-compose up -d
App is now ready on port 3000.
To view the app, create 2 new inbound rules on the EC2 instance. Custom TCP Port 3000 that allows anywhere to access.
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
You can bring the app down by:
docker-compose stopYou 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
.
- sudo amazon-linux-extras install -y nginx1
- nginx -v
- sudo systemctl start nginx
- sudo nano /etc/nginx/conf.d/outerbridge.conf
Copy paste the following and change to your domain:
server {listen 80;listen [::]:80;server_name yourdomain.com; #Example: demo.outerbridge.iolocation / {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;}}- sudo systemctl restart nginx
Go to your DNS provider, and add a new A record with IP address using Public IPv4 address from EC2 instance.
You should now be able to open the app:
http://yourdomain.com
.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:
- sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- sudo yum-config-manager --enable epel
- sudo yum install certbot python2-certbot-nginx
- certbot --version
- sudo certbot --nginx
If cert expired, simply renew:
sudo certbot renew --dry-runYou 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:
- sudo yum --enablerepo epel install s3cmd
- s3cmd --configure
- sudo nano mongo_backup.sh
Copy paste and replace values:
#!/bin/bash#Force file syncronization and lock writesmongo admin --eval "printjson(db.fsyncLock())"MONGODUMP_PATH="/usr/bin/mongodump"MONGO_DATABASE="dbname_here" #replace with your database nameTIMESTAMP=`date +%F-%H%M`S3_BUCKET_NAME="bucketname_here" #replace with your bucket name on Amazon S3S3_BUCKET_PATH="mongodb-backups"# Create backup$MONGODUMP_PATH -d $MONGO_DATABASE# Add timestamp to backupmv dump mongodb-$HOSTNAME-$TIMESTAMPtar cf mongodb-$HOSTNAME-$TIMESTAMP.tar mongodb-$HOSTNAME-$TIMESTAMP# Upload to S3s3cmd put mongodb-$HOSTNAME-$TIMESTAMP.tar s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/mongodb-$HOSTNAME-$TIMESTAMP.tar#Unlock database writesmongo admin --eval "printjson(db.fsyncUnlock())"#Delete local filesrm -rf mongodb-*- bash mongo_backup.sh
Go to S3 bucket, you should see a tar file.
Setup cron
crontab -eCopy paste:
#1st of every month at 9 am00 09 1 * * /bin/bash /home/ec2-user/mongo_backup.sh