Farmbot-Web-App/DEPLOYMENT.md

5.3 KiB

Run on a Local Machine (fast)

If you want to run a server on a LAN for personal use, this is the easiest and cheapest option.

Simplicity: ❤️❤️❤️ Reliability: 💔 Affordability: ❤️❤️❤️

  1. Follow the developer setup guide.

Deployment to Dokku (cheap)

DEPRECATION NOTICE / PULL REQUESTS WELCOME: We no longer deploy the server using Dokku. The instructions related to MariaDB are out of date (we use Postgresql now). If you wish to use Dokku we would be happy to help you along the way. Please raise an issue if you would like to help with updating the deployment docs.

Simplicity: 💔 Reliability: ❤️❤️ Affordability: ❤️❤️

  1. Provision a fresh Ubuntu 16 server. We recommend DigitalOcean's "Ubuntu 16 docker" image. Make sure you have at least 1gb of memory. Don't use the Dokku image that Digital Ocean provides. It is out of date and will not support this application.
  2. Install the latest version of Dokku onto the machine
  3. Visit the server's URL in a browser. Follow the directions on screen to setup Dokku.
  4. git remote add my_server dokku@my_server_name:my_app_name
  5. Install mariaDB plugin: instructions.
  6. Create the Dokku app (if you didn't do it already). ssh dokku@my_server_name apps:create my_app_name.
  7. Give Dokku a place to store RSA keys: ssh dokku@my_server_name storage:mount my_app_name /var/lib/dokku/data/keys:/keys.

(Out of date. Help welcome)7. Create a databse: ssh dokku@my_server_name mariadb:create my_db_name

(Out of date. Help welcome)8. Link the DB: ssh dokku@my_server_name mariadb:link my_db_name my_app_name

  1. Set ENV vars to real values (See full instructions in the README)

  2. ssh dokku@my_server_name config:set my_app_name DEVISE_SECRET=$(rake secret) API_HOST=yourdomain.com API_PORT=1234

  3. Deploy the app: git push dokku@my_server_name:my_app_name master

  4. (optional) In case of failure, redeploy after performing the following:

  • dokku trace on (sets dokku to debug mode).
  • dokku config:set --global CURL_TIMEOUT=600
  • dokku config:set --global CURL_CONNECT_TIMEOUT=30
  1. Migrate the database: ssh dokku@my_server_name run my_app_name rake db:setup
  2. Your API is ready to go! You probably need to deploy the MQTT server next.

Deployment Using Heroku (good)

Simplicity: ❤️❤️❤️❤️ Reliability: ❤️❤️❤️❤️ Affordability: 💔

  1. Deploy as you would normally deploy to Heroku
  2. Enable Dyno metadata: heroku labs:enable runtime-dyno-metadata --app <app name> (we need this to know the version number of the web app).

Don't forget to set ENV vars and run heroku run rake db:setup.

Setting up SSL

Before setting up SSL, setup your domain on Heroku.

Install Certbot.

Run sudo certbot certonly --manual

Wait until you see this message and DO NOT CONTINUE:

Make sure your web server displays the following content at
http://yourdomain.io/.well-known/acme-challenge/SOME-LONG-URL before continuing:

ya6k1edW38z-CopyThisValueNow!!!

Set the ACME_SECRET ENV var to the value shown above (yours will be different) and restart your API process. On heroku, do heroku ps:restart --app=MY-APP-NAME-HERE

Once you have restarted the API process, continue through the installer.

You should see this:

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/yourdomain.io/fullchain.pem

Heroku Users: Run the following snippet to submit the certs to Heroku:

First time:

heroku certs:add /etc/letsencrypt/live/yourdomain.io/fullchain.pem /etc/letsencrypt/live/yourdomain.io/privkey.pem

After that:

sudo heroku certs:update /etc/letsencrypt/live/staging.farmbot.io/fullchain.pem /etc/letsencrypt/live/staging.farmbot.io/privkey.pem --app=farmbot-staging

Heroku will then give you instructions on which DNS records you must create.

Dokku Users: FarmBot, Inc. no longer uses Dokku. As such, our ability to troubleshoot problems is limited. Please raise an issue to receive community support.

Renew SSL Certificates

  1. Run sudo certbot certonly --manual -d YOUR_DOMAIN_HERE
  2. Wait for this message:

Make sure your web server displays the following content at
http://staging.farmbot.io/.well-known/acme-challenge/<CODE_HERE> before continuing:

3tFAi5c7tJK-YOURS\_WILL\_BE\_DIFFERENT

  1. Set the ACME_SECRET ENV var to the value shown above (yours will be different). Process restart may be required if you are not on Heroku!
heroku config:set ACME_SECRET=THAT_BIG_CODE_FROM_PREVIOUS_STEP --app=YOUR_APP_HERE
  - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/staging.farmbot.io/fullchain.pem.
  1. (Heroku users only) sudo heroku certs:update /etc/letsencrypt/live/YOUR_DOMAIN_HERE/fullchain.pem /etc/letsencrypt/live/YOUR_DOMAIN_HERE/privkey.pem