🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(docker): make the one-click Docker Compose install start on the released image (#19590)
Arvin Xu40f8f469cfb0
diff --git a/docker-compose/deploy/docker-compose.yml b/docker-compose/deploy/docker-compose.ymlindex e3b3ebae6b2..547333bcd8a 100644--- a/docker-compose/deploy/docker-compose.yml+++ b/docker-compose/deploy/docker-compose.yml@@ -50,15 +50,22 @@ services:- '5432:5432'volumes:- './data:/var/lib/postgresql/data'- command: ['postgres', '-c', 'shared_preload_libraries=pg_search']+ # Keep the image's default preload list: its first-start bootstrap creates the pg_cron+ # extension and aborts initialization when pg_cron is missing from this list.+ command: ['postgres', '-c', 'shared_preload_libraries=pg_search,pg_cron,pg_stat_statements']environment:- 'POSTGRES_DB=${LOBE_DB_NAME}'- 'POSTGRES_PASSWORD=${POSTGRES_PASSWORD}'healthcheck:- test: ['CMD-SHELL', 'pg_isready -U postgres']+ # Probe over TCP: during first-time initialization the image runs a temporary server that+ # only listens on the Unix socket, so a socket probe reports ready while LobeHub's TCP+ # connections are still refused.+ test: ['CMD-SHELL', 'pg_isready -U postgres -h 127.0.0.1']interval: 5stimeout: 5sretries: 5+ # TCP stays closed until initialization finishes, which can outlast the retries above+ start_period: 60srestart: alwaysnetworks:- lobe-network@@ -119,7 +126,8 @@ services:volumes:- ./bucket.config.json:/bucket.config.json:roentrypoint: /bin/sh- command: -c ' set -eux; echo "S3_ACCESS_KEY=${RUSTFS_ACCESS_KEY}, S3_SECRET_KEY=${RUSTFS_SECRET_KEY}"; rc --version; rc alias set rustfs "http://rustfs:9000" "${RUSTFS_ACCESS_KEY}" "${RUSTFS_SECRET_KEY}"; rc ls rustfs || true; rc mb "rustfs/lobe" --ignore-existing; rc admin info cluster rustfs || true; rc anonymous set-json "/bucket.config.json" "rustfs/lobe"; '+ # Browsers upload through presigned URLs on the RustFS origin, so the bucket also needs a CORS rule+ command: -c ' set -eux; echo "S3_ACCESS_KEY=${RUSTFS_ACCESS_KEY}, S3_SECRET_KEY=${RUSTFS_SECRET_KEY}"; rc --version; rc alias set rustfs "http://rustfs:9000" "${RUSTFS_ACCESS_KEY}" "${RUSTFS_SECRET_KEY}"; rc ls rustfs || true; rc mb "rustfs/lobe" --ignore-existing; rc admin info cluster rustfs || true; rc anonymous set-json "/bucket.config.json" "rustfs/lobe"; printf "%s" "<CORSConfiguration><CORSRule><AllowedOrigin>*</AllowedOrigin><AllowedMethod>GET</AllowedMethod><AllowedMethod>PUT</AllowedMethod><AllowedMethod>HEAD</AllowedMethod><AllowedHeader>*</AllowedHeader><ExposeHeader>ETag</ExposeHeader><MaxAgeSeconds>3600</MaxAgeSeconds></CORSRule></CORSConfiguration>" | rc bucket cors set "rustfs/lobe" -; 'restart: 'no'networks:- lobe-networkdiff --git a/docker-compose/dev/docker-compose.yml b/docker-compose/dev/docker-compose.ymlindex 1eee7b72b02..6a64cf2c7b1 100644--- a/docker-compose/dev/docker-compose.yml+++ b/docker-compose/dev/docker-compose.yml@@ -21,15 +21,22 @@ services:- '5432:5432'volumes:- './data:/var/lib/postgresql/data'- command: ['postgres', '-c', 'shared_preload_libraries=pg_search']+ # Keep the image's default preload list: its first-start bootstrap creates the pg_cron+ # extension and aborts initialization when pg_cron is missing from this list.+ command: ['postgres', '-c', 'shared_preload_libraries=pg_search,pg_cron,pg_stat_statements']environment:- 'POSTGRES_DB=${LOBE_DB_NAME}'- 'POSTGRES_PASSWORD=${POSTGRES_PASSWORD}'healthcheck:- test: ['CMD-SHELL', 'pg_isready -U postgres']+ # Probe over TCP: during first-time initialization the image runs a temporary server that+ # only listens on the Unix socket, so a socket probe reports ready while LobeHub's TCP+ # connections are still refused.+ test: ['CMD-SHELL', 'pg_isready -U postgres -h 127.0.0.1']interval: 5stimeout: 5sretries: 5+ # TCP stays closed until initialization finishes, which can outlast the retries above+ start_period: 60srestart: alwaysnetworks:- lobe-network@@ -90,6 +97,7 @@ services:rc mb "rustfs/lobe" --ignore-existing;rc admin info cluster rustfs || true;rc anonymous set-json "/bucket.config.json" "rustfs/lobe";+ printf "%s" "<CORSConfiguration><CORSRule><AllowedOrigin>*</AllowedOrigin><AllowedMethod>GET</AllowedMethod><AllowedMethod>PUT</AllowedMethod><AllowedMethod>HEAD</AllowedMethod><AllowedHeader>*</AllowedHeader><ExposeHeader>ETag</ExposeHeader><MaxAgeSeconds>3600</MaxAgeSeconds></CORSRule></CORSConfiguration>" | rc bucket cors set "rustfs/lobe" -;'restart: 'no'networks:diff --git a/docker-compose/setup.sh b/docker-compose/setup.shindex 966972bf0fb..fa120fa642f 100644--- a/docker-compose/setup.sh+++ b/docker-compose/setup.sh@@ -25,7 +25,7 @@ fi# Arg: --url# Determine the source URL to download files-SOURCE_URL="https://raw.githubusercontent.com/lobehub/lobe-chat/main"+SOURCE_URL="https://raw.githubusercontent.com/lobehub/lobehub/main"# Arg: --host# Determine the server host@@ -410,8 +410,13 @@ show_message() {}# Function to download files+# curl is preinstalled on macOS and already needed to fetch this script; wget is the fallbackdownload_file() {- wget "$1" -O "$2"+ if command -v curl &> /dev/null ; then+ curl -fsSL "$1" -o "$2"+ else+ wget "$1" -O "$2"+ fi# If run failed, exitif [ $? -ne 0 ]; thenshow_message "tips_download_failed" "$2"@@ -419,6 +424,20 @@ download_file() {fi}+# Detect the primary IPv4 address of this machine+# `hostname -I` only exists on Linux; macOS falls back to the default route's interface+detect_host_ip() {+ local ip=""+ ip=$(hostname -I 2>/dev/null | awk '{print $1}')+ if [ -z "$ip" ] && command -v ip &> /dev/null ; then+ ip=$(ip route get 1.1.1.1 2>/dev/null | awk '{for (i = 1; i < NF; i++) if ($i == "src") { print $(i + 1); exit }}')+ fi+ if [ -z "$ip" ] && command -v ipconfig &> /dev/null ; then+ ip=$(ipconfig getifaddr "$(route -n get default 2>/dev/null | awk '/interface:/ {print $2}')" 2>/dev/null)+ fi+ echo "$ip"+}+print_centered() {local text="$1" # Get input textslocal color="${2:-reset}" # Get color, default to reset@@ -519,8 +538,8 @@ fisection_download_files(){# Download files asynchronously- if ! command -v wget &> /dev/null ; then- echo "wget" $(show_message "tips_no_executable")+ if ! command -v curl &> /dev/null && ! command -v wget &> /dev/null ; then+ echo "curl / wget" $(show_message "tips_no_executable")exit 1fi@@ -577,7 +596,7 @@ section_configurate_host() {# If user not specify host, try to get the server ipif [ -z "$HOST" ]; then- HOST=$(hostname -I | awk '{print $1}')+ HOST=$(detect_host_ip)# If the host is a private ip and the deploy mode is port modeif [[ "$DEPLOY_MODE" == "1" ]] && ([[ "$HOST" == "192.168."* ]] || [[ "$HOST" == "172."* ]] || [[ "$HOST" == "10."* ]]); thenecho $(show_message "tips_private_ip_detected")diff --git a/docs/self-hosting/platform/docker-compose.mdx b/docs/self-hosting/platform/docker-compose.mdxindex 8488d9513f7..79067fb3be7 100644--- a/docs/self-hosting/platform/docker-compose.mdx+++ b/docs/self-hosting/platform/docker-compose.mdx@@ -490,6 +490,8 @@ docker compose logs rustfsdocker compose logs rustfs-init```+`rustfs-init` also applies the bucket CORS rule that browser uploads need. If uploads fail in the browser with a network error, re-run it with `docker compose up -d --force-recreate rustfs-init`.+Verify the bucket was created: `docker compose exec rustfs ls /data/lobe`**Running out of disk space**diff --git a/docs/self-hosting/platform/docker-compose.zh-CN.mdx b/docs/self-hosting/platform/docker-compose.zh-CN.mdxindex ca9b09f9862..eb4af9679b3 100644--- a/docs/self-hosting/platform/docker-compose.zh-CN.mdx+++ b/docs/self-hosting/platform/docker-compose.zh-CN.mdx@@ -484,6 +484,8 @@ docker compose logs rustfsdocker compose logs rustfs-init```+`rustfs-init` 同时会为存储桶配置浏览器直传所需的 CORS 规则。如果浏览器上传时报网络错误,可以执行 `docker compose up -d --force-recreate rustfs-init` 重新配置。+确认 bucket 是否已创建:`docker compose exec rustfs ls /data/lobe`**磁盘空间不足**diff --git a/scripts/dockerComposeDeploy.test.ts b/scripts/dockerComposeDeploy.test.tsindex 5c667285564..718786ba96c 100644--- a/scripts/dockerComposeDeploy.test.ts+++ b/scripts/dockerComposeDeploy.test.ts@@ -1,4 +1,6 @@-import { readFileSync } from 'node:fs';+import { execFileSync } from 'node:child_process';+import { chmodSync, mkdtempSync, readFileSync, symlinkSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';import path from 'node:path';import { describe, expect, it } from 'vitest';@@ -14,7 +16,7 @@ const compose = parse(readFileSync(path.join(deployDirectory, 'docker-compose.ymdepends_on?: Record<string, { condition: string }>;entrypoint?: string[];environment?: string[];- healthcheck?: { test: string[] };+ healthcheck?: { start_period?: string; test: string[] };image: string;ports?: string[];profiles?: string[];@@ -37,6 +39,39 @@ const envExamples = ['.env.example', '.env.zh-CN.example'].map((file) =>const ELASTICSEARCH_PROFILES = ['elasticsearch', 'elasticsearch-reindex', 'elasticsearch-sync'];+describe.each(['deploy', 'dev'])('%s docker-compose rustfs-init', (directory) => {+ const rustfsInit = (+ parse(+ readFileSync(+ path.resolve(import.meta.dirname, '../docker-compose', directory, 'docker-compose.yml'),+ 'utf8',+ ),+ ) as { services: Record<string, { command: string }> }+ ).services['rustfs-init'];++ it('lets browsers upload to the bucket through presigned URLs on the RustFS origin', () => {+ // Without a bucket CORS rule RustFS answers the preflight without Access-Control-Allow-*+ // headers, so the browser blocks the presigned PUT and in-chat uploads silently fail.+ const corsStep = rustfsInit.command.match(+ /printf "%s" "(<CORSConfiguration>.*?<\/CORSConfiguration>)" \| rc bucket cors set "rustfs\/lobe" -;/,+ );++ expect(corsStep).not.toBeNull();+ const rule = corsStep![1];+ expect(rule).toContain('<AllowedOrigin>*</AllowedOrigin>');+ for (const method of ['GET', 'PUT', 'HEAD']) {+ expect(rule).toContain(`<AllowedMethod>${method}</AllowedMethod>`);+ }+ expect(rule).toContain('<ExposeHeader>ETag</ExposeHeader>');+ });++ it('applies the CORS rule after the bucket exists', () => {+ expect(rustfsInit.command.indexOf('rc mb "rustfs/lobe"')).toBeLessThan(+ rustfsInit.command.indexOf('rc bucket cors set'),+ );+ });+});+describe('deploy docker-compose optional Elasticsearch', () => {const {elasticsearch,@@ -193,3 +228,103 @@ describe('deploy docker-compose optional Elasticsearch', () => {}});});++describe('deploy docker-compose first start', () => {+ it('reports PostgreSQL healthy only once it accepts TCP connections', () => {+ // First-time initialization runs a temporary server on the Unix socket only. A socket probe+ // passed there, LobeHub started early, and its migrations failed with ECONNREFUSED until the+ // container had restarted several times.+ const { healthcheck } = compose.services.postgresql;++ expect(healthcheck?.test.join(' ')).toContain('pg_isready -U postgres -h 127.0.0.1');+ expect(healthcheck?.start_period).toBe('60s');+ });++ it('preloads every library the ParadeDB first-start bootstrap needs', () => {+ // The image bootstrap runs CREATE EXTENSION pg_cron under `set -e`. Preloading only pg_search+ // aborted initialization, the container restarted, and the first `docker compose up` failed+ // with "container lobe-postgres is unhealthy" before LobeHub started.+ const preload = compose.services.postgresql+ .command!.find((argument) => argument.startsWith('shared_preload_libraries='))!+ .split('=')[1]+ .split(',');++ expect(preload).toEqual(expect.arrayContaining(['pg_search', 'pg_cron', 'pg_stat_statements']));+ });+});++describe('setup.sh one-click install', () => {+ const awkPath = execFileSync('/bin/sh', ['-c', 'command -v awk'], { encoding: 'utf8' }).trim();++ const extractFunction = (name: string) => {+ const match = setupScript.match(new RegExp(`^${name}\\(\\) \\{\\n[\\s\\S]*?\\n\\}`, 'm'));+ expect(match).not.toBeNull();+ return match![0];+ };++ /** A PATH that holds only the given stubs plus awk, so no host tool can leak into the result. */+ const createStubPath = (stubs: Record<string, string>) => {+ const bin = mkdtempSync(path.join(tmpdir(), 'setup-sh-'));+ for (const [name, body] of Object.entries(stubs)) {+ const file = path.join(bin, name);+ writeFileSync(file, `#!/bin/sh\n${body}\n`);+ chmodSync(file, 0o755);+ }+ symlinkSync(awkPath, path.join(bin, 'awk'));+ return bin;+ };++ const runInBash = (script: string, bin: string) =>+ execFileSync('/bin/bash', ['-c', script], {+ cwd: bin,+ encoding: 'utf8',+ env: { PATH: bin },+ }).trim();++ it('downloads the templates from the branch the released image is built from', () => {+ expect(setupScript).toContain(+ 'SOURCE_URL="https://raw.githubusercontent.com/lobehub/lobehub/main"',+ );+ });++ it('detects the host IP with hostname -I on Linux', () => {+ const bin = createStubPath({ hostname: 'echo "10.0.0.5 172.17.0.1"' });++ expect(runInBash(`${extractFunction('detect_host_ip')}\ndetect_host_ip`, bin)).toBe('10.0.0.5');+ });++ it('falls back to the default route source address when hostname -I is unsupported', () => {+ const bin = createStubPath({+ hostname: 'echo "hostname: illegal option -- I" >&2; exit 1',+ ip: 'echo "1.1.1.1 via 10.0.0.1 dev eth0 src 10.0.0.9 uid 0"',+ });++ expect(runInBash(`${extractFunction('detect_host_ip')}\ndetect_host_ip`, bin)).toBe('10.0.0.9');+ });++ it('detects the host IP on macOS, where hostname -I and ip are unavailable', () => {+ const bin = createStubPath({+ hostname: 'echo "hostname: illegal option -- I" >&2; exit 1',+ ipconfig: '[ "$1" = getifaddr ] && [ "$2" = en0 ] && echo 192.168.1.20',+ route: 'echo " interface: en0"',+ });++ expect(runInBash(`${extractFunction('detect_host_ip')}\ndetect_host_ip`, bin)).toBe(+ '192.168.1.20',+ );+ });++ it('downloads with curl, which macOS ships, before falling back to wget', () => {+ const downloadFile = extractFunction('download_file');+ const script = `${downloadFile}\ndownload_file https://example.com/file out.txt && echo "$(< out.txt)"`;++ const withCurl = createStubPath({+ curl: 'for last; do :; done; echo curl > "$last"',+ wget: 'echo wget > "$3"',+ });+ expect(runInBash(script, withCurl)).toBe('curl');++ const wgetOnly = createStubPath({ wget: 'echo wget > "$3"' });+ expect(runInBash(script, wgetOnly)).toBe('wget');+ });+});