Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

dx: Dev bootstrap (#66501)

Nemanja Glumacb748b7f2064f
diff --git a/bin/dev-bootstrap b/bin/dev-bootstrap
new file mode 100755
index 00000000000..6b7110b6067
--- /dev/null
+++ b/bin/dev-bootstrap
@@ -0,0 +1,150 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+# Load shared utilities
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
+source "$SCRIPT_DIR/utils/all.sh"
+
+# Lock directory to prevent concurrent runs
+LOCK_DIR="$PROJECT_ROOT/logs/dev-bootstrap.lock"
+
+acquire_lock() {
+ mkdir -p "$(dirname "$LOCK_DIR")"
+ # Use mkdir for atomic lock acquisition
+ if ! mkdir "$LOCK_DIR" 2>/dev/null; then
+ print_error "Bootstrap is already running"
+ echo " If this is a mistake, run: rm -rf $LOCK_DIR"
+ exit 1
+ fi
+}
+
+release_lock() {
+ rm -rf "$LOCK_DIR"
+}
+
+trap release_lock EXIT
+
+check_required_tools() {
+ local missing=()
+
+ # If any of these tools are an incorrect version, the build
+ # step will fail later on, so we just check for their presence here.
+ if ! command -v node &> /dev/null; then
+ missing+=("node")
+ fi
+
+ if ! command -v yarn &> /dev/null; then
+ missing+=("yarn")
+ fi
+
+ if ! command -v java &> /dev/null; then
+ missing+=("java")
+ fi
+
+ if ! command -v clojure &> /dev/null; then
+ missing+=("clojure")
+ fi
+
+ if [ ${#missing[@]} -gt 0 ]; then
+ echo -e "${RED}${BOLD}Missing required tools:${NC} ${missing[*]}"
+ echo ""
+ echo "Run ./bin/dev-requirements to check your development environment."
+ echo ""
+ echo "If you'd like an automated setup, run ./bin/dev-install which uses mise (coming soon)."
+ exit 1
+ fi
+}
+
+install_frontend_deps() {
+ print_step "Installing frontend dependencies"
+
+ if yarn install --frozen-lockfile --prefer-offline; then
+ print_success "Frontend dependencies installed"
+ else
+ print_error "Failed to install frontend dependencies"
+ exit 1
+ fi
+}
+
+install_backend_deps() {
+ print_step "Downloading backend dependencies"
+
+ if clojure -A:build:dev:ee:ee-dev:drivers:drivers-dev:cljs -P; then
+ print_success "Backend dependencies downloaded"
+ else
+ print_error "Failed to download backend dependencies"
+ exit 1
+ fi
+}
+
+build_jar() {
+ print_step "Building Metabase JAR (this may take a while)"
+
+ if ./bin/build.sh; then
+ print_success "Metabase JAR built successfully"
+ else
+ print_error "Failed to build Metabase JAR"
+ exit 1
+ fi
+}
+
+main() {
+ acquire_lock
+
+ print_header "Metabase Development Bootstrap"
+
+ echo "This script will:"
+ echo " 1. Verify required tools are installed"
+ echo " 2. Install frontend dependencies (yarn)"
+ echo " 3. Download backend dependencies (Clojure)"
+ echo " 4. Build the Metabase JAR"
+ echo ""
+
+ print_step "Checking required tools"
+ check_required_tools
+ print_success "All required tools found"
+
+ install_frontend_deps
+ install_backend_deps
+
+ # Check for existing JAR and show its age
+ local jar_file="target/uberjar/metabase.jar"
+ local jar_age=$(get_file_age "$jar_file")
+
+ echo ""
+ if [ "$jar_age" = "not found" ]; then
+ if ask_yes_no "Build the Metabase JAR? (takes several minutes)" "n"; then
+ build_jar
+ else
+ print_warning "Skipping JAR build"
+ echo " You can build it later with: ./bin/build.sh"
+ fi
+ else
+ print_success "Existing JAR found (built ${jar_age})"
+ if ask_yes_no "Rebuild it?" "n"; then
+ build_jar
+ else
+ print_warning "Keeping existing JAR"
+ fi
+ fi
+
+ print_header "Bootstrap Complete!"
+
+ echo "Your development environment is ready."
+ echo ""
+ echo "To start the backend (from source):"
+ echo " clj -M:dev:drivers:drivers-dev:ee:ee-dev:dev-start --hot"
+ echo ""
+ echo "To start the backend (from JAR):"
+ echo " java --add-opens java.base/java.nio=ALL-UNNAMED -jar target/uberjar/metabase.jar"
+ echo ""
+ echo "To start the frontend:"
+ echo " yarn build-hot"
+ echo ""
+ echo "For more information, see docs/developers-guide/devenv.md"
+ echo ""
+}
+
+main "$@"
diff --git a/bin/dev-requirements b/bin/dev-requirements
index f87034906fb..ccfa0a11555 100755
--- a/bin/dev-requirements
+++ b/bin/dev-requirements
@@ -2,40 +2,29 @@
set -euo pipefail
-# Colors for output
-RED='\033[0;31m'
-GREEN='\033[0;32m'
-YELLOW='\033[1;33m'
-BLUE='\033[0;34m'
-BOLD='\033[1m'
-NC='\033[0m' # No Color
-
-# Print functions
-print_header() {
- echo -e "\n${BOLD}${BLUE}═══════════════════════════════════════════════════════════════${NC}"
- echo -e "${BOLD}${BLUE} $1${NC}"
- echo -e "${BOLD}${BLUE}═══════════════════════════════════════════════════════════════${NC}\n"
-}
-
-print_section() {
- echo -e "\n${BOLD}$1${NC}"
- echo -e "${BOLD}$(printf '─%.0s' {1..63})${NC}"
-}
+# Load shared utilities
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+source "$SCRIPT_DIR/utils/all.sh"
+# Script-specific print functions
print_found() {
- echo -e " ${GREEN}✓${NC} $1"
+ print_success "$1"
}
print_not_found() {
- echo -e " ${RED}✗${NC} $1"
-}
-
-print_warning() {
- echo -e " ${YELLOW}⚠️${NC} $1"
+ print_error "$1"
}
-print_info() {
- echo -e " ${BLUE}ℹ${NC} $1"
+print_optional_tool() {
+ local cmd=$1
+ local name=$2
+ local url=$3
+ if command -v "$cmd" &> /dev/null; then
+ echo -e " ${GREEN}✓${NC} $name"
+ else
+ echo -e " ${RED}✗${NC} $name"
+ fi
+ echo -e " ${DIM}$url${NC}"
}
# Detection functions
@@ -224,9 +213,9 @@ main() {
print_warning "Multiple version managers detected!"
echo " Having multiple version managers can cause conflicts where different"
echo " tools compete to manage the same runtime versions. This may lead to:"
- echo " • Unexpected version switches"
- echo " • PATH conflicts"
- echo " • Shell initialization slowdowns"
+ echo " - Unexpected version switches"
+ echo " - PATH conflicts"
+ echo " - Shell initialization slowdowns"
echo ""
echo -e " 💡 ${BOLD}Recommendation:${NC} Use only one version manager (we recommend mise)."
fi
@@ -241,13 +230,13 @@ main() {
if [ -n "$node_version" ]; then
node_major=$(echo "$node_version" | sed 's/v//' | cut -d. -f1)
if [ "$node_major" -ge 22 ]; then
- print_found "Node.js $node_version (meets requirement: ≥22)"
+ print_found "Node.js $node_version (meets requirement: >= 22)"
else
- print_warning "Node.js $node_version (required: ≥22)"
+ print_warning "Node.js $node_version (required: >= 22)"
requirements_met=false
fi
else
- print_not_found "Node.js (required: ≥22)"
+ print_not_found "Node.js (required: >= 22)"
requirements_met=false
fi
@@ -334,44 +323,32 @@ main() {
required_clojure_version=$(get_required_clojure_version)
echo -e " ${BOLD}Required Tools:${NC}"
- echo " • Node.js ≥22 (currently specified in .nvmrc)"
- echo " • Yarn Classic 1.x (NOT Yarn 2+, NO Corepack)"
- echo " • Java 21 with Eclipse Temurin distribution (for Clojure backend)"
+ echo " - Node.js >= 22 (currently specified in .nvmrc)"
+ echo " - Yarn Classic 1.x (NOT Yarn 2+, NO Corepack)"
+ echo " - Java 21 with Eclipse Temurin distribution (for Clojure backend)"
if [ -n "$required_clojure_version" ]; then
- echo " • Clojure CLI (for Clojure $required_clojure_version specified in deps.edn)"
+ echo " - Clojure CLI (for Clojure $required_clojure_version specified in deps.edn)"
else
- echo " • Clojure CLI"
+ echo " - Clojure CLI"
fi
- echo " • Babashka (for mage task automation)"
+ echo " - Babashka (for mage task automation)"
echo ""
echo -e " ${BOLD}Optional Tools (quality of life):${NC}"
- if command -v bat &> /dev/null; then
- echo -e " ${GREEN}✓${NC} bat - A cat clone with syntax highlighting (https://github.com/sharkdp/bat)"
- else
- echo -e " ${RED}✗${NC} bat - A cat clone with syntax highlighting (https://github.com/sharkdp/bat)"
- fi
- if command -v fzf &> /dev/null; then
- echo -e " ${GREEN}✓${NC} fzf - A fuzzy finder for the terminal (https://github.com/junegunn/fzf)"
- else
- echo -e " ${RED}✗${NC} fzf - A fuzzy finder for the terminal (https://github.com/junegunn/fzf)"
- fi
- if command -v fd &> /dev/null; then
- echo -e " ${GREEN}✓${NC} fd - A fast alternative to find (https://github.com/sharkdp/fd)"
- else
- echo -e " ${RED}✗${NC} fd - A fast alternative to find (https://github.com/sharkdp/fd)"
- fi
- if command -v rg &> /dev/null; then
- echo -e " ${GREEN}✓${NC} ripgrep - A fast alternative to grep (https://github.com/BurntSushi/ripgrep)"
- else
- echo -e " ${RED}✗${NC} ripgrep - A fast alternative to grep (https://github.com/BurntSushi/ripgrep)"
- fi
+ print_optional_tool bat "bat - A cat clone with syntax highlighting" "https://github.com/sharkdp/bat"
+ print_optional_tool fzf "fzf - A fuzzy finder for the terminal" "https://github.com/junegunn/fzf"
+ print_optional_tool fd "fd - A fast alternative to find" "https://github.com/sharkdp/fd"
+ print_optional_tool rg "ripgrep - A fast alternative to grep" "https://github.com/BurntSushi/ripgrep"
+ print_optional_tool gh "gh - GitHub CLI" "https://cli.github.com/"
+ print_optional_tool op "op - 1Password CLI" "https://1password.com/downloads/command-line/"
+ print_optional_tool aws "aws - AWS CLI" "https://aws.amazon.com/cli/"
+ print_optional_tool orb "OrbStack - Fast Docker & Linux on macOS" "https://orbstack.dev/"
print_section "Recommended Setup"
echo -e " ${BOLD}${GREEN}We recommend using 'mise'${NC} for version management because:"
- echo " • Manages Node.js, Java, and other tools in one place"
- echo " • Automatically switches versions per-project"
- echo " • Cross-platform and actively maintained"
+ echo " - Manages Node.js, Java, and other tools in one place"
+ echo " - Automatically switches versions per-project"
+ echo " - Cross-platform and actively maintained"
echo ""
echo " Learn more: https://mise.jdx.dev/getting-started.html"
diff --git a/bin/utils/all.sh b/bin/utils/all.sh
new file mode 100644
index 00000000000..070329c9f34
--- /dev/null
+++ b/bin/utils/all.sh
@@ -0,0 +1,22 @@
+# bin/utils/all.sh - Load all utility modules
+# Source this file to get all utilities in one go.
+#
+# Usage:
+# SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+# source "$SCRIPT_DIR/utils/all.sh"
+#
+# This sources all utility modules in the correct order to satisfy dependencies.
+
+# Guard against multiple inclusion
+[[ -n "${_DEVUTILS_ALL_LOADED:-}" ]] && return 0
+_DEVUTILS_ALL_LOADED=1
+
+_DEVUTILS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+# Order matters: colors first (no deps), then modules that depend on it
+source "$_DEVUTILS_DIR/colors.sh"
+source "$_DEVUTILS_DIR/logging.sh"
+source "$_DEVUTILS_DIR/prompts.sh"
+source "$_DEVUTILS_DIR/files.sh"
+
+unset _DEVUTILS_DIR
diff --git a/bin/utils/colors.sh b/bin/utils/colors.sh
new file mode 100644
index 00000000000..a82f5961360
--- /dev/null
+++ b/bin/utils/colors.sh
@@ -0,0 +1,33 @@
+# bin/utils/colors.sh - TTY-aware color definitions
+# Source this file to get color variables for terminal output.
+#
+# Usage:
+# source "$(dirname "${BASH_SOURCE[0]}")/utils/colors.sh"
+# echo -e "${GREEN}Success${NC}"
+#
+# Provides: RED, GREEN, YELLOW, BLUE, CYAN, BOLD, DIM, NC
+# All variables are empty strings when output is not a terminal.
+
+# Guard against multiple inclusion
+[[ -n "${_DEVUTILS_COLORS_LOADED:-}" ]] && return 0
+_DEVUTILS_COLORS_LOADED=1
+
+if [ -t 1 ] && [ -n "${TERM:-}" ] && [ "${TERM}" != "dumb" ]; then
+ RED='\033[0;31m'
+ GREEN='\033[0;32m'
+ YELLOW='\033[1;33m'
+ BLUE='\033[0;34m'
+ CYAN='\033[0;36m'
+ BOLD='\033[1m'
+ DIM='\033[2m'
+ NC='\033[0m'
+else
+ RED=''
+ GREEN=''
+ YELLOW=''
+ BLUE=''
+ CYAN=''
+ BOLD=''
+ DIM=''
+ NC=''
+fi
diff --git a/bin/utils/files.sh b/bin/utils/files.sh
new file mode 100644
index 00000000000..314d49ad13c
--- /dev/null
+++ b/bin/utils/files.sh
@@ -0,0 +1,41 @@
+# bin/utils/files.sh - File utilities
+# Source this file to get file-related helper functions.
+#
+# Usage:
+# source "$(dirname "${BASH_SOURCE[0]}")/utils/files.sh"
+# age=$(get_file_age "/path/to/file")
+# echo "File was modified $age"
+#
+# Provides: get_file_age
+
+# Guard against multiple inclusion
+[[ -n "${_DEVUTILS_FILES_LOADED:-}" ]] && return 0
+_DEVUTILS_FILES_LOADED=1
+
+# No dependencies - this module is standalone
+
+# Get a human-readable age string for a file
+# Usage: get_file_age "/path/to/file"
+# Returns: "Xs ago", "Xm ago", "Xh ago", "Xd ago", or "not found"
+get_file_age() {
+ local file="$1"
+ if [ ! -f "$file" ]; then
+ echo "not found"
+ return
+ fi
+
+ local now=$(date +%s)
+ # macOS uses -f, Linux uses -c
+ local file_time=$(stat -f %m "$file" 2>/dev/null || stat -c %Y "$file" 2>/dev/null)
+ local age_seconds=$((now - file_time))
+
+ if [ $age_seconds -lt 60 ]; then
+ echo "${age_seconds}s ago"
+ elif [ $age_seconds -lt 3600 ]; then
+ echo "$((age_seconds / 60))m ago"
+ elif [ $age_seconds -lt 86400 ]; then
+ echo "$((age_seconds / 3600))h ago"
+ else
+ echo "$((age_seconds / 86400))d ago"
+ fi
+}
diff --git a/bin/utils/logging.sh b/bin/utils/logging.sh
new file mode 100644
index 00000000000..47f79fa5a95
--- /dev/null
+++ b/bin/utils/logging.sh
@@ -0,0 +1,62 @@
+# bin/utils/logging.sh - Logging and output functions
+# Source this file to get standardized print functions for terminal output.
+#
+# Usage:
+# source "$(dirname "${BASH_SOURCE[0]}")/utils/logging.sh"
+# print_header "My Script"
+# print_step "Doing something"
+# print_success "It worked"
+#
+# Provides: print_header, print_step, print_success, print_error, print_warning, print_info
+
+# Guard against multiple inclusion
+[[ -n "${_DEVUTILS_LOGGING_LOADED:-}" ]] && return 0
+_DEVUTILS_LOGGING_LOADED=1
+
+# Source dependencies
+_DEVUTILS_LOGGING_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+source "$_DEVUTILS_LOGGING_DIR/colors.sh"
+unset _DEVUTILS_LOGGING_DIR
+
+# Print a prominent header (for script titles, major sections)
+print_header() {
+ echo -e "\n${BOLD}${BLUE}===================================================================${NC}"
+ echo -e "${BOLD}${BLUE} $1${NC}"
+ echo -e "${BOLD}${BLUE}===================================================================${NC}\n"
+}
+
+# Print a section header (for grouping related output)
+print_section() {
+ echo -e "\n${BOLD}$1${NC}"
+ echo -e "${BOLD}$(printf -- '-%.0s' {1..67})${NC}"
+}
+
+# Print a step indicator (for progress through tasks)
+print_step() {
+ echo -e "\n${BOLD}${BLUE}→${NC} ${BOLD}$1${NC}"
+}
+
+# Print a success message
+print_success() {
+ echo -e " ${GREEN}✓${NC} $1"
+}
+
+# Print an error message
+print_error() {
+ echo -e " ${RED}✗${NC} $1"
+}
+
+# Print a warning message
+print_warning() {
+ echo -e " ${YELLOW}⚠${NC} $1"
+}
+
+# Print an info message
+print_info() {
+ echo -e " ${BLUE}ℹ${NC} $1"
+}
+
+# Print a dimmed message (for hints, secondary info)
+print_dim() {
+ echo -e " ${DIM}$1${NC}"
+}
diff --git a/bin/utils/prompts.sh b/bin/utils/prompts.sh
new file mode 100644
index 00000000000..57013b0e5c4
--- /dev/null
+++ b/bin/utils/prompts.sh
@@ -0,0 +1,40 @@
+# bin/utils/prompts.sh - Interactive prompt utilities
+# Source this file to get functions for user interaction.
+#
+# Usage:
+# source "$(dirname "${BASH_SOURCE[0]}")/utils/prompts.sh"
+# if ask_yes_no "Continue?" "y"; then
+# echo "User said yes"
+# fi
+#
+# Provides: ask_yes_no
+
+# Guard against multiple inclusion
+[[ -n "${_DEVUTILS_PROMPTS_LOADED:-}" ]] && return 0
+_DEVUTILS_PROMPTS_LOADED=1
+
+# No dependencies - this module is standalone
+
+# Ask a yes/no question with a default answer
+# Usage: ask_yes_no "Question?" [default]
+# default: "y" for yes (default), "n" for no
+# Returns: 0 for yes, 1 for no
+ask_yes_no() {
+ local prompt=$1
+ local default=${2:-y}
+ local yn
+
+ if [ "$default" = "y" ]; then
+ prompt="$prompt [Y/n] "
+ else
+ prompt="$prompt [y/N] "
+ fi
+
+ read -r -p "$prompt" yn
+ yn=${yn:-$default}
+
+ case "$yn" in
+ [Yy]*) return 0 ;;
+ *) return 1 ;;
+ esac
+}