Skip to content
This repository has been archived by the owner on Jul 9, 2019. It is now read-only.

Latest commit

 

History

History
98 lines (72 loc) · 2.77 KB

DEPLOYMENT.md

File metadata and controls

98 lines (72 loc) · 2.77 KB

How to Deploy

  1. Get a nice, fresh VM with Ubuntu 16. We recomend the one that comes pre-installed Docker on Digital Ocean.
  2. Install Docker if you didn't use Digital Ocean's docker image.. DigitalOcean offers an Ubuntu image that comes pre-installed with Docker.
  3. sudo docker build -t mqtt https://github.com/FarmBot/mqtt-gateway.git
  4. Run this:
sudo docker run -d \
                -e WEB_API_URL=http://YOUR_API_URL_HERE \
                -p 3002:3002 \
                -p 8883:8883 \
                -p 1883:1883 \
                -p 80:3002 \
                -p 443:443 \
                -v /etc/letsencrypt/:/etc/letsencrypt/ \
                --restart=always mqtt

Add this to command above if you use SSL:

    -e SSL_DOMAIN=YOUR_MQTT_SERVER_HOSTNAME_HERE

The server is now running.

Renewing SSL Certs with Let's Encrypt

NOTE: I have made a script, letsencrypt_renewal.sh to help.

Step 1

SSH into the runing docker container (docker exec -i -t CONTAINER_ID_HERE /bin/bash)

Step 2

Run letsencrypt renew within 90 day. There is a --force flag if you care to use it.

Step 3

Kill the container. docker kill CONTAINER_NAME. Re-run the container, this time with two extra ENV vars:

sudo docker run -d \
                -e WEB_API_URL=http://YOUR_API_URL_HERE \
                -e SSL_DOMAIN=YOUR_MQTT_URL_HERE \
                -e SSL_EMAIL=you@domain.com \
                -p 3002:3002 \
                -p 8883:8883 \
                -p 1883:1883 \
                -p 80:3002 \
                -p 443:443 \
                -v /etc/letsencrypt/:/etc/letsencrypt/ \
                --restart=always mqtt

Adding SSL to New Setups with Let's Encrypt

STEP 1:

SSH into the runing docker container (docker exec -i -t CONTAINER_ID_HERE /bin/bash)

STEP 2:

From inside the container, run:

letsencrypt certonly --webroot \
                    -w /app/public \
                    -d SSL_DOMAIN_HERE \
                    --text \
                    --non-interactive \
                    --agree-tos \
                    --email SSL_EMAIL_HERE

Step 3:

Exit from the shell session (exit) and set the SSL_DOMAIN.

You can accomplish this by running the same command during setup (see top of document), but this time add an additional flag to docker run:

sudo docker run -d \
                -e WEB_API_URL=http://YOUR_API_URL_HERE \
                -e SSL_DOMAIN=YOUR-MQTT-DOMAIN-HERE \
                -p 3002:3002 \
                -p 8883:8883 \
                -p 1883:1883 \
                -p 80:3002 \
                -p 443:443 \
                -v /etc/letsencrypt/:/etc/letsencrypt/ \
                --restart=always mqtt