Skip to content

Commit

Permalink
upgrade postgres/rabbitmq/node and add instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Aug 15, 2024
1 parent 6c8e741 commit 8d8a79c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 39 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.vscode
*.log
*.pem
*.sql
passenger.*.pid
*.tsbuildinfo
*.pid.lock
Expand All @@ -27,7 +28,3 @@ public/dist
# ActiveStorage blobs:
storage/*
tmp

# === Legacy
# v13 upgrade creates a DB backup as dump.sql:
dump.sql
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
# +--------+ +------------+
# ================================================

version: "3"
services:
redis:
env_file: ".env"
Expand All @@ -37,8 +36,7 @@ services:

db:
env_file: ".env"
# Know to work: 10, 11
image: postgres:13
image: postgres:16
restart: always
volumes: ["./docker_volumes/db:/var/lib/postgresql/data"]

Expand Down
2 changes: 1 addition & 1 deletion docker_configs/api.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | te
apt-get update -qq && apt-get install -y build-essential libpq-dev postgresql postgresql-contrib && \
mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
sh -c 'echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list' && \
sh -c 'echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" >> /etc/apt/sources.list.d/nodesource.list' && \
apt-get update -qq && \
sh -c 'echo "\nPackage: *\nPin: origin deb.nodesource.com\nPin-Priority: 700\n" >> /etc/apt/preferences' && \
apt-get install -y nodejs && \
Expand Down
2 changes: 1 addition & 1 deletion docker_configs/rabbitmq.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rabbitmq:3.12.6
FROM rabbitmq:3.13.6
RUN rabbitmq-plugins enable --offline \
rabbitmq_auth_backend_http \
rabbitmq_management \
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Farmbot web frontend.",
"engines": {
"browsers": "defaults",
"node": "20.x",
"node": "22.x",
"npm": "10.x",
"parcel": "2.x"
},
Expand Down
90 changes: 61 additions & 29 deletions ubuntu_example.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# How to install FarmBot Web API on a fresh Ubuntu 22.04 machine
# How to install FarmBot Web API on a fresh Ubuntu 24.04 machine

# IMPORTANT NOTE: Resources are limited and FarmBot Inc cannot provide
# longterm support to self-hosted users. If you have never administered a
Expand All @@ -12,10 +12,6 @@
#
# Self-hosting a FarmBot server is not a simple task.

# Remove old (possibly broke) docker versions
sudo apt remove docker-engine
sudo apt remove docker docker.io containerd runc

# Install docker and docker compose
sudo apt update
sudo apt install ca-certificates curl gnupg -y
Expand Down Expand Up @@ -58,36 +54,72 @@ sudo docker compose run web npm install
sudo docker compose run web bundle exec rails db:create db:migrate
# Generate a set of *.pem files for data encryption
sudo docker compose run web rake keys:generate # ⚠ SKIP THIS STEP IF UPGRADING!
# Build the UI assets via ParcelJS
sudo docker compose run web rake assets:precompile
# Run the server! ٩(^‿^)۶
# NOTE: DONT TRY TO LOGIN until you see a message similar to this:
# Note: You won't be able to log in until you see a message similar to this:
# "✨ Built in 44.92s"
# THIS MAY TAKE A VERY LONG TIME ON SLOW MACHINES (~3 minutes on DigitalOcean)
# You will just get an empty screen otherwise.
# This only happens during initialization
# This only happens during initialization and may take a long time on slow machines.
sudo docker compose up

# At this point, setup is complete. Content should be visible at ===============
# http://YOUR_HOST:3000/.

# You can optionally verify installation by running unit tests.
# At this point, setup is complete.
# Content should be visible at http://YOUR_HOST:3000/.

# Create the database for the app to use:
sudo docker compose run -e RAILS_ENV=test web bundle exec rails db:setup
# Run the tests in the "test" RAILS_ENV:
sudo docker compose run -e RAILS_ENV=test web rspec spec
# Run user-interface unit tests REQUIRES AT LEAST 4 GB OF RAM:
sudo docker compose run web npm run test
# --- You can optionally verify installation by running unit tests. ---
# Create the database for the app to use
sudo docker compose run -e RAILS_ENV=test web bundle exec rails db:setup
# Run the tests in the "test" RAILS_ENV
sudo docker compose run -e RAILS_ENV=test web rspec spec
# Run user-interface unit tests (requires a large amount of RAM)
sudo docker compose run web npm run test
# --- end of optional tests ---

# === BEGIN OPTIONAL UPGRADES
# To update to later versions of FarmBot,
# shut down the server, create a database backup
# and run commands below.
# === BEGIN OPTIONAL UPGRADES to later versions of the FarmBot Web App ===
# Shut down the server
sudo docker compose down
# Start the database service by starting the web container
sudo docker compose run web gem install bundler
# Verify that the correct database service is running.
# If the version doesn't print, a `git reset` may be required.
sudo docker compose exec db pg_dumpall -V
# Create a database backup (this will overwrite dump.sql!)
# If you do not do this before `git pull`, you will need to `git reset` first.
sudo docker compose exec db pg_dumpall -U postgres > dump.sql
# Create a backup of the dump.sql file
cp -vi dump.sql dump_$(date +%Y%m%d%H%M%S).sql
# Stop and remove containers
sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)
# Remove docker images. This will later require re-download of large amounts of data.
sudo docker system prune -af --volumes
# Delete the database. This will delete all of your data!
# Only run after verifying your data is backed up in dump.sql.
# Commented with `#` for safety. Run the command without `#`.
# sudo rm -rf docker_volumes/db
# Verify that the database has been deleted. Do not continue on until "OK".
if [ -d docker_volumes/db ]; then echo "ERROR"; else echo "OK"; fi
# Download the latest version of the web app
git pull https://github.com/FarmBot/Farmbot-Web-App.git main
sudo docker compose build
sudo docker compose run web bundle install # <== ⚠ UPGRADE USERS ONLY
sudo docker compose run web npm install # <== ⚠ UPGRADE USERS ONLY
sudo docker compose run web rails db:migrate # <== ⚠ UPGRADE USERS ONLY
# === END OPTIONAL UPGRADES ^
# Install Ruby gems
sudo docker compose run web gem install bundler
sudo docker compose run web bundle install
# Install NPM packages
sudo docker compose run web npm install
# Replace the dump.sql password value with the value of POSTGRES_PASSWORD from .env
nano dump.sql
# Verify that the correct database service is running
sudo docker compose exec db pg_dumpall -V
# Restore the database
sudo docker compose run -v $(pwd):/farmbot db bash
# Run these commands in the db container shell opened by the previous command
# --- begin db container shell commands ---
cd /farmbot
PGPASSWORD=$POSTGRES_PASSWORD psql -U postgres -h db < dump.sql
exit
# --- end db container shell commands ---
# Migrate the database
sudo docker compose run web rails db:migrate
# Run the server
sudo docker compose up
# If you get a MQTT authentification error, stop and start the server again.
# === END OPTIONAL UPGRADES ===

0 comments on commit 8d8a79c

Please sign in to comment.