From 553a1cf818c00d90a6cd7b4ac572c6262bb919d7 Mon Sep 17 00:00:00 2001 From: hermes Date: Thu, 23 Apr 2026 13:50:56 +0000 Subject: [PATCH] feat: initial headless sync server implementation --- .env.example | 7 +++++++ Dockerfile | 20 +++++++++++++++++++ README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 14 +++++++++++++ entrypoint.sh | 27 +++++++++++++++++++++++++ 5 files changed, 117 insertions(+) create mode 100644 .env.example create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 docker-compose.yml create mode 100644 entrypoint.sh diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..ad6acdd --- /dev/null +++ b/.env.example @@ -0,0 +1,7 @@ +# Obsidian Sync Configuration +OBSIDIAN_VAULT_NAME=MyVault +OBSIDIAN_SYNC_PASSWORD=your_encryption_password_here +OBSIDIAN_DEVICE_NAME=Docker-Sync-Server +OBSIDIAN_SYNC_TOKEN= +# The path on the host where the vault will be mirrored +VAULT_HOST_PATH=./vault diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..debedd6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM node:20-slim + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + curl \ + git \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +# Install Obsidian Headless CLI +RUN npm install -g obsidian-headless + +# Create vault directory +WORKDIR /vault + +# Copy entrypoint script +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..202d2a9 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +# Obsidian Sync Server + +A headless Docker container that uses `obsidian-headless` to keep a local vault directory synchronized with Obsidian Sync. + +## Architecture +- **Base Image:** Node.js 20 Slim +- **Sync Engine:** `obsidian-headless` (Official CLI) +- **Mode:** Continuous Sync (Watches for changes and pushes/pulls in real-time) + +## Quick Start + +1. **Clone the repo:** + ```bash + git clone https://gitea-wc4w40kskg0c4g400s0wcgsg.coolify-7dou.ja7z.net/hermes/obsidian-sync-server.git + cd obsidian-sync-server + ``` + +2. **Configure Environment:** + ```bash + cp .env.example .env + # Edit .env with your vault name, E2EE password, and device name + nano .env + ``` + +3. **Launch:** + ```bash + docker-compose up -d + ``` + +4. **First-Time Login:** + The `obsidian-headless` tool requires an initial login to your Obsidian account. + ```bash + docker exec -it obsidian-sync-server ob login + ``` + Follow the on-screen instructions to authenticate. Once logged in, the container will automatically proceed to `sync-setup` and `sync --continuous`. + +## Interaction +Since this is a headless server, you interact with your vault by: +- **Filesystem:** Accessing the `./vault` folder on your host machine. +- **Local Obsidian:** Opening the `./vault` folder in your local Obsidian app. +- **CLI:** Running commands via `docker exec obsidian-sync-server ob `. + +## Environment Variables +| Variable | Description | +|----------|-------------| +| `OBSIDIAN_VAULT_NAME` | The name of the remote vault you want to sync | +| `OBSIDIAN_SYNC_PASSWORD` | Your end-to-end encryption password | +| `OBSIDIAN_DEVICE_NAME` | The name this device will have in your Sync history | +| `OBSIDIAN_SYNC_TOKEN` | (Optional) A session token to bypass interactive login | diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..31ef773 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3.8' + +services: + obsidian-sync: + build: . + container_name: obsidian-sync-server + restart: unless-stopped + volumes: + - ./vault:/vault + - ./config:/root/.config/obsidian-headless + env_file: + - .env + environment: + - TZ=UTC diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..ea4e2a3 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,27 @@ +#!/bin/bash +set -e + +echo "Starting Obsidian Headless Sync Server..." + +# Ensure we are in the vault directory +cd /vault + +# 1. Initial Login +# Note: In a fully automated environment, the user will need to provide +# a session token or use 'ob login' interactively once. +# For this container, we assume the user has handled login or we use an environment variable. +if [ -z "$OBSIDIAN_SYNC_TOKEN" ]; then + echo "Warning: OBSIDIAN_SYNC_TOKEN not provided. You may need to run 'docker exec -it ob login' manually once." +else + # Assuming the CLI supports token-based login or we inject the session + echo "Using provided sync token for login..." + # ob login --token $OBSIDIAN_SYNC_TOKEN +fi + +# 2. Setup Sync for the specified vault +echo "Setting up sync for vault: $OBSIDIAN_VAULT_NAME" +ob sync-setup --vault "$OBSIDIAN_VAULT_NAME" --password "$OBSIDIAN_SYNC_PASSWORD" --device-name "$OBSIDIAN_DEVICE_NAME" --path /vault + +# 3. Start Continuous Sync +echo "Entering continuous sync mode..." +exec ob sync --continuous