2017-11-27 21:00:08 -07:00
|
|
|
# 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"
|
2018-10-02 07:57:59 -06:00
|
|
|
sh "sudo docker-compose run web bundle install"
|
2018-10-03 09:57:46 -06:00
|
|
|
sh "sudo docker-compose run web npm install"
|
2018-10-02 07:57:59 -06:00
|
|
|
sh "sudo docker-compose run web rails db:migrate"
|
2017-11-27 21:00:08 -07:00
|
|
|
end
|
2017-12-14 07:52:01 -07:00
|
|
|
|
2018-08-18 10:06:49 -06:00
|
|
|
def check_for_digests
|
|
|
|
Log
|
|
|
|
.where(sent_at: nil, created_at: 1.day.ago...Time.now)
|
|
|
|
.where(Log::IS_EMAIL_ISH)
|
|
|
|
.where
|
|
|
|
.not(Log::IS_FATAL_EMAIL)
|
|
|
|
.pluck(:device_id)
|
|
|
|
.uniq
|
|
|
|
.map do |id|
|
|
|
|
device = Device.find(id)
|
|
|
|
puts "Sending log digest to device \##{id} (#{device.name})"
|
|
|
|
LogDeliveryMailer.log_digest(device).deliver
|
|
|
|
end
|
2018-10-03 08:46:25 -06:00
|
|
|
sleep 10.minutes
|
2018-08-18 10:06:49 -06:00
|
|
|
end
|
|
|
|
|
2018-10-02 14:47:36 -06:00
|
|
|
class V7Migration
|
2018-10-02 16:01:48 -06:00
|
|
|
BIG_WARNING = <<~END
|
2018-10-02 14:47:36 -06:00
|
|
|
░██████░░███████░░█████░░░██████░░ You have recently upgraded your server
|
|
|
|
░██░░░░░░░░██░░░░██░░░██░░██░░░██░ from version 6 to version 7.
|
|
|
|
░██████░░░░██░░░░██░░░██░░██████░░ This requires action on your part.
|
|
|
|
░░░░░██░░░░██░░░░██░░░██░░██░░░░░░ Please read the instructions below
|
|
|
|
░██████░░░░██░░░░░████░░░░██░░░░░░ carefully.
|
|
|
|
|
2018-10-02 16:01:48 -06:00
|
|
|
The biggest change from version 6 to version 7 is the addition of Docker for
|
|
|
|
managing services. This simplifies server setup because all software runs
|
|
|
|
inside of a container (no need to install Postgres or Ruby on your local
|
|
|
|
machine). Unfortunately, this change required a number of non-compatible
|
|
|
|
changes to the codebase, particularly related to the database and
|
|
|
|
configuration management.
|
|
|
|
|
|
|
|
The biggest changes for v7:
|
|
|
|
* Use a `.env` file instead of `application.yml`
|
|
|
|
* The database runs in a container
|
|
|
|
* The `mqtt/` directory was renamed `docker_configs/` (this directory
|
|
|
|
contains passwords which were previously `gitignore`ed)
|
|
|
|
|
|
|
|
Please perform the following steps to upgrade:
|
|
|
|
|
|
|
|
1. Follow v7 installation steps found in "ubuntu_example.sh". You will need
|
|
|
|
to skip certain steps. The skipable steps are listed in the instructions.
|
2018-10-02 14:47:36 -06:00
|
|
|
|
|
|
|
2. Stop using `rails api:start` and `rails mqtt:start` commands. The new
|
|
|
|
startup command is `sudo docker-compose up` See "ubuntu_example.sh" for
|
2018-10-02 16:01:48 -06:00
|
|
|
details. All services run in a single command now.
|
2018-10-02 14:47:36 -06:00
|
|
|
|
|
|
|
3. If you wish to continue using your current database:
|
2018-10-02 16:01:48 -06:00
|
|
|
a. To keep using the old database (v6) database, set the `DATABASE_URL`
|
|
|
|
ENV var to match the following format:
|
|
|
|
`postgres://username:password@host_name:5432/database_name`
|
2018-10-02 14:47:36 -06:00
|
|
|
b. Migrate the database to the new container-based DB manually:
|
|
|
|
https://stackoverflow.com/questions/1237725/copying-postgresql-database-to-another-server
|
2018-10-02 16:01:48 -06:00
|
|
|
(NOTE: We do not provide database migration support- consult
|
|
|
|
StackOverflow and the PostgreSQL docs)
|
|
|
|
c. Start a fresh database by following directions in `ubuntu_setup.sh`.
|
|
|
|
Old data will be lost.
|
2018-10-02 14:47:36 -06:00
|
|
|
|
2018-10-02 16:01:48 -06:00
|
|
|
4. Update database.yml to match https://github.com/FarmBot/Farmbot-Web-App/blob/staging/config/database.yml
|
2018-10-02 14:47:36 -06:00
|
|
|
|
2018-10-02 16:01:48 -06:00
|
|
|
5. Migrate the contents of `config/application.yml` to `.env`. Ensure you
|
|
|
|
have removed "quotation marks" and that all entries are `key=value` pairs.
|
2018-10-02 14:47:36 -06:00
|
|
|
|
2018-10-02 16:01:48 -06:00
|
|
|
6. (SECURITY CRITICAL) Migrate `mqtt/` folder to `docker_configs/` and
|
|
|
|
delete `mqtt/`
|
|
|
|
END
|
2018-10-02 14:47:36 -06:00
|
|
|
end
|
|
|
|
|
2018-10-03 12:07:22 -06:00
|
|
|
def hard_reset_api
|
|
|
|
sh "sudo rm -rf docker_volumes/"
|
|
|
|
sh "sudo docker stop $(sudo docker ps -a -q)"
|
|
|
|
sh "sudo docker rm $(sudo docker ps -a -q)"
|
|
|
|
rescue => exception
|
|
|
|
puts exception.message
|
|
|
|
puts "Reset failed. Was there nothing to destroy?"
|
|
|
|
end
|
|
|
|
|
|
|
|
def rebuild_deps
|
|
|
|
sh "sudo docker-compose run web bundle install"
|
|
|
|
sh "sudo docker-compose run web npm install"
|
|
|
|
sh "sudo docker-compose run web bundle exec rails db:setup"
|
|
|
|
sh "sudo docker-compose run web rake keys:generate"
|
|
|
|
sh "sudo docker-compose run web bundle exec rails r docker_configs/rabbitmq_config_builder.rb"
|
|
|
|
sh "sudo docker-compose run web npm run build"
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_typed?(word)
|
|
|
|
STDOUT.flush
|
|
|
|
STDIN.gets.chomp.downcase.include?(word.downcase)
|
|
|
|
end
|
|
|
|
|
2017-10-10 16:27:28 -06:00
|
|
|
namespace :api do
|
2018-08-18 10:06:49 -06:00
|
|
|
desc "Runs pending email digests. "\
|
|
|
|
"Use the `FOREVER` ENV var to continually check."
|
2018-08-17 07:10:32 -06:00
|
|
|
task log_digest: :environment do
|
2018-08-18 10:06:49 -06:00
|
|
|
ENV["FOREVER"] ? loop { check_for_digests } : check_for_digests
|
2018-08-17 07:10:32 -06:00
|
|
|
end
|
|
|
|
|
2018-10-02 16:01:48 -06:00
|
|
|
# TODO: Remove in dec 2018
|
|
|
|
desc "Deprecated. Will be removed in December of 2018"
|
|
|
|
task(:start) { puts V7Migration::BIG_WARNING }
|
2018-07-24 14:17:47 -06:00
|
|
|
|
2018-10-02 19:08:24 -06:00
|
|
|
desc "Run Rails _ONLY_. No Webpack."
|
|
|
|
task only: :environment do
|
|
|
|
sh "sudo docker-compose up --scale webpack=0"
|
|
|
|
end
|
|
|
|
|
2018-10-03 08:46:25 -06:00
|
|
|
desc "Run Webpack _ONLY_. No other services"
|
|
|
|
task webpack: :environment do
|
|
|
|
sh "sudo docker-compose run webpack npm run webpack"
|
|
|
|
end
|
|
|
|
|
2017-11-27 21:00:08 -07:00
|
|
|
desc "Pull the latest Farmbot API version"
|
|
|
|
task(update: :environment) { same_thing }
|
|
|
|
|
|
|
|
desc "Pull the latest Farmbot API version"
|
|
|
|
task(upgrade: :environment) { same_thing }
|
2018-10-03 12:07:22 -06:00
|
|
|
|
|
|
|
desc "Reset _everything_, including your database"
|
|
|
|
task :reset do
|
|
|
|
puts "This is going to destroy _ALL_ of your local data."\
|
|
|
|
" Type 'destroy' to continue"
|
|
|
|
if user_typed?("destroy")
|
|
|
|
hard_reset_api
|
|
|
|
puts "Done. Type 'build' to re-install dependencies"
|
|
|
|
rebuild_deps if user_typed?("build")
|
|
|
|
end
|
|
|
|
end
|
2017-10-10 16:27:28 -06:00
|
|
|
end
|