Prerequisites
Before deploying to production, ensure you have:- Latest version of Bun installed (expected as
bun) - Latest version of Docker or another container manager (expected as
docker) - Latest version of Caddy server (expected as
caddy) - A terminal with access to your server
- Server hardware (physical or virtual)
Deployment Steps
Configure environment variables
Copy and configure the environment file:Edit
Site/.env with your production settings:Site/.env
Start Caddy reverse proxy
Start the Caddy server to handle HTTPS and routing:To reload Caddy configuration without restarting:
If you’re using Caddy with multiple configuration files, import the Caddyfile from the repository root into your main Caddyfile, then run
caddy start and caddy reload from that location.Start services with Docker
Launch the database and economy services:
If you want to run the site in Docker as well, use
docker compose up -d to start all services. Otherwise, you’ll run the site directly with Bun.Build for production
Navigate to the Site directory and build:This command installs production dependencies and builds the optimized site.
Running as a Background Process
For production environments, you’ll want Mercury Core to run continuously in the background. Several methods are available:Option 1: PM2 (Recommended)
Option 2: GNU Screen
Option 3: Docker Container
Run the entire site in a Docker container:compose.yml file.
Option 4: Systemd Service
Create a systemd service file for automatic startup and management:/etc/systemd/system/mercury-core.service
Docker Services in Production
The production deployment uses three Docker services defined incompose.yml:
Database Service (SurrealDB)
- Port: 8000
- Storage: Persists to
./data/surreal - Credentials: root/root (change in production!)
- Backend: surrealkv
Economy Service
- Port: 2009
- Storage: Persists to
./data/economy - Language: Go
Site Service (Optional)
- Port: 4443
- Dependencies: Waits for database and economy services
- Runtime: Bun
Caddy Reverse Proxy
Caddy provides several production benefits:- Automatic HTTPS: Obtains and renews TLS certificates automatically
- URL Rewriting: Routes requests to appropriate endpoints
- Performance: Efficient reverse proxy with modern defaults
- Configuration: Simpler than Apache or nginx
The Caddyfile in the repository root contains pre-configured routing for Mercury Core. Review and adjust it based on your domain and client integration needs.
Data Directory Management
Thedata/ directory contains all runtime data and should be carefully managed:
data/assets- Binary asset files (images, meshes)data/economy- Transaction ledgerdata/icons- Place iconsdata/surreal- Database filesdata/thumbnails- Asset thumbnailsdata/PrivateKey.pem- Corescript signing key (if using client integration)
Backup Strategy
External Volume Mounting
For better data management and safety:compose.yml to use external volumes:
Security Considerations
Performance Optimization
Production Build
Thebun prod command creates an optimized build:
- Minified JavaScript and CSS
- Optimized assets
- Tree-shaking to remove unused code
- Production-only dependencies
Resource Limits
Configure body size limits in your.env:
Container Resources
Limit Docker container resources if needed:Monitoring and Logs
Docker Logs
PM2 Logs
Updating Mercury Core
To update your production deployment:Troubleshooting
Service Won’t Start
Check service status:Port Already in Use
Change the port inSite/.env:
Database Connection Issues
Verify the database is running:Next Steps
- Configure customization settings
- Set up client integration
- Review security best practices
- Monitor your deployment with appropriate tools