From 21952f8130cb9787631310dbf3467899eae76597 Mon Sep 17 00:00:00 2001 From: Nystik <236107-Nystik@users.noreply.gitlab.com> Date: Tue, 10 Mar 2026 21:07:19 +0100 Subject: [PATCH] docker deploy setup --- Dockerfile | 67 +++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 11 +++++++ scripts/patch-obsidian.js | 38 ++++++++++++++++++++++ server/config.js | 8 +++-- server/index.js | 15 +++------ 5 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 scripts/patch-obsidian.js diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e16eea9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,67 @@ +# Stage 1: Build shims and extract/patch Obsidian +FROM node:20-slim AS build + +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + binutils \ + xz-utils \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /build + +# Install dependencies first (layer caching) +COPY package.json package-lock.json ./ +RUN npm ci --ignore-scripts + +# Copy source +COPY build.js ./ +COPY shims/ ./shims/ +COPY scripts/ ./scripts/ +COPY server/ ./server/ + +# Build shim-loader bundle +RUN npm run build:shims + +# Download and extract Obsidian +ARG OBSIDIAN_VERSION=1.8.9 +RUN curl -fSL "https://github.com/obsidianmd/obsidian-releases/releases/download/v${OBSIDIAN_VERSION}/obsidian_${OBSIDIAN_VERSION}_amd64.deb" \ + -o /tmp/obsidian.deb \ + && mkdir -p /tmp/obsidian-deb \ + && ar x /tmp/obsidian.deb --output=/tmp/obsidian-deb \ + && mkdir -p /tmp/obsidian-pkg \ + && tar -xf /tmp/obsidian-deb/data.tar.xz -C /tmp/obsidian-pkg \ + && rm -rf /tmp/obsidian.deb /tmp/obsidian-deb + +# Extract asar +RUN npx --yes @electron/asar extract \ + /tmp/obsidian-pkg/opt/Obsidian/resources/obsidian.asar \ + /build/obsidian-app \ + && rm -rf /tmp/obsidian-pkg + +# Patch index.html +RUN node scripts/patch-obsidian.js /build/obsidian-app + +# Copy built shim-loader into the obsidian app directory +RUN cp dist/shim-loader.js /build/obsidian-app/shim-loader.js + +# Stage 2: Production image +FROM node:20-slim + +WORKDIR /app + +COPY package.json package-lock.json ./ +RUN npm ci --omit=dev --ignore-scripts + +COPY server/ ./server/ +COPY --from=build /build/obsidian-app ./obsidian-app + +ENV PORT=8080 +ENV VAULT_PATH=/vault +ENV OBSIDIAN_ASSETS_PATH=/app/obsidian-app + +EXPOSE 8080 + +VOLUME /vault + +CMD ["node", "server/index.js"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..27367d1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +services: + ignis: + build: + context: . + args: + OBSIDIAN_VERSION: "1.8.9" + ports: + - "8082:8080" + volumes: + - ./vault:/vault + restart: unless-stopped diff --git a/scripts/patch-obsidian.js b/scripts/patch-obsidian.js new file mode 100644 index 0000000..018bb9e --- /dev/null +++ b/scripts/patch-obsidian.js @@ -0,0 +1,38 @@ +#!/usr/bin/env node +// Patches the extracted Obsidian asar for browser use: +// 1. Removes Content-Security-Policy meta tag +// 2. Injects shim-loader.js script (non-deferred, before all other scripts) + +const fs = require("fs"); +const path = require("path"); + +const asarDir = process.argv[2]; +if (!asarDir) { + console.error("Usage: node patch-obsidian.js "); + process.exit(1); +} + +const indexPath = path.join(asarDir, "index.html"); +if (!fs.existsSync(indexPath)) { + console.error(`Not found: ${indexPath}`); + process.exit(1); +} + +let html = fs.readFileSync(indexPath, "utf-8"); + +// Remove CSP meta tag +html = html.replace( + /\s*]*>\s*/g, + "\n", +); + +// Inject shim-loader before the first \n' + + '