[STABLE] Update deployment instructions, docs, fix bug in token ISS claim.

pull/267/head
Rick Carlino 2016-09-14 11:57:03 -05:00
parent d6b16ff5d4
commit 08f1e90e8c
6 changed files with 22 additions and 6 deletions

View File

@ -1,7 +1,7 @@
# Deployment # Deployment
0. Create a fresh Ubuntu 16 server with Dokku (or just use DigitalOcean) 0. Provision a fresh Ubuntu 16 server (we use DigitalOcean's "Ubuntu 16 x64" image).
* Make sure you have atleast 1gb. * Make sure you have atleast 1gb.
0. [Install the latest version of Dokku (don't use that DigitalOcean image)](https://github.com/dokku/dokku#installing) 0. [Install the latest version of Dokku (don't use that DigitalOcean image)](https://github.com/dokku/dokku#installing)
0. Visit the server's URL in a browser. Follow the directions on screen to setup Dokku. 0. Visit the server's URL in a browser. Follow the directions on screen to setup Dokku.
@ -12,7 +12,11 @@
0. Create a databse: `ssh dokku@my_server_name mariadb:create my_db_name` 0. Create a databse: `ssh dokku@my_server_name mariadb:create my_db_name`
0. Link the DB: `ssh dokku@my_server_name mariadb:link my_db_name my_app_name` 0. Link the DB: `ssh dokku@my_server_name mariadb:link my_db_name my_app_name`
0. Set ENV vars (Set `JS\_FILE\_URL` and `MQTT_HOST` to real values): 0. Set ENV vars (Set `JS\_FILE\_URL` and `MQTT_HOST` to real values):
* `ssh dokku@my_server_name config:set my_app_name DEVISE_SECRET=$(rake secret) JS_FILE_URL=//mycdn.org/farmbot-fronted.js MQTT_HOST=my-mqtt-server.org` * `ssh dokku@my_server_name config:set my_app_name DEVISE_SECRET=$(rake secret) JS_FILE_URL=//mycdn.org/farmbot-fronted.js MQTT_HOST=my-mqtt-server.org API_HOST=yourdomain.com API_PORT=1234`
0. Deploy the app: `git push dokku@my_server_name:my_app_name master ` 0. Deploy the app: `git push dokku@my_server_name:my_app_name master `
0. (optional) If that didn't work, do this on the server and try pushing again:
* `dokku trace on` (sets dokku to debug mode).
* `dokku config:set --global CURL_TIMEOUT=600`
* `dokku config:set --global CURL_CONNECT_TIMEOUT=30`
0. Migrate the database: `ssh dokku@my_server_name run my_app_name rake db:setup` 0. Migrate the database: `ssh dokku@my_server_name run my_app_name rake db:setup`
0. Your API is ready to go! You probably need to deploy the MQTT server next. 0. Your API is ready to go! You probably need to deploy the MQTT server next.

View File

@ -37,7 +37,9 @@ Here are some of the configuration options you must set when provisioning a new
* `ENV['DEVISE_SECRET']`: Used for devise. Use `rake secret` to generate a new value. * `ENV['DEVISE_SECRET']`: Used for devise. Use `rake secret` to generate a new value.
* `ENV['MQTT_HOST']`: Host (no port or slashes or anything) of running [MQTT gateway](https://github.com/FarmBot/mqtt-gateway). This is required so that Farmbot can know where to connect when given an authorization token. * `ENV['MQTT_HOST']`: Host (no port or slashes or anything) of running [MQTT gateway](https://github.com/FarmBot/mqtt-gateway). This is required so that Farmbot can know where to connect when given an authorization token.
* `ENV['JS_FILE_URL']`: URL pointing to the [Farmbot Frontend](https://github.com/FarmBot/farmbot-web-frontend) `bundle.js` file. This is what gets injected into the `<script>` tag when the user visits `/app`. * `ENV['JS_FILE_URL']`: URL pointing to the [Farmbot Frontend](https://github.com/FarmBot/farmbot-web-frontend) `bundle.js` file. This is what gets injected into the `<script>` tag when the user visits `/app`.
* `ENV['API_HOST']`: Domain of the server. Default is `localhost`.
* `ENV['API_PORT']`: Port the server is on. Default is `3000`.
**We can't fix issues we don't know about.** Please submit an issue if you are having trouble installing on your local machine. **We can't fix issues we don't know about.** Please submit an issue if you are having trouble installing on your local machine.
## Running Specs ## Running Specs

View File

@ -1,5 +1,8 @@
module Users module Users
class Create < Mutations::Command class Create < Mutations::Command
HOST = Rails.application.routes.default_url_options[:host]
PORT = Rails.application.routes.default_url_options[:port]
required do required do
string :name string :name
string :email string :email
@ -25,7 +28,7 @@ module Users
resp.merge!(Auth::CreateToken.run!(email: email, resp.merge!(Auth::CreateToken.run!(email: email,
password: password, password: password,
host: "http://localhost:3000")) host: "http://#{ HOST }:#{ PORT }"))
end end
end end
end end

View File

@ -2,3 +2,5 @@
require File.expand_path('../application', __FILE__) require File.expand_path('../application', __FILE__)
# Initialize the Rails application. # Initialize the Rails application.
FarmBot::Application.initialize! FarmBot::Application.initialize!
Rails.application.routes.default_url_options[:host] = ENV["API_HOST"] || "localhost"
Rails.application.routes.default_url_options[:port] = ENV["API_PORT"] || 3000

View File

@ -1,6 +1,9 @@
FarmBot::Application.configure do FarmBot::Application.configure do
config.action_controller.perform_caching = false config.action_controller.perform_caching = false
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } config.action_mailer.default_url_options = {
host: Rails.application.routes.default_url_options[:host],
port: Rails.application.routes.default_url_options[:port]
}
config.active_support.deprecation = :log config.active_support.deprecation = :log
config.assets.debug = true config.assets.debug = true
config.cache_classes = false config.cache_classes = false

View File

@ -1,4 +1,6 @@
class SessionToken class SessionToken
HOST = Rails.application.routes.default_url_options[:host]
PORT = Rails.application.routes.default_url_options[:port]
EXPIRY = 4.days EXPIRY = 4.days
PRIVATE_KEY = KeyGen.current PRIVATE_KEY = KeyGen.current
PUBLIC_KEY = KeyGen.current.public_key PUBLIC_KEY = KeyGen.current.public_key
@ -19,7 +21,7 @@ class SessionToken
def self.issue_to(user, def self.issue_to(user,
iat: Time.now.to_i, iat: Time.now.to_i,
exp: EXPIRY.from_now.to_i, exp: EXPIRY.from_now.to_i,
iss: "http://localhost:3000") iss: "http://#{ HOST }:#{ PORT }")
self.new(sub: user.email, self.new(sub: user.email,
iat: iat, iat: iat,