Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Improve local backend dev setup with mise

Damian Legawiec91ca10769478
diff --git a/backend/.mise.toml b/backend/.mise.toml
new file mode 100644
index 0000000000..47ea4f7a0a
--- /dev/null
+++ b/backend/.mise.toml
@@ -0,0 +1,2 @@
+[settings]
+idiomatic_version_file_enable_tools = ["ruby"]
diff --git a/backend/README.md b/backend/README.md
index 5bdbd6a947..d0ab59c491 100644
--- a/backend/README.md
+++ b/backend/README.md
@@ -1,4 +1,4 @@
-# Spree Backend
+# Spree Server
A Rails application that serves as the Spree Commerce backend. It mounts the Spree engines (core, api, admin, emails, sample) from the `engines/` directory and provides the API and admin interface.
@@ -20,21 +20,32 @@ backend/
## Setup
-### Prerequisites
+### Local Development (Ruby developers)
-- Ruby 4.0+
-- PostgreSQL 16+
-- libvips (for image processing)
+PostgreSQL must be running before you start. If you have it installed locally, make sure it's running. Otherwise you can start it with Docker:
-### Local Development (Ruby developers)
+```bash
+docker run -d --name spree-postgres -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust postgres:17-alpine
+```
+
+Then run the setup script:
```bash
cd backend
-bundle install
-bin/rails db:prepare
+bin/setup
bin/rails server
```
+`bin/setup` handles everything: installs Ruby (via [mise](https://mise.jdx.dev) if available, otherwise uses your system Ruby), system packages (libpq, vips), gems, and prepares the database.
+
+By default the app connects to PostgreSQL at `localhost:5432` as user `postgres` with no password. Override with environment variables if needed:
+
+```bash
+DATABASE_HOST=127.0.0.1 DATABASE_PORT=5433 DATABASE_USERNAME=myuser bin/setup
+```
+
+Use `bin/setup --reset` to drop and recreate the database.
+
The app starts at `http://localhost:3000`.
### Docker (TypeScript / frontend developers)
diff --git a/backend/bin/setup b/backend/bin/setup
index 81be011e87..67122f3542 100755
--- a/backend/bin/setup
+++ b/backend/bin/setup
@@ -1,35 +1,53 @@
-#!/usr/bin/env ruby
-require "fileutils"
-
-APP_ROOT = File.expand_path("..", __dir__)
-
-def system!(*args)
- system(*args, exception: true)
-end
-
-FileUtils.chdir APP_ROOT do
- # This script is a way to set up or update your development environment automatically.
- # This script is idempotent, so that you can run it at any time and get an expectable outcome.
- # Add necessary setup steps to this file.
-
- puts "== Installing dependencies =="
- system("bundle check") || system!("bundle install")
-
- # puts "\n== Copying sample files =="
- # unless File.exist?("config/database.yml")
- # FileUtils.cp "config/database.yml.sample", "config/database.yml"
- # end
-
- puts "\n== Preparing database =="
- system! "bin/rails db:prepare"
- system! "bin/rails db:reset" if ARGV.include?("--reset")
-
- puts "\n== Removing old logs and tempfiles =="
- system! "bin/rails log:clear tmp:clear"
-
- unless ARGV.include?("--skip-server")
- puts "\n== Starting development server =="
- STDOUT.flush # flush the output before exec(2) so that it displays
- exec "bin/dev"
- end
-end
+#!/usr/bin/env bash
+set -eo pipefail
+
+app_root="$(cd "$(dirname "$0")/.." && pwd)"
+export PATH="$app_root/bin:$PATH"
+
+step() {
+ local step_name="$1"
+ shift
+ echo
+ echo "▸ $step_name"
+ "$@"
+}
+
+# Use mise to install Ruby if available, skip if Ruby is already present
+if command -v mise &>/dev/null; then
+ step "Installing Ruby" mise install --yes
+ eval "$(mise hook-env -s bash)"
+elif ! command -v ruby &>/dev/null; then
+ echo "Ruby not found. Install it manually or install mise (https://mise.jdx.dev) to auto-install."
+ exit 1
+fi
+
+# Install system packages
+if command -v brew &>/dev/null; then
+ packages=(libpq vips)
+ missing_packages=()
+ for pkg in "${packages[@]}"; do
+ if ! brew list "$pkg" &>/dev/null; then
+ missing_packages+=("$pkg")
+ fi
+ done
+ if [ ${#missing_packages[@]} -gt 0 ]; then
+ step "Installing packages" brew install "${missing_packages[@]}"
+ fi
+elif command -v apt-get &>/dev/null; then
+ step "Installing packages" sudo apt-get update -qq && sudo apt-get install -y libpq-dev libvips-dev
+fi
+
+step "Installing gems" bundle install
+
+if [[ $* == *--reset* ]]; then
+ step "Resetting the database" bin/rails db:reset
+else
+ step "Preparing the database" bin/rails db:prepare
+fi
+
+step "Cleaning up" bin/rails log:clear tmp:clear
+
+echo
+echo "✓ Done (${SECONDS}s)"
+echo
+echo "Run 'bin/rails server' to start the app."