Shuffle files around better, remove more legacy references. Ready for one last QA round

pull/1003/head
Rick Carlino 2018-10-02 08:57:59 -05:00
parent 35e384cf91
commit b2c3bc1ff9
16 changed files with 44 additions and 65 deletions

4
.gitignore vendored
View File

@ -13,8 +13,8 @@ erd_diagram.png
erd.pdf
latest_corpus.ts
log/*.log
mqtt/rabbitmq.conf
mqtt/rabbitmq.config
docker_configs/rabbitmq.conf
docker_configs/rabbitmq.config
node_modules
node_modules/
package-lock.json

View File

@ -4,23 +4,23 @@ Parts of this document may be out of date or reflect practices that are no longe
Please raise an issue if you hit any issues during deployment.
# Run on a Local Machine (saves time)
# Run on a Local Machine
If you want to run a server on a LAN for personal use, this is the easiest and cheapest option.
**Simplicity:** :heart::heart::heart:
**Simplicity:** :heart: :heart: :heart:
**Reliability:** :broken_heart:
**Affordability:** :heart::heart::heart:
**Affordability:** :heart: :heart: :heart:
1. Follow the [developer setup guide](https://github.com/FarmBot/Farmbot-Web-App#q-how-do-i-setup-an-instance-locally).
# Deployment Using Heroku (best reliability)
**Simplicity:** :heart::heart::heart::heart:
**Simplicity:** :heart: :heart: :heart: :heart:
**Reliability:** :heart::heart::heart::heart:
**Reliability:** :heart: :heart: :heart: :heart:
**Affordability:** :broken_heart:
@ -28,4 +28,4 @@ If you want to run a server on a LAN for personal use, this is the easiest and c
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).
3. (If emails are enabled) Enable the [Heroku scheduler](https://elements.heroku.com/addons/scheduler) and configure it to run `rake api:log_digest` every 10 minutes. This is required for Device log digests via email.
Don't forget to [set ENV vars](https://devcenter.heroku.com/articles/config-vars) as you would normally do with `application.yml` and run `heroku run rake db:setup`.
Don't forget to [set ENV vars](https://devcenter.heroku.com/articles/config-vars) and run `heroku run rake db:setup`.

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2015 Farmbot.io
Copyright (c) 2018 Farmbot.io
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -11,12 +11,13 @@
This repository is intended for *software developers* who wish to modify the [Farmbot Web App](http://my.farmbot.io/). **If you are not a developer**, you are highly encouraged to use [the publicly available web app](http://my.farmbot.io/). Running a server is *a non-trivial task with security implications*. It requires an intermediate background in Ruby, SQL and Linux system administration.
If you are a developer interested in contributing or would like to provision your own server, you are in the right place.
We do not have the resources available to help novice developers learn to setup servers, environments, configurations, or perform basic Linux command line instructions.
If you raise an issue indicating that you haven't followed the setup instructions, looked through past issues, or done a cursory internet search for basic help, expect the issue to be closed and we'll point you to the setup instructions. *Again, if you do not have at least intermediate Linux and Ruby experience, please use the hosted version of the web app at my.farm.bot.* Running a self-hosted server is not easy!
If you are a developer interested in contributing or would like to provision your own server, you are in the right place.
# Q: Where do I report security issues?
We take security seriously and value the input of independent researchers. Please see our [responsible disclosure guidelines](https://farm.bot/responsible-disclosure-of-security-vulnerabilities/).
@ -33,25 +34,21 @@ For a list of example API requests and responses, see our [reference documentati
We provide example setup instructions for Ubuntu 18 [here](https://github.com/FarmBot/Farmbot-Web-App/blob/master/ubuntu_example.sh).
Installation was last tested against Ubuntu 18.04 in June of 2018 on an x86 based machine.
Installation was last tested against Ubuntu 18.04 in October of 2018 on an x86 based machine.
Our ability to help individual users with private setup is limited. Using the public server at http://my.farm.bot is the recommended setup for end users. Please see the top of this document for more information.
# Config Settings (important)
We try our best to follow the [12 Factor Methodology](https://12factor.net/). Part of that means using ENV variables as a means of [storing configuration](https://12factor.net/config). **Your server won't run without setting ENV variables first**.
We follow the [12 Factor Methodology](https://12factor.net/). As such, ENV variables are the primary means of [storing configuration](https://12factor.net/config). **Your server won't run without setting ENV variables first**.
You can accomplish this by setting the ENV variables directly from your shell / server management tool or by writing an `application.yml` file.
You can accomplish this by setting the ENV variables directly from your shell / server management tool or by writing an `.env` file in server's base directory.
See `config/application.example.yml` for a list of all the variables that must be set.
See `example.env` for a list of all the variables that must be set.
**Encryption keys**: Encryption keys will be auto-generated if not present. They can be reset using `rake keys:generate`. If `ENV['RSA_KEY']` is set, it will be used in place of the `*.pem` files. Useful for environments like Heroku, where file system access is not allowed.
**Encryption keys**: Encryption keys will be auto-generated if not present. They can be reset using `rake keys:generate`. If `ENV['RSA_KEY']` is set, it will be used in place of the `*.pem` files. This is useful for environments like Heroku and Docker, where file system access is not allowed.
# Want to Help?
[Low Hanging Fruit](https://github.com/FarmBot/Farmbot-Web-App/search?utf8=%E2%9C%93&q=todo). [Raise an issue](https://github.com/FarmBot/Farmbot-Web-App/issues/new?title=Question%20about%20a%20TODO) if you have any questions.
## Translating the web app into your language
# Translating the Web App into Your Language
Thanks for your interest in internationalizing the FarmBot web app! To add translations:
@ -59,3 +56,7 @@ Thanks for your interest in internationalizing the FarmBot web app! To add trans
0. Navigate to `/public/app-resources/languages` and run the command `node _helper.js yy` where `yy` is your language's [language code](http://www.science.co.il/Language/Locale-codes.php). Eg: `ru` for Russian.
0. Edit the translations in the file created in the previous step: `"phrase": "translated phrase"`.
0. When you have updated or added new translations, commit/push your changes and submit a pull request.
# Want to Help?
[Low Hanging Fruit](https://github.com/FarmBot/Farmbot-Web-App/search?utf8=%E2%9C%93&q=todo). [Raise an issue](https://github.com/FarmBot/Farmbot-Web-App/issues/new?title=Question%20about%20a%20TODO) if you have any questions.

View File

@ -14,8 +14,8 @@ class KeyGen
return rsa
end
# Heroku / 12Factor users can't store stuff on the file system. Store your pem
# file in ENV['RSA_KEY'] if that applies to you.
# Heroku / 12Factor users can't store stuff on the file system.
# Store your pem file in ENV['RSA_KEY'] if that applies to you.
def self.try_env
OpenSSL::PKey::RSA.new(ENV['RSA_KEY']) if ENV['RSA_KEY']
end

View File

@ -13,11 +13,7 @@ FarmBot::Application.configure do
config.log_level = :info
config.perform_caching = false
config.public_file_server.enabled = false
# config.after_initialize do
# Bullet.enable = true
# Bullet.console = true
# Bullet.rollbar = true if ENV["ROLLBAR_ACCESS_TOKEN"]
# end
# HACK AHEAD! Here's why:
# 1. FarmBot Inc. Uses Sendgrid for email.
# 2. FarmBot is an open source project that must be vendor neutral.

View File

@ -1,7 +1,7 @@
version: '3'
services:
mqtt: # ======================================================================
build: ./mqtt
build: ./docker_configs/rabbitmq.Dockerfile
ports:
- "5672:5672" # AMQP (RabbitMQ)
- "1883:1883" # MQTT
@ -17,7 +17,7 @@ services:
web: # ======================================================================
build:
context: .
dockerfile: docker-api.Dockerfile
dockerfile: docker_configs/api.Dockerfile
# Add the `rm -f` part to avoid "server is still running..." errors:
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -e development -p ${API_PORT:-3000} -b 0.0.0.0"
volumes:
@ -32,7 +32,7 @@ services:
webpack: # ===================================================================
build:
context: .
dockerfile: docker-api.Dockerfile
dockerfile: docker_configs/api.Dockerfile
command: ./node_modules/.bin/webpack-dev-server --config config/webpack.config.js
volumes:
- .:/farmbot
@ -46,7 +46,7 @@ services:
delayed_job: # ===============================================================
build:
context: .
dockerfile: docker-api.Dockerfile
dockerfile: docker_configs/api.Dockerfile
command: bundle exec rake jobs:work
volumes:
- .:/farmbot
@ -58,7 +58,7 @@ services:
log_digests: # ===============================================================
build:
context: .
dockerfile: docker-api.Dockerfile
dockerfile: docker_configs/api.Dockerfile
command: bundle exec rake api:log_digest
volumes:
- .:/farmbot
@ -70,7 +70,7 @@ services:
rabbit_jobs: # ===============================================================
build:
context: .
dockerfile: docker-api.Dockerfile
dockerfile: docker_configs/api.Dockerfile
command: bundle exec rails r lib/rabbit_workers.rb
volumes:
- .:/farmbot

View File

@ -1,17 +1,17 @@
require 'erb'
def needs_admin_password
raise "You must set an ADMIN_PASSWORD in application.yml."
raise "You must set an ADMIN_PASSWORD in `.env`."
end
puts "=== Setting config data"
CONFIG_PATH = "./mqtt"
CONFIG_PATH = "./docker_configs"
CONFIG_FILENAME = "rabbitmq.conf"
CONFIG_OUTPUT = "#{CONFIG_PATH}/#{CONFIG_FILENAME}"
NO_API_HOST = "\nYou MUST set API_HOST to a real IP address or " +
"domain name (not localhost).\n" +
"API_PORT is also mandatory."
TEMPLATE_FILE = "./mqtt/rabbitmq.conf.erb"
TEMPLATE_FILE = "./docker_configs/rabbitmq.conf.erb"
TEMPLATE = File.read(TEMPLATE_FILE)
RENDERER = ERB.new(TEMPLATE)
PROTO = ENV["FORCE_SSL"] ? "https:" : "http:"
@ -26,6 +26,7 @@ if !ENV["API_HOST"] || !ENV["API_PORT"]
puts NO_API_HOST
exit
end
ok = RENDERER.result(binding)
# Write the config file.
File.write(CONFIG_OUTPUT, RENDERER.result(binding))
File.write(CONFIG_OUTPUT, ok)
puts ok

View File

@ -1,9 +1,9 @@
# Going to make an `update` AND `upgrade` task that do the same thing
def same_thing
sh "git pull https://github.com/FarmBot/Farmbot-Web-App.git master"
sh "bundle install"
sh "yarn install"
sh "rails db:migrate"
sh "sudo docker-compose run web bundle install"
sh "sudo docker-compose run web yarn install"
sh "sudo docker-compose run web rails db:migrate"
end
def check_for_digests
@ -31,12 +31,7 @@ namespace :api do
desc "Run Webpack and Rails"
task start: :environment do
sh "PORT=3000 bundle exec foreman start --procfile=Procfile.dev"
end
desc "Run Rails _ONLY_. No Webpack."
task only: :environment do
sh "PORT=3000 bundle exec foreman start --procfile=Procfile.api_only"
puts "Perhaps you meant `sudo docker-compose up`?"
end
desc "Pull the latest Farmbot API version"
@ -44,5 +39,4 @@ namespace :api do
desc "Pull the latest Farmbot API version"
task(upgrade: :environment) { same_thing }
end

View File

@ -1,13 +0,0 @@
namespace :mqtt do
desc "Bootstraps the MQTT config file. To force a rebuild of *everything*, " +
"set FORCE_REBUILD='true'"
task start: :environment do
begin
require_relative '../../mqtt/server.rb'
rescue Errno::ECONNREFUSED => e
puts "API is not up yet. Waiting 5 seconds..."
sleep 5
retry
end
end
end

View File

@ -11,7 +11,7 @@
"coverage": "cat **/*lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"clean": "rm -rf public/dist && rm -rf public/webpack",
"build": "TARGET=production bundle exec rake webpack:compile",
"start": "echo 'use `rails api:start`'",
"start": "echo 'use `sudo docker-compose up` instead.'",
"heroku-postbuild": "webpack --config=./config/webpack.prod.js",
"webpack": "./node_modules/.bin/webpack-dev-server --config config/webpack.dev.js",
"test-slow": "jest --coverage --no-cache -w 4",

View File

@ -79,7 +79,7 @@ RSpec.configure do |config|
require "capybara/rails"
require "capybara/rspec"
require "selenium/webdriver"
# Be sure to run `RAILS_ENV=test rails api:start` and `rails mqtt:start`!
# Be sure to run the server in a seperate window!
Capybara.run_server = false
Capybara.app_host = "http://localhost:3000"
Capybara.server_host = "localhost"

View File

@ -38,9 +38,9 @@ sudo docker-compose run web npm install
sudo docker-compose run web bundle exec rails db:setup
# Generate a set of *.pem files for data encryption
sudo docker-compose run web rake keys:generate
# Manually create the rabbitmq.conf file
# Manually create the rabbitmq.conf file.
# TODO: Improve this step -RC 1 Oct 18
sudo docker-compose run web bundle exec rails r mqtt/server.rb
sudo docker-compose run web bundle exec rails r docker_configs/rabbitmq_config_builder.rb
# Build the UI assets via WebPack
sudo docker-compose run web npm run build
# Run the server! ٩(^‿^)۶