Skip to content

Commit

Permalink
TODO: Try DATABASE_URL instead of database.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
RickCarlino committed Oct 1, 2018
1 parent aa70438 commit 8badc9c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 110 deletions.
24 changes: 13 additions & 11 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
FarmBot::Application.configure do
config.force_ssl = true if ENV["FORCE_SSL"]
config.perform_caching = false
config.cache_store = :null_store
config.action_mailer.default_url_options = { host: ENV.fetch("API_HOST", "my.farmbot.io") }
config.active_support.deprecation = :notify
config.cache_classes = true
config
.action_mailer
.default_url_options = { host: ENV.fetch("API_HOST", "my.farmbot.io") }
config.active_support.deprecation = :notify
config.cache_classes = true
config.cache_store = :null_store
config.consider_all_requests_local = false
config.eager_load = true
config.i18n.fallbacks = true
config.log_formatter = ::Logger::Formatter.new
config.log_level = :info
config.public_file_server.enabled = false
config.eager_load = true
config.force_ssl = true if ENV["FORCE_SSL"]
config.i18n.fallbacks = true
config.log_formatter = ::Logger::Formatter.new
config.log_level = :info
config.perform_caching = false
config.public_file_server.enabled = false
# config.after_initialize do
# Bullet.enable = true
# Bullet.console = true
Expand Down
54 changes: 13 additions & 41 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -1,44 +1,16 @@
FarmBot::Application.configure do
# config.after_initialize do
# Bullet.enable = true
# Bullet.console = true
# Bullet.raise = true
# end

# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true

# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = true

# Configure static asset server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
config.assets.debug = true
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false

# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
config.active_job.queue_adapter = :inline

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

config.log_level = :error
config.action_controller.perform_caching = false
config.action_dispatch.show_exceptions = false
config.action_mailer.delivery_method = :test
config.active_job.queue_adapter = :inline
config.active_support.deprecation = :stderr
config.assets.debug = true
config.cache_classes = true
config.consider_all_requests_local = true
config.eager_load = false
config.log_level = :error
config.public_file_server.enabled = true
config.public_file_server.headers = \
{ 'Cache-Control' => 'public, max-age=3600' }
end
12 changes: 6 additions & 6 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ API_PORT="3000"
# Most users can just delete it.
# This is used for people writing modifications to the software, mostly.
DOCS="Set this to any value if you want to generate API docs after running tests"
# Most users can delete this.
# Used by people who pay for managed database hosting.
# Most users can delete this.
DATABASE_URL="postgres://USERNAME:PASSWORD@URL:PORT/DB_NAME"
# MUST REPLACE.
# Generate a secret by typing `rake secret` into the console.
DEVISE_SECRET="Used for devise. Use `rake secret` to generate a new value."
# MUST REPLACE. MUST BE A VERY RANDOM VALUE.
# 128 CHARACTERS LONG, HEXADECIMAL STRING (0-9, A-F)
DEVISE_SECRET="Used for devise. Generate a new value using `openssl rand -hex 64`."
# Most personal server users can delete this.
FORCE_SSL="Remove this if not using HTTPS://"
# FarmBot OS update server. Use default if you don't have a special use case.
Expand All @@ -51,9 +51,9 @@ GCS_ID="GOOGLE_CLOUD_STORAGE='interop' id"
GCS_KEY="GOOGLE_CLOUD_STORAGE='interop' key"
# Most self hosting users will want to delete this.
HEROKU_SLUG_COMMIT="This is set by Heroku, used by Frontend to show current version."
# Where is your MQTT server running?
# Where is your MQTT server running? 99% of setups will use the same value
# found in API_HOST. Heroku users will not use the same value.
# Use a REAL IP ADDRESS if you are controlling real bots.
# 0.0.0.0 is only OK for software testing. Change this!
MQTT_HOST="98.76.54.32"
# Same as above. Can be deleted unless you are a Rollbar.IO customer.
ROLLBAR_ACCESS_TOKEN="____"
Expand Down
60 changes: 12 additions & 48 deletions mqtt/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@ def needs_admin_password
raise "You must set an ADMIN_PASSWORD in application.yml."
end

puts "=== Retrieving container info"
DOCKER_IMG_NAME = "farmbot-mqtt"
IMG_IS_BUILT = `cd mqtt; sudo docker images`.include?(DOCKER_IMG_NAME)

puts "=== Setting config data"
CONFIG_PATH = "./mqtt"
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.read(TEMPLATE_FILE)
RENDERER = ERB.new(TEMPLATE)
PROTO = ENV["FORCE_SSL"] ? "https:" : "http:"
VHOST = ENV.fetch("MQTT_VHOST") { "/" }
admin_password = ENV.fetch("ADMIN_PASSWORD") { needs_admin_password }
CONFIG_PATH = "./mqtt"
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.read(TEMPLATE_FILE)
RENDERER = ERB.new(TEMPLATE)
PROTO = ENV["FORCE_SSL"] ? "https:" : "http:"
VHOST = ENV.fetch("MQTT_VHOST") { "/" }
admin_password = ENV.fetch("ADMIN_PASSWORD") { needs_admin_password }

needs_admin_password if admin_password.length < 5

Expand All @@ -33,35 +29,3 @@ def needs_admin_password

# Write the config file.
File.write(CONFIG_OUTPUT, RENDERER.result(binding))

# Re-init docker stuff

processes = `sudo docker ps -a -f "name=farmbot-mqtt" -q`

if processes.present?
puts "=== Stopping pre-existing farmbot containers"
sh "cd mqtt && sudo docker stop #{processes}"
sh "cd mqtt && sudo docker rm #{processes}"
end

if IMG_IS_BUILT
puts "=== Destroying old docker images"
sh "cd mqtt; sudo docker rmi #{DOCKER_IMG_NAME} --force"
end

puts "=== Building docker image"
sh "cd mqtt; sudo docker build -t farmbot-mqtt ."

puts "=== Starting MQTT"

exec [
'cd mqtt;',
'sudo docker run',
'-p "5672:5672"', # AMQP (RabbitMQ)
'-p "1883:1883"', # MQTT
'-p "8883:8883"', # MQTT over TLS/SSL
'-p "3002:15675"', # MQTT over WebSockets
'-p "15672:15672"', # Management API
'--name "farmbot-mqtt"',
'farmbot-mqtt'
].join(" ")
11 changes: 7 additions & 4 deletions new_ubuntu_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ cd Farmbot-Web-App
# Open `config/application.yml` in a text editor and change all the values.
#
# == Nothing will work if you skip this step!!! ==
# Don't know which text editor to use?
# Use micro! `snap install micro --classic`
#
# BE SURE TO READ `application.yml` AND CHANGE THE VALUES
# READ `example.env` AND CHANGE THE VALUES. SAVE RESULTS TO `.env`!
# This is the most important step ^

snap install micro --classic # Don't like `micro`? vim, nano, etc are fine, too.
# READ NOTE ABOVE. Very important!
# SAVE THIS FILE AS `.env` WHEN FINISHED!
nano example.env
sudo docker-compose build
bundle install
docker-compose run web bundle install
yarn install
cp config/database.example.yml config/database.yml
cp config/application.example.yml config/application.yml
Expand Down

0 comments on commit 8badc9c

Please sign in to comment.