#!/usr/bin/env bash # GoClaw Docker setup — generates .env and docker-compose command for your chosen variant. # # Usage: # ./scripts/setup-docker.sh # Interactive mode # ./scripts/setup-docker.sh --variant full --with-ui # ./scripts/setup-docker.sh --variant alpine --dev # # Variants: # alpine — Base image (~50 MB), no runtimes # node — Alpine + Node.js pre-installed # python — Alpine + Python pre-installed # full — Alpine + Node.js + Python + all skill dependencies # # Flags: # --dev Mount local source for development (live reload) # --with-ui Include web dashboard # --port N Gateway port (default: 18790) # --ui-port N Dashboard port (default: 3000) # --pg-port N PostgreSQL port (default: 5432) set -euo pipefail # ── Defaults ── VARIANT="" DEV_MODE=false WITH_UI=false PORT="${GOCLAW_PORT:-18790}" UI_PORT="${GOCLAW_UI_PORT:-3000}" PG_PORT="${POSTGRES_PORT:-5432}" DATA_DIR="${GOCLAW_DATA_DIR:-./goclaw-data}" # ── Parse args ── while [[ $# -gt 0 ]]; do case "$1" in --variant) VARIANT="$2"; shift 2 ;; --dev) DEV_MODE=true; shift ;; --with-ui) WITH_UI=true; shift ;; --port) PORT="$2"; shift 2 ;; --ui-port) UI_PORT="$2"; shift 2 ;; --pg-port) PG_PORT="$2"; shift 2 ;; --data-dir) DATA_DIR="$2"; shift 2 ;; --help|-h) head -20 "$0" | grep '^#' | sed 's/^# \?//' exit 0 ;; *) echo "Unknown option: $1"; exit 1 ;; esac done # ── Interactive variant selection ── if [ -z "$VARIANT" ]; then echo "Select GoClaw Docker variant:" echo "" echo " 1) alpine — Base image (~50 MB), no runtimes (published as :latest)" echo " 2) node — + Node.js (published as :node)" echo " 3) python — + Python (published as :python)" echo " 4) full — + Node.js + Python + all skill deps (published as :full)" echo "" read -rp "Choice [1-4, default=1]: " choice case "${choice:-1}" in 1|alpine) VARIANT="alpine" ;; 2|node) VARIANT="node" ;; 3|python) VARIANT="python" ;; 4|full) VARIANT="full" ;; *) echo "Invalid choice"; exit 1 ;; esac fi # ── Resolve Docker image tag ── DOCKER_IMAGE="digitop/goclaw" case "$VARIANT" in alpine) IMAGE_TAG="latest" ;; node) IMAGE_TAG="node" ;; python) IMAGE_TAG="python" ;; full) IMAGE_TAG="full" ;; *) echo "Unknown variant: $VARIANT"; exit 1 ;; esac echo "" echo "Setting up GoClaw (${VARIANT})..." # ── Create data directories ── mkdir -p "${DATA_DIR}"/{config,data,workspace,skills,storage} # ── Generate secrets if not present ── ENV_FILE="${DATA_DIR}/.env" if [ ! -f "$ENV_FILE" ]; then GATEWAY_TOKEN="$(openssl rand -hex 32 2>/dev/null || head -c 64 /dev/urandom | od -An -tx1 | tr -d ' \n')" ENCRYPTION_KEY="$(openssl rand -hex 16 2>/dev/null || head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n')" PG_PASSWORD="$(openssl rand -hex 12 2>/dev/null || head -c 24 /dev/urandom | od -An -tx1 | tr -d ' \n')" cat > "$ENV_FILE" < "$COMPOSE_FILE" <> "$COMPOSE_FILE" <> "$COMPOSE_FILE" <> "$COMPOSE_FILE" <> "$COMPOSE_FILE" <> "$COMPOSE_FILE" <