Skip to content

πŸš€ Complete Docker Swarm deployment solution for [Papermark](https://github.com/mfts/papermark) - the open-source DocSend alternative with built-in analytics and custom domains.

Notifications You must be signed in to change notification settings

mortenh77/papermark-self-host

 
 

Repository files navigation

Papermark Self-Hosted Deployment

πŸš€ Complete Docker Swarm deployment solution for Papermark - the open-source DocSend alternative with built-in analytics and custom domains.

Build & Push Papermark License: MIT

✨ Features

  • 🐳 Production-Ready Docker Deployment - Optimized multi-stage builds
  • πŸ”„ Automated CI/CD - GitHub Actions workflow with PR merging support
  • 🌐 Traefik Integration - Automatic SSL certificates and load balancing
  • πŸ—„οΈ PostgreSQL Database - Included with automatic backups
  • πŸ“¦ S3-Compatible Storage - AWS S3, MinIO, Backblaze B2, or any S3-compatible service
  • πŸ“§ Email Support - Resend integration for transactional emails
  • πŸ” OAuth Authentication - Google and GitHub login support
  • πŸ“Š Optional Analytics - Tinybird integration for document tracking
  • πŸ”„ High Availability - Multi-replica support with sticky sessions
  • πŸ”’ Security Hardened - Rate limiting, security headers, and best practices

πŸ“‹ What's Included

.
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── build-and-push.yml      # Automated build and push workflow
β”œβ”€β”€ docker-compose.papermark.yml     # Production stack configuration
β”œβ”€β”€ Dockerfile.papermark             # Optimized multi-stage Dockerfile
β”œβ”€β”€ .env.example                     # Environment configuration template
β”œβ”€β”€ DEPLOYMENT.md                    # Comprehensive deployment guide
β”œβ”€β”€ setup.sh                         # Interactive setup script
└── README.md                        # This file

πŸš€ Quick Start

Prerequisites

  • Docker Engine 20.10+ with Swarm mode
  • Traefik v2+ reverse proxy
  • Minimum 2GB RAM (4GB recommended)
  • Domain name with DNS configured

1. Clone Repository

git clone https://github.com/avnox-com/papermark-self-host.git
cd papermark-self-host

2. Run Setup Script

chmod +x setup.sh
./setup.sh

The interactive script will help you configure:

  • Domain name
  • Database credentials (auto-generated)
  • Storage backend (S3, MinIO, etc.)
  • Email service (Resend)
  • OAuth providers (Google, GitHub)

3. Deploy Stack

# Deploy to Docker Swarm
docker stack deploy -c docker-compose.papermark.yml papermark

# Check status
docker stack ps papermark

4. Access Your Instance

Visit https://your-domain.com and create your first account!

πŸ”§ Configuration

Essential Environment Variables

Copy .env.example to .env and configure:

# Core Settings
PAPERMARK_PUBLIC_URL=https://papermark.yourdomain.com
PAPERMARK_DOMAIN=papermark.yourdomain.com
NEXTAUTH_SECRET=your-secret-here

# Database
POSTGRES_PASSWORD=your-secure-password

# Storage (choose one)
AWS_ACCESS_KEY_ID=your-key
AWS_SECRET_ACCESS_KEY=your-secret
AWS_S3_BUCKET_NAME=your-bucket

# Email
RESEND_API_KEY=re_your-key
EMAIL_FROM=noreply@yourdomain.com

# Authentication (optional)
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-secret

See .env.example for all available options.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Traefik   β”‚ ← Reverse Proxy + SSL
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β”œβ”€β†’ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚   β”‚  Papermark   β”‚ ← Next.js Application (Multi-replica)
       β”‚   β”‚  (2 replicas)β”‚
       β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚          β”‚
       β”‚          β”œβ”€β†’ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚          β”‚   β”‚ PostgreSQL β”‚ ← Database
       β”‚          β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚          β”‚
       β”‚          └─→ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚              β”‚   Redis    β”‚ ← Caching
       β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       └─→ S3-Compatible Storage (AWS S3, MinIO, etc.)

πŸ€– CI/CD Workflow

The GitHub Actions workflow automatically:

  1. βœ… Checks out your repository
  2. βœ… Clones the latest Papermark source
  3. βœ… Optionally merges PRs for testing
  4. βœ… Builds optimized Docker images
  5. βœ… Pushes to your container registry
  6. βœ… Supports WireGuard for private registries

Configure GitHub Secrets

# Required
REGISTRY=ghcr.io
REGISTRY_USERNAME=your-github-username
REGISTRY_PASSWORD=your-github-token
IMAGE_PREFIX=ghcr.io/avnox-com

# Optional
REGISTRY_IP=10.0.0.1        # For private registry via WireGuard
WG_CONF=<wireguard-config>   # Full wg0.conf content

Merge PRs During Build

Edit .github/workflows/build-and-push.yml:

env:
  PAPERMARK_PRS: "123,456"  # PR numbers to merge and test

πŸ“š Storage Configuration

AWS S3

BLOB_STORAGE_TYPE=s3
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
AWS_S3_BUCKET_NAME=papermark-uploads
AWS_REGION=us-east-1

MinIO (Self-Hosted)

# Add MinIO to docker-compose and configure:
BLOB_STORAGE_TYPE=s3
AWS_ACCESS_KEY_ID=minioadmin
AWS_SECRET_ACCESS_KEY=minioadmin
S3_ENDPOINT=http://minio:9000
S3_FORCE_PATH_STYLE=true
AWS_S3_BUCKET_NAME=papermark

Other S3-Compatible (Backblaze B2, etc.)

BLOB_STORAGE_TYPE=s3
AWS_ACCESS_KEY_ID=your-key-id
AWS_SECRET_ACCESS_KEY=your-app-key
S3_ENDPOINT=https://s3.us-west-001.backblazeb2.com
AWS_S3_BUCKET_NAME=your-bucket
AWS_REGION=us-west-001

πŸ” Authentication Setup

Google OAuth

  1. Create project at Google Cloud Console
  2. Enable Google+ API
  3. Create OAuth 2.0 credentials
  4. Add redirect URI: https://yourdomain.com/api/auth/callback/google
  5. Add credentials to .env

GitHub OAuth

  1. Go to GitHub Developer Settings
  2. Create new OAuth App
  3. Set callback: https://yourdomain.com/api/auth/callback/github
  4. Add credentials to .env

πŸ› οΈ Management

View Logs

# All services
docker stack ps papermark

# Specific service
docker service logs -f papermark_papermark
docker service logs -f papermark_postgres

Scale Services

# Scale Papermark horizontally
docker service scale papermark_papermark=4

# Or edit .env and redeploy
PAPERMARK_REPLICAS=4
docker stack deploy -c docker-compose.papermark.yml papermark

Update Papermark

# Automatic via GitHub Actions
git push origin main

# Or manual
docker service update --image ghcr.io/avnox-com/papermark:latest papermark_papermark

Database Backups

Backups are automatic! Configure in .env:

BACKUP_PATH=./backups
BACKUP_SCHEDULE=@daily
BACKUP_KEEP_DAYS=7
BACKUP_KEEP_WEEKS=4
BACKUP_KEEP_MONTHS=6

Manual backup:

docker exec -it $(docker ps -q -f name=papermark_postgres) \
  pg_dump -U papermark papermark > backup-$(date +%Y%m%d).sql

πŸ“Š Monitoring

Health Checks

# Check service health
curl https://your-domain.com/api/health

# Service status
docker service ps papermark_papermark

Resource Usage

# Container stats
docker stats $(docker ps -q -f name=papermark)

# Service details
docker service inspect papermark_papermark --pretty

πŸ› Troubleshooting

Service Won't Start

# Check logs
docker service logs papermark_papermark --tail 100 --follow

# Inspect service
docker service ps papermark_papermark --no-trunc

Database Connection Issues

# Test connection
docker exec -it $(docker ps -q -f name=papermark_postgres) \
  psql -U papermark -d papermark -c "SELECT version();"

Storage Issues

# Test AWS S3
aws s3 ls s3://your-bucket --profile papermark

# Test MinIO
docker exec -it $(docker ps -q -f name=minio) \
  mc alias set local http://localhost:9000 minioadmin minioadmin

See DEPLOYMENT.md for comprehensive troubleshooting.

πŸ”’ Security Best Practices

βœ… Use strong, randomly generated secrets
βœ… Enable HTTPS only (enforced by Traefik)
βœ… Configure rate limiting (included)
βœ… Regular backups (automated)
βœ… Keep software updated
βœ… Use separate credentials for each service
βœ… Review logs for suspicious activity
βœ… Use firewall rules to restrict access

πŸ“ˆ Performance Optimization

  • Horizontal Scaling: Increase PAPERMARK_REPLICAS
  • Resource Limits: Adjust CPU/Memory in docker-compose
  • Redis Caching: Ensure Redis is running
  • CDN: Consider CloudFlare or similar for static assets
  • Database: Regular VACUUM ANALYZE and indexing

🀝 Contributing

Found a bug or have a feature request? Please open an issue!

Want to improve this deployment? PRs are welcome!

πŸ“ License

This deployment configuration is licensed under MIT.

Papermark itself is licensed under AGPL-3.0 - some features may require enterprise license for commercial use.

πŸ”— Links

πŸ™ Acknowledgments


Made with ❀️ for the self-hosting community

About

πŸš€ Complete Docker Swarm deployment solution for [Papermark](https://github.com/mfts/papermark) - the open-source DocSend alternative with built-in analytics and custom domains.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 38.7%
  • Shell 30.8%
  • Makefile 24.2%
  • TypeScript 6.3%