From bea99b868c912687f28765863abab626d38434b8 Mon Sep 17 00:00:00 2001 From: Luke Betteridge Date: Wed, 8 Apr 2026 13:24:25 +0100 Subject: [PATCH] Added Docker Support --- .dockerignore | 7 +++++++ README.md | 19 +++++++++++++++++++ apps/sync-server/Dockerfile | 35 +++++++++++++++++++++++++++++++++++ compose.yaml | 17 +++++++++++++++++ docs/deployment.md | 19 +++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 .dockerignore create mode 100644 apps/sync-server/Dockerfile create mode 100644 compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e1b2c20 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +node_modules/ +data/ +.git/ +.vscode/ +dist/ +coverage/ +*.log diff --git a/README.md b/README.md index 051f51f..0b1c960 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,23 @@ npm run dev:server The default server URL is `http://localhost:8787`. +## Run The Server In Docker + +Build and start the server with Docker Compose: + +```bash +docker compose up --build sync-server +``` + +Or build the image directly: + +```bash +docker build -f apps/sync-server/Dockerfile -t obsidian-sync-server . +docker run --rm -p 8787:8787 -v obsidian-sync-data:/app/data obsidian-sync-server +``` + +The Docker image persists server state in `/app/data`, which is backed by the `obsidian-sync-data` volume in `compose.yaml`. + ## Build The Obsidian Plugin The plugin build now emits a bundled `main.js` directly in `apps/obsidian-plugin`, beside `manifest.json`, which is the layout Obsidian expects for local plugins. @@ -93,6 +110,8 @@ Use the plugin settings device list to revoke a device that should no longer hav - `data/sync-state.json`: durable revision, device, tombstone, and key-status state - `data/logs/server.jsonl`: structured server and client-sync diagnostics +When running under Docker, these same files are stored under `/app/data` inside the container. + ## Current Limitations - The server storage backend is file-based rather than SQLite or PostgreSQL. diff --git a/apps/sync-server/Dockerfile b/apps/sync-server/Dockerfile new file mode 100644 index 0000000..e3fe16a --- /dev/null +++ b/apps/sync-server/Dockerfile @@ -0,0 +1,35 @@ +FROM node:22-alpine AS build + +WORKDIR /app + +COPY package.json package-lock.json ./ +COPY tsconfig.json tsconfig.base.json ./ +COPY apps ./apps +COPY packages ./packages + +RUN npm ci +RUN npm run build --workspace @obsidian-sync/sync-server +RUN npm prune --omit=dev + +FROM node:22-alpine AS runtime + +WORKDIR /app + +ENV NODE_ENV=production +ENV PORT=8787 +ENV SYNC_DATA_DIR=/app/data + +COPY --from=build /app/package.json ./package.json +COPY --from=build /app/package-lock.json ./package-lock.json +COPY --from=build /app/node_modules ./node_modules +COPY --from=build /app/apps/sync-server/package.json ./apps/sync-server/package.json +COPY --from=build /app/apps/sync-server/dist ./apps/sync-server/dist +COPY --from=build /app/packages/sync-protocol/package.json ./packages/sync-protocol/package.json +COPY --from=build /app/packages/sync-protocol/dist ./packages/sync-protocol/dist + +EXPOSE 8787 +VOLUME ["/app/data"] + +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 CMD node -e "fetch('http://127.0.0.1:8787/health').then((response)=>{if(!response.ok) process.exit(1);}).catch(()=>process.exit(1));" + +CMD ["node", "apps/sync-server/dist/index.js"] diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..e4fb27a --- /dev/null +++ b/compose.yaml @@ -0,0 +1,17 @@ +services: + sync-server: + container_name: obsidian-sync-server + build: + context: . + dockerfile: apps/sync-server/Dockerfile + environment: + PORT: 8787 + SYNC_DATA_DIR: /app/data + ports: + - "${OBSIDIAN_SYNC_PORT:-8787}:8787" + volumes: + - obsidian-sync-data:/app/data + restart: unless-stopped + +volumes: + obsidian-sync-data: diff --git a/docs/deployment.md b/docs/deployment.md index c71820a..c1fdd59 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -27,10 +27,28 @@ npm run dev:server The server listens on `http://localhost:8787` by default. +## Run With Docker + +Use Docker Compose from the repository root: + +```bash +docker compose up --build sync-server +``` + +Or build the image directly: + +```bash +docker build -f apps/sync-server/Dockerfile -t obsidian-sync-server . +docker run --rm -p 8787:8787 -v obsidian-sync-data:/app/data obsidian-sync-server +``` + +The compose setup binds port `8787` by default and stores durable state in a named Docker volume called `obsidian-sync-data`. + ## Environment Variables - `PORT`: overrides the default HTTP port. - `SYNC_DATA_DIR`: overrides the default data directory. If omitted, the server writes data under `./data` from the workspace root. +- `OBSIDIAN_SYNC_PORT`: optional compose override for the host port published by `compose.yaml`. ## Data Written By The Server @@ -50,3 +68,4 @@ The server listens on `http://localhost:8787` by default. - Request logs include a response header named `x-request-id` for correlating client and server failures. - The current storage backend is file-based. It is durable for a single-node deployment but not yet designed for clustered or high-availability hosting. - The plugin updates local sync state after each accepted push batch and each applied pull page, which lets interrupted sync runs resume from the last durable checkpoint. +- The Docker image includes a health check against `/health` and stores runtime data in `/app/data`.