Add initial Docker setup and configuration for self-hosted LiveSync with CouchDB

This commit is contained in:
mugenrei
2026-02-18 09:46:49 -03:00
parent b1bba7685e
commit f99d7dc00f
8 changed files with 637 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
# Caddy config for Self-hosted LiveSync CouchDB
# =============================================================================
# IMPORTANT: CouchDB handles CORS itself.
# Do NOT add CORS headers here — they will conflict with CouchDB's own headers.
# Do NOT intercept OPTIONS requests.
# =============================================================================
{
# Email used for Let's Encrypt certificate notifications
email {$ACME_EMAIL}
}
{$COUCHDB_DOMAIN} {
# Forward all traffic to CouchDB, preserving Host and forwarded-for headers
reverse_proxy couchdb:5984 {
header_up Host {host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
}
# Logging
log {
output stdout
level WARN
}
}
+31
View File
@@ -0,0 +1,31 @@
# cloudflared tunnel configuration for Self-hosted LiveSync
# =============================================================================
#
# Prerequisites:
# 1. Create a tunnel in Cloudflare Zero Trust → Networks → Tunnels
# 2. Copy the tunnel token to CF_TUNNEL_TOKEN in your .env
# 3. Add a public hostname in the tunnel config:
# Hostname : couchdb.yourdomain.com (or whatever you set COUCHDB_DOMAIN to)
# Service : http://couchdb:5984
#
# Known issue: Cloudflare's 100-second proxy timeout can interrupt CouchDB's
# long-polling replication change feed, causing 524 errors.
# MITIGATION: In the Obsidian plugin settings, enable:
# "Use Request API to avoid inevitable CORS problem"
# This switches from long-poll to short-poll mode.
#
# =============================================================================
tunnel: ${CF_TUNNEL_ID}
credentials-file: /etc/cloudflared/credentials.json
ingress:
- hostname: ${COUCHDB_DOMAIN}
service: http://couchdb:5984
originRequest:
# Increase timeouts for CouchDB replication streams
connectTimeout: 30s
keepAliveTimeout: 90s
keepAliveConnections: 100
noTLSVerify: false
- service: http_status:404
+30
View File
@@ -0,0 +1,30 @@
; CouchDB local configuration for Self-hosted LiveSync
; This file is volume-mounted into /opt/couchdb/etc/local.d/livesync.ini
;
; IMPORTANT: Do NOT set require_valid_user here.
; CouchDB needs to start without auth to complete its first-run cluster setup
; (_users, _replicator databases must be created first).
; The couchdb-init service applies auth lockdown via REST API after first-run.
[couchdb]
; Max size per document (50MB). Large enough for binary attachments.
max_document_size = 50000000
[chttpd]
; Bind on all interfaces.
bind_address = 0.0.0.0
port = 5984
; 4 GB max request (handles very large vaults)
max_http_request_size = 4294967296
[httpd]
WWW-Authenticate = Basic realm="couchdb"
[cors]
; These are the exact app origins Obsidian uses on desktop + mobile
credentials = true
origins = app://obsidian.md,capacitor://localhost,http://localhost
[log]
; Reduce noise in Docker logs — set to "debug" if troubleshooting
level = warning
+19
View File
@@ -0,0 +1,19 @@
{
"TCP": {
"443": {
"HTTPS": true
}
},
"Web": {
"${TS_CERT_DOMAIN}:443": {
"Handlers": {
"/": {
"Proxy": "http://127.0.0.1:5984"
}
}
}
},
"AllowFunnel": {
"${TS_CERT_DOMAIN}:443": true
}
}