Added Docker Support
This commit is contained in:
7
.dockerignore
Normal file
7
.dockerignore
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
node_modules/
|
||||||
|
data/
|
||||||
|
.git/
|
||||||
|
.vscode/
|
||||||
|
dist/
|
||||||
|
coverage/
|
||||||
|
*.log
|
||||||
19
README.md
19
README.md
@@ -54,6 +54,23 @@ npm run dev:server
|
|||||||
|
|
||||||
The default server URL is `http://localhost:8787`.
|
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
|
## 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.
|
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/sync-state.json`: durable revision, device, tombstone, and key-status state
|
||||||
- `data/logs/server.jsonl`: structured server and client-sync diagnostics
|
- `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
|
## Current Limitations
|
||||||
|
|
||||||
- The server storage backend is file-based rather than SQLite or PostgreSQL.
|
- The server storage backend is file-based rather than SQLite or PostgreSQL.
|
||||||
|
|||||||
35
apps/sync-server/Dockerfile
Normal file
35
apps/sync-server/Dockerfile
Normal file
@@ -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"]
|
||||||
17
compose.yaml
Normal file
17
compose.yaml
Normal file
@@ -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:
|
||||||
@@ -27,10 +27,28 @@ npm run dev:server
|
|||||||
|
|
||||||
The server listens on `http://localhost:8787` by default.
|
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
|
## Environment Variables
|
||||||
|
|
||||||
- `PORT`: overrides the default HTTP port.
|
- `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.
|
- `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
|
## 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.
|
- 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 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 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`.
|
||||||
|
|||||||
Reference in New Issue
Block a user