docker deploy setup

This commit is contained in:
Nystik
2026-03-10 21:07:19 +01:00
parent d8d12054b7
commit 21952f8130
5 changed files with 125 additions and 14 deletions

67
Dockerfile Normal file
View File

@@ -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"]

11
docker-compose.yml Normal file
View File

@@ -0,0 +1,11 @@
services:
ignis:
build:
context: .
args:
OBSIDIAN_VERSION: "1.8.9"
ports:
- "8082:8080"
volumes:
- ./vault:/vault
restart: unless-stopped

38
scripts/patch-obsidian.js Normal file
View File

@@ -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 <extracted-asar-dir>");
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*<meta\s+http-equiv="Content-Security-Policy"[^>]*>\s*/g,
"\n",
);
// Inject shim-loader before the first <script> tag
html = html.replace(
'<script type="text/javascript"',
'<!-- Shim loader MUST load before everything else (no defer) -->\n' +
'<script type="text/javascript" src="shim-loader.js"></script>\n' +
'<script type="text/javascript"',
);
fs.writeFileSync(indexPath, html);
console.log(`[patch] Patched ${indexPath}`);

View File

@@ -1,7 +1,9 @@
const path = require('path');
const path = require("path");
module.exports = {
port: process.env.PORT || 8080,
vaultPath: process.env.VAULT_PATH || path.join(__dirname, '..', 'test-vault'),
obsidianAssetsPath: path.join(__dirname, '..', 'investigation', 'obsidian.asar.unpacked'),
vaultPath: process.env.VAULT_PATH || path.join(__dirname, "..", "test-vault"),
obsidianAssetsPath:
process.env.OBSIDIAN_ASSETS_PATH ||
path.join(__dirname, "..", "investigation", "obsidian.asar.unpacked"),
};

View File

@@ -40,18 +40,11 @@ app.use("/api/vault", vaultRoutes);
app.use("/vault-files", express.static(config.vaultPath));
// --- Static serving ---
// Serve the built shim-loader.js
app.use(
"/shim-loader.js",
express.static(path.join(__dirname, "..", "dist", "shim-loader.js")),
);
// dist/ has shim-loader.js + patched index.html (dev mode).
// In Docker, these live inside the obsidian assets dir instead.
app.use(express.static(path.join(__dirname, "..", "dist")));
// Serve patched index.html at root
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "..", "dist", "index.html"));
});
// Serve obsidian assets
// Serve obsidian assets (app.js, app.css, libs, fonts, etc.)
app.use(express.static(config.obsidianAssetsPath));
// --- Start ---