From 0ca3d35fa0d313910537f487b33e7507e91243fb Mon Sep 17 00:00:00 2001 From: Acbox Date: Sat, 7 Mar 2026 19:18:13 +0800 Subject: [PATCH] script: update version management --- README.md | 15 ++++-- README_CN.md | 15 ++++-- docs/docs/installation/docker.md | 86 +++--------------------------- scripts/install.sh | 91 +++++++++++++++++++++++--------- 4 files changed, 95 insertions(+), 112 deletions(-) diff --git a/README.md b/README.md index 2da98322..6810f907 100644 --- a/README.md +++ b/README.md @@ -48,11 +48,16 @@ cd Memoh sudo docker compose up -d ``` -> If you experience slow image pulls, use the CN override: -```bash -sudo docker compose -f docker-compose.yml -f docker/docker-compose.cn.yml up -d -``` - +> **Install a specific version:** +> ```bash +> MEMOH_VERSION=v1.0.0 curl -fsSL https://memoh.sh | sudo sh +> ``` +> +> **Use CN mirror for slow image pulls:** +> ```bash +> USE_CN_MIRROR=true curl -fsSL https://memoh.sh | sudo sh +> ``` +> > On macOS or if your user is in the `docker` group, `sudo` is not required. Visit after startup. Default login: `admin` / `admin123` diff --git a/README_CN.md b/README_CN.md index 48d1c264..e05b34ef 100644 --- a/README_CN.md +++ b/README_CN.md @@ -48,11 +48,16 @@ cd Memoh sudo docker compose up -d ``` -> 若镜像拉取较慢,可使用中国大陆镜像源配置: -```bash -sudo docker compose -f docker-compose.yml -f docker/docker-compose.cn.yml up -d -``` - +> **安装指定版本:** +> ```bash +> MEMOH_VERSION=v1.0.0 curl -fsSL https://memoh.sh | sudo sh +> ``` +> +> **使用中国大陆镜像加速:** +> ```bash +> USE_CN_MIRROR=true curl -fsSL https://memoh.sh | sudo sh +> ``` +> > macOS 或用户已在 `docker` 用户组中时,无需 `sudo`。 启动后访问 。默认登录:`admin` / `admin123` diff --git a/docs/docs/installation/docker.md b/docs/docs/installation/docker.md index 9db3e927..2940a3eb 100644 --- a/docs/docs/installation/docker.md +++ b/docs/docs/installation/docker.md @@ -22,8 +22,7 @@ The script will: 2. Prompt for configuration (workspace, data directory, admin credentials, JWT secret, Postgres password, China mirror) 3. Clone the repository 4. Generate `config.toml` from the Docker template with your settings -5. Write a `.env` file with `POSTGRES_PASSWORD` and `MEMOH_CONFIG` -6. Pull images and start all services +5. Pull images and start all services **Silent install** (use all defaults, no prompts): @@ -42,7 +41,7 @@ Defaults when running silently: ## Manual Install ```bash -git clone --depth 1 https://github.com/memohai/Memoh.git +git clone https://github.com/memohai/Memoh.git cd Memoh cp conf/app.docker.toml config.toml ``` @@ -51,7 +50,7 @@ Edit `config.toml` — at minimum change: - `admin.password` — Admin password - `auth.jwt_secret` — Generate with `openssl rand -base64 32` -- `postgres.password` — Database password (must match the `POSTGRES_PASSWORD` env var) +- `postgres.password` — Database password (also set `POSTGRES_PASSWORD` env var to match) Then start: @@ -59,22 +58,9 @@ Then start: sudo POSTGRES_PASSWORD=your-db-password docker compose up -d ``` -Alternatively, create a `.env` file in the project root: - -```env -POSTGRES_PASSWORD=your-db-password -MEMOH_CONFIG=./config.toml -``` - -Then simply run: - -```bash -sudo docker compose up -d -``` - > On macOS or if your user is in the `docker` group, `sudo` is not required. -> **Important**: `docker-compose.yml` mounts `${MEMOH_CONFIG:-./config.toml}` into the containers. You must create this file before starting — running without it will fail. +> **Important**: `docker-compose.yml` mounts `./config.toml` by default. You must create this file before starting — running without it will fail. ### China Mainland Mirror @@ -93,21 +79,6 @@ sudo docker compose -f docker-compose.yml -f docker/docker-compose.cn.yml up -d The install script handles this automatically when you answer "yes" to the China mirror prompt. -## Service Architecture - -Docker Compose starts the following services: - -| Service | Image | Description | -|------------|-----------------------------|-----------------------------------------------------------------------------| -| `postgres` | `postgres:18-alpine` | PostgreSQL database | -| `qdrant` | `qdrant/qdrant:latest` | Qdrant vector database for memory semantic search | -| `migrate` | `memohai/server:latest` | One-shot service — runs database migrations, then exits | -| `server` | `memohai/server:latest` | Main backend with embedded Containerd (privileged) | -| `agent` | `memohai/agent:latest` | Agent Gateway (Bun/Elysia) for AI chat, tool execution, and SSE streaming | -| `web` | `memohai/web:latest` | Web UI (Vue 3 + Nginx) | - -Startup order: `postgres` and `qdrant` start first; once healthy, `migrate` runs database migrations; after migration completes, `server` starts; finally `agent` and `web` come up. - ## Access Points After startup: @@ -122,24 +93,6 @@ Default login: `admin` / `admin123` (change this in `config.toml`). First startup may take 1–2 minutes while images are pulled and services initialize. -## Data Persistence - -All persistent data is stored in Docker named volumes: - -| Volume | Description | -|---------------------|------------------------------------------| -| `postgres_data` | PostgreSQL database files | -| `qdrant_data` | Qdrant vector storage | -| `containerd_data` | Containerd image store and snapshots | -| `memoh_data` | Bot container data (mounted at `/opt/memoh/data` inside the server) | -| `server_cni_state` | CNI network state for container networking | - -These volumes survive `docker compose down`. To fully reset all data, run: - -```bash -docker compose down -v -``` - ## Common Commands > Prefix with `sudo` on Linux if your user is not in the `docker` group. @@ -148,51 +101,28 @@ docker compose down -v docker compose up -d # Start docker compose down # Stop docker compose logs -f # View logs -docker compose logs server # View a specific service's logs docker compose ps # Status docker compose pull && docker compose up -d # Update to latest images ``` -## Upgrading - -To upgrade to the latest version: - -```bash -cd /path/to/Memoh -git pull -docker compose pull -docker compose up -d -``` - -The `migrate` service runs automatically on every startup, applying any new database migrations. - -## Environment Variables - -| Variable | Default | Description | -|--------------------|------------------|----------------------------------------------| -| `POSTGRES_PASSWORD`| `memoh123` | PostgreSQL password (must match `postgres.password` in `config.toml`) | -| `MEMOH_CONFIG` | `./config.toml` | Path to the configuration file | - ## Production Checklist 1. **Passwords** — Change all default passwords and secrets in `config.toml` 2. **HTTPS** — Configure SSL (e.g. via `docker-compose.override.yml` with certs or a reverse proxy) 3. **Firewall** — Restrict access to necessary ports 4. **Resource limits** — Set memory/CPU limits for containers -5. **Backups** — Regular backups of Postgres and Qdrant data volumes +5. **Backups** — Regular backups of Postgres and Qdrant data ## Troubleshooting ```bash docker compose logs server # View main service logs -docker compose logs migrate # Check if migrations succeeded -docker compose config # Validate compose configuration -docker compose down && docker compose up -d # Full restart +docker compose config # Validate configuration +docker compose build --no-cache && docker compose up -d # Full rebuild ``` - ## Security Warnings -- The main service runs with privileged container access (required for embedded Containerd) — only run in trusted environments +- The main service runs with privileged container access — only run in trusted environments - You must change all default passwords and secrets before production use - Use HTTPS in production diff --git a/scripts/install.sh b/scripts/install.sh index fd9fafe6..2b31a4fa 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -3,10 +3,12 @@ set -e GREEN='\033[0;32m' YELLOW='\033[1;33m' +PURPLE='\033[0;35m' RED='\033[0;31m' NC='\033[0m' -REPO="https://github.com/memohai/Memoh.git" +GITHUB_REPO="memohai/Memoh" +REPO="https://github.com/${GITHUB_REPO}.git" DIR="Memoh" SILENT=false @@ -22,10 +24,7 @@ if [ "$SILENT" = false ] && ! [ -e /dev/tty ]; then SILENT=true fi -echo "${GREEN}========================================${NC}" -echo "${GREEN} Memoh One-Click Install${NC}" -echo "${GREEN}========================================${NC}" -echo "" +echo "${PURPLE}Memoh One-Click Install${NC}" # Check Docker and determine if sudo is needed DOCKER="docker" @@ -49,10 +48,38 @@ if ! $DOCKER compose version >/dev/null 2>&1; then exit 1 fi echo "${GREEN}✓ Docker and Docker Compose detected${NC}" -echo "" -echo "${GREEN}✓ Install mode: latest Docker images${NC}" -echo "" +# Resolve version: use MEMOH_VERSION env if set, otherwise fetch latest release +VERSION_USER_PROVIDED=false +if [ -n "$MEMOH_VERSION" ]; then + VERSION_USER_PROVIDED=true + echo "${GREEN}✓ Using specified version: ${MEMOH_VERSION}${NC}" +else + fetch_latest_version() { + if command -v curl >/dev/null 2>&1; then + curl -fsSL "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" 2>/dev/null + elif command -v wget >/dev/null 2>&1; then + wget -qO- "https://api.github.com/repos/${GITHUB_REPO}/releases/latest" 2>/dev/null + else + echo "${RED}Error: curl or wget is required${NC}" >&2 + exit 1 + fi + } + MEMOH_VERSION=$(fetch_latest_version | grep '"tag_name"' | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/') + if [ -n "$MEMOH_VERSION" ]; then + echo "${GREEN}✓ Latest release: ${MEMOH_VERSION}${NC}" + else + echo "${YELLOW}Warning: Failed to fetch latest release tag, falling back to main branch${NC}" + fi +fi + +# Docker image tag: pin to version only when user explicitly specified MEMOH_VERSION +if [ "$VERSION_USER_PROVIDED" = true ]; then + MEMOH_DOCKER_VERSION=$(echo "$MEMOH_VERSION" | sed 's/^v//') +else + MEMOH_DOCKER_VERSION="latest" +fi +echo "${GREEN}✓ Docker image version: ${MEMOH_DOCKER_VERSION}${NC}" # Generate random JWT secret gen_secret() { @@ -129,21 +156,38 @@ fi mkdir -p "$WORKSPACE" cd "$WORKSPACE" -# Clone repository or update local checkout +# Clone or update if [ -d "$DIR" ]; then echo "Updating existing installation in $WORKSPACE..." cd "$DIR" - DEFAULT_BRANCH=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's@^origin/@@') - [ -z "$DEFAULT_BRANCH" ] && DEFAULT_BRANCH="main" - git fetch --depth 1 origin "$DEFAULT_BRANCH" 2>/dev/null || git fetch --depth 1 origin - git checkout "$DEFAULT_BRANCH" 2>/dev/null || git checkout -b "$DEFAULT_BRANCH" --track "origin/$DEFAULT_BRANCH" - git pull --ff-only origin "$DEFAULT_BRANCH" + if [ -n "$MEMOH_VERSION" ]; then + git fetch --depth 1 origin tag "$MEMOH_VERSION" + git checkout "$MEMOH_VERSION" + else + git fetch --depth 1 origin main + git checkout main 2>/dev/null || git checkout -b main --track origin/main + git reset --hard origin/main + fi else echo "Cloning Memoh into $WORKSPACE..." - git clone --depth 1 "$REPO" "$DIR" + if [ -n "$MEMOH_VERSION" ]; then + git clone --depth 1 --branch "$MEMOH_VERSION" "$REPO" "$DIR" + else + git clone --depth 1 "$REPO" "$DIR" + fi cd "$DIR" fi +# Pin Docker image versions in docker-compose.yml +if [ "$MEMOH_DOCKER_VERSION" != "latest" ]; then + sed -i.bak "s|memohai/server:latest|memohai/server:${MEMOH_DOCKER_VERSION}|g" docker-compose.yml + sed -i.bak "s|memohai/agent:latest|memohai/agent:${MEMOH_DOCKER_VERSION}|g" docker-compose.yml + sed -i.bak "s|memohai/web:latest|memohai/web:${MEMOH_DOCKER_VERSION}|g" docker-compose.yml + sed -i.bak "s|memohai/browser:latest|memohai/browser:${MEMOH_DOCKER_VERSION}|g" docker-compose.yml + rm -f docker-compose.yml.bak + echo "${GREEN}✓ Docker images pinned to ${MEMOH_DOCKER_VERSION}${NC}" +fi + # Generate config.toml from template cp conf/app.docker.toml config.toml sed -i.bak "s|username = \"admin\"|username = \"${ADMIN_USER}\"|" config.toml @@ -181,20 +225,19 @@ echo "${GREEN}Starting services (first startup may take a few minutes)...${NC}" $DOCKER compose $COMPOSE_FILES up -d echo "" -echo "${GREEN}========================================${NC}" -echo "${GREEN} Memoh is running!${NC}" -echo "${GREEN}========================================${NC}" +echo "${GREEN}✅ Memoh is running!${NC}${NC}" echo "" -echo " Web UI: http://localhost:8082" -echo " API: http://localhost:8080" -echo " Agent Gateway: http://localhost:8081" +echo " 🌐 Web UI: http://localhost:8082" +echo " 🔌 API: http://localhost:8080" +echo " 🤖 Agent Gateway: http://localhost:8081" +echo " 🌍 Browser Gateway: http://localhost:8083" echo "" -echo " Admin login: ${ADMIN_USER} / ${ADMIN_PASS}" +echo " 🔑 Admin login: ${ADMIN_USER} / ${ADMIN_PASS}" echo "" COMPOSE_CMD="$DOCKER compose $COMPOSE_FILES" -echo "Commands:" +echo "📋 Commands:" echo " cd ${INSTALL_DIR} && ${COMPOSE_CMD} ps # Status" echo " cd ${INSTALL_DIR} && ${COMPOSE_CMD} logs -f # Logs" echo " cd ${INSTALL_DIR} && ${COMPOSE_CMD} down # Stop" echo "" -echo "${YELLOW}First startup may take 1-2 minutes, please be patient.${NC}" +echo "${YELLOW}⏳ First startup may take 1-2 minutes, please be patient.${NC}"