From 6ce724afb47f3de63b2ab90d5a3a4b29513019ac Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Thu, 2 Apr 2026 10:33:13 +0100 Subject: [PATCH] Add dockerfiles to webapp and webpeer --- src/apps/webapp/Dockerfile | 58 +++++++++++++++++++++++++++++++++++ src/apps/webapp/package.json | 2 ++ src/apps/webpeer/Dockerfile | 57 ++++++++++++++++++++++++++++++++++ src/apps/webpeer/package.json | 2 ++ 4 files changed, 119 insertions(+) create mode 100644 src/apps/webapp/Dockerfile create mode 100644 src/apps/webpeer/Dockerfile diff --git a/src/apps/webapp/Dockerfile b/src/apps/webapp/Dockerfile new file mode 100644 index 0000000..fbad070 --- /dev/null +++ b/src/apps/webapp/Dockerfile @@ -0,0 +1,58 @@ +# syntax=docker/dockerfile:1 +# +# Self-hosted LiveSync WebApp — Docker image +# Browser-based vault sync using the FileSystem API, served by nginx. +# +# Build (from the repository root): +# docker build -f src/apps/webapp/Dockerfile -t livesync-webapp . +# +# Run: +# docker run --rm -p 8080:80 livesync-webapp +# Then open http://localhost:8080/webapp.html in Chrome/Edge 86+. +# +# Notes: +# - This image serves purely static files; no server-side code is involved. +# - The FileSystem API is a browser feature and requires Chrome/Edge 86+ or +# Safari 15.2+ (limited). Firefox is not supported. +# - CouchDB / S3 connections are made directly from the browser; the container +# only serves HTML/JS/CSS assets. + +# ───────────────────────────────────────────────────────────────────────────── +# Stage 1 — builder +# Full Node.js environment to install dependencies and build the Vite bundle. +# ───────────────────────────────────────────────────────────────────────────── +FROM node:22-slim AS builder + +WORKDIR /build + +# Install workspace dependencies (all apps share the root package.json) +COPY package.json ./ +RUN npm install + +# Copy the full source tree and build the WebApp bundle +COPY . . +RUN cd src/apps/webapp && npm run build + +# ───────────────────────────────────────────────────────────────────────────── +# Stage 2 — runtime +# Minimal nginx image that serves the static build output. +# ───────────────────────────────────────────────────────────────────────────── +FROM nginx:stable-alpine + +# Remove the default nginx welcome page +RUN rm -rf /usr/share/nginx/html/* + +# Copy the built static assets +COPY --from=builder /build/src/apps/webapp/dist /usr/share/nginx/html + +# Redirect the root to webapp.html so the app loads on first visit +RUN printf 'server {\n\ + listen 80;\n\ + root /usr/share/nginx/html;\n\ + index webapp.html;\n\ + location / {\n\ + try_files $uri $uri/ =404;\n\ + }\n\ +}\n' > /etc/nginx/conf.d/default.conf + +EXPOSE 80 diff --git a/src/apps/webapp/package.json b/src/apps/webapp/package.json index 414c3e7..07e8f94 100644 --- a/src/apps/webapp/package.json +++ b/src/apps/webapp/package.json @@ -7,6 +7,8 @@ "scripts": { "dev": "vite", "build": "vite build", + "build:docker": "docker build -f Dockerfile -t livesync-webapp ../../..", + "run:docker": "docker run -p 8002:80 livesync-webapp", "preview": "vite preview" }, "dependencies": {}, diff --git a/src/apps/webpeer/Dockerfile b/src/apps/webpeer/Dockerfile new file mode 100644 index 0000000..ed69068 --- /dev/null +++ b/src/apps/webpeer/Dockerfile @@ -0,0 +1,57 @@ +# syntax=docker/dockerfile:1 +# +# Self-hosted LiveSync WebPeer — Docker image +# Browser-based P2P peer daemon served by nginx. +# +# Build (from the repository root): +# docker build -f src/apps/webpeer/Dockerfile -t livesync-webpeer . +# +# Run: +# docker run --rm -p 8081:80 livesync-webpeer +# Then open http://localhost:8081/ in any modern browser. +# +# What is WebPeer? +# WebPeer acts as a pseudo P2P peer that runs entirely in the browser. +# It can replace a CouchDB remote server by replying to sync requests from +# other Self-hosted LiveSync instances over the WebRTC P2P channel. +# +# P2P (WebRTC) networking notes +# ───────────────────────────── +# WebRTC connections are initiated by the *browser* visiting this page, not by +# the nginx container itself. Therefore the Docker network mode of this +# container has NO effect on WebRTC connectivity. +# Simply publish port 80 (as above) and the browser handles all ICE/STUN/TURN +# negotiation on its own. +# +# If the browser is running inside another container or a restricted network, +# configuring a TURN server in the WebPeer settings is recommended. + +# ───────────────────────────────────────────────────────────────────────────── +# Stage 1 — builder +# Full Node.js environment to install dependencies and build the Vite bundle. +# ───────────────────────────────────────────────────────────────────────────── +FROM node:22-slim AS builder + +WORKDIR /build + +# Install workspace dependencies (all apps share the root package.json) +COPY package.json ./ +RUN npm install + +# Copy the full source tree and build the WebPeer bundle +COPY . . +RUN cd src/apps/webpeer && npm run build + +# ───────────────────────────────────────────────────────────────────────────── +# Stage 2 — runtime +# Minimal nginx image that serves the static build output. +# ───────────────────────────────────────────────────────────────────────────── +FROM nginx:stable-alpine + +# Remove the default nginx welcome page +RUN rm -rf /usr/share/nginx/html/* + +# Copy the built static assets +COPY --from=builder /build/src/apps/webpeer/dist /usr/share/nginx/html + +EXPOSE 80 diff --git a/src/apps/webpeer/package.json b/src/apps/webpeer/package.json index 584432c..b2201f6 100644 --- a/src/apps/webpeer/package.json +++ b/src/apps/webpeer/package.json @@ -6,6 +6,8 @@ "scripts": { "dev": "vite", "build": "vite build", + "build:docker": "docker build -f Dockerfile -t livesync-webpeer ../../..", + "run:docker": "docker run -p 8001:80 livesync-webpeer", "preview": "vite preview", "check": "svelte-check --tsconfig ./tsconfig.app.json && tsc -p tsconfig.node.json" },