Deploying a Bugsink App
Introduction
Bugsink is a self-hosted, open-source error tracking platform that is Sentry-SDK compatible. It provides a scalable and reliable way to monitor and track errors in your applications. Deploying Bugsink on Klutch.sh gives you complete control over your error tracking infrastructure with automatic HTTPS, persistent storage for your error data, and seamless scaling capabilities.
This comprehensive guide walks you through deploying Bugsink on Klutch.sh using a Dockerfile, setting up persistent storage for your database and media files, configuring environment variables, connecting to PostgreSQL, and following production best practices for a robust error tracking system.
Prerequisites
Before you begin, ensure you have:
- A Klutch.sh account
- A GitHub repository for your Bugsink deployment
- Basic knowledge of Docker, error tracking systems, and environment variables
- (Optional, recommended for production) A managed PostgreSQL database or Klutch.sh PostgreSQL instance
Project Structure
A minimal repository layout for deploying Bugsink on Klutch.sh:
bugsink-deploy/├── Dockerfile├── bugsink_conf.py (optional custom configuration)├── .dockerignore└── README.mdFor quick testing, you can use the official Bugsink Docker image. For production deployments with custom configurations, you may want to extend the base image.
Step 1: Prepare Your Bugsink Repository
-
Create a new GitHub repository or fork an existing one for your Bugsink deployment. If you’re creating a new repository, initialize it with a README.
-
Clone your repository locally:
Terminal window git clone https://github.com/yourusername/bugsink-deploy.gitcd bugsink-deploy -
Ensure sensitive data like database credentials and secret keys are never committed to the repository. These will be configured as environment variables in Klutch.sh.
For more information on connecting your GitHub repository, see the Klutch.sh Quick Start Guide.
Step 2: Create the Dockerfile
Bugsink provides an official Docker image that can be used directly. Create a Dockerfile in your repository root:
Option A: Using the Official Image (Recommended for Quick Start)
FROM bugsink/bugsink:latest
# The official image already includes all necessary dependencies# Default port is 8000EXPOSE 8000Option B: Custom Build with PostgreSQL Support
For production deployments with PostgreSQL and custom configurations:
ARG PYTHON_VERSION=3.12
# Build image for creating wheelsFROM python:${PYTHON_VERSION} AS build
# Build mysqlclient wheel (useful if you might switch to MySQL later)RUN --mount=type=cache,target=/var/cache/buildkit/pip \ pip wheel --wheel-dir /wheels mysqlclient
# Production imageFROM python:${PYTHON_VERSION}-slim
ENV PYTHONUNBUFFERED=1ENV PORT=8000
WORKDIR /app
# Install MySQL client libraries (even if using PostgreSQL)RUN apt-get update && \ apt-get install -y default-libmysqlclient-dev git && \ rm -rf /var/lib/apt/lists/*
# Copy and install wheelsCOPY --from=build /wheels /wheelsRUN --mount=type=cache,target=/var/cache/buildkit/pip \ pip install --find-links /wheels --no-index mysqlclient
# Install PostgreSQL adapterRUN --mount=type=cache,target=/var/cache/buildkit/pip \ pip install "psycopg[binary]"
# Install BugsinkRUN --mount=type=cache,target=/var/cache/buildkit/pip \ pip install bugsink
# Create bugsink user and data directoryRUN groupadd --gid 14237 bugsink && \ useradd --uid 14237 --gid 14237 bugsink && \ mkdir -p /data && \ chown -R bugsink:bugsink /data
USER bugsink
# Health checkHEALTHCHECK CMD python -c 'import requests; requests.get("http://localhost:8000/health/ready").raise_for_status()'
# Start Bugsink with gunicornCMD ["sh", "-c", "bugsink-manage migrate && bugsink-manage migrate snappea --database=snappea && gunicorn --bind=0.0.0.0:$PORT --access-logfile - bugsink.wsgi"]
EXPOSE 8000Create a .dockerignore File
Create a .dockerignore file to exclude unnecessary files from the Docker build:
.git.github*.md.gitignore.env.env.**.pyc__pycache__.pytest_cache*.logStep 3: Set Up Persistent Storage
Bugsink requires persistent storage for its database (if using SQLite) and media files. Even when using an external PostgreSQL database, you’ll need storage for uploaded files and static assets.
-
In the Klutch.sh dashboard, navigate to your project.
-
Create a new volume for Bugsink data storage. Recommended size: Start with 10GB and scale up based on usage.
-
When configuring your app deployment, attach the volume with the following mount path:
/dataThis path will store:
- SQLite database file (if not using PostgreSQL)
- Uploaded media files
- Static assets
- Cache files
For more details on managing volumes, see the Klutch.sh Volumes Guide.
Step 4: Configure Environment Variables
Bugsink requires several environment variables for proper operation. Configure these in the Klutch.sh dashboard under your app’s environment settings.
Required Environment Variables
-
SECRET_KEY (Required)
Django secret key for cryptographic signing. Generate a secure random string of at least 50 characters:
Terminal window python -c "import secrets; print(secrets.token_urlsafe(50))"Set in Klutch.sh as a secret environment variable.
-
PORT (Auto-configured)
Bugsink listens on port
8000by default. Configure your app in Klutch.sh to route HTTP traffic to port8000. -
CREATE_SUPERUSER (Optional, for first-time setup)
Format:
username:passwordExample:
admin:yourStrongPassword123This creates the initial admin user on first startup. Remove this variable after the first deployment for security.
Database Configuration (PostgreSQL - Recommended for Production)
For production deployments, use PostgreSQL instead of SQLite:
-
DATABASE_URL (Recommended)
The easiest way to configure PostgreSQL:
postgresql://username:password@hostname:5432/database_nameExample:
postgresql://bugsink:secure_password@postgres.example.com:5432/bugsink_db -
Alternative: Individual database environment variables:
DB_ENGINE=django.db.backends.postgresqlDB_NAME=bugsink_dbDB_USER=bugsinkDB_PASSWORD=your_secure_passwordDB_HOST=postgres.example.comDB_PORT=5432
Optional Environment Variables
- ALLOWED_HOSTS: Comma-separated list of allowed hostnames (e.g.,
example-app.klutch.sh,bugsink.example.com) - DEBUG: Set to
falsefor production (default isfalse) - CSRF_TRUSTED_ORIGINS: Comma-separated list of trusted origins for CSRF protection
- EMAIL_HOST: SMTP host for sending email notifications
- EMAIL_PORT: SMTP port (default: 587)
- EMAIL_HOST_USER: SMTP username
- EMAIL_HOST_PASSWORD: SMTP password
- EMAIL_USE_TLS: Set to
trueto use TLS (recommended)
Example Environment Configuration
For a production deployment with PostgreSQL:
SECRET_KEY=your-super-secret-key-of-at-least-50-characters-hereDATABASE_URL=postgresql://bugsink:secure_password@postgres-host:5432/bugsinkALLOWED_HOSTS=example-app.klutch.sh,bugsink.yourdomain.comDEBUG=falseCSRF_TRUSTED_ORIGINS=https://example-app.klutch.sh,https://bugsink.yourdomain.comEMAIL_HOST=smtp.sendgrid.netEMAIL_PORT=587EMAIL_HOST_USER=apikeyEMAIL_HOST_PASSWORD=your_sendgrid_api_keyEMAIL_USE_TLS=true⚠️ Important: Always mark sensitive variables (SECRET_KEY, passwords, API keys) as secret in the Klutch.sh dashboard to prevent them from being exposed in logs.
Step 5: Deploy to Klutch.sh
-
Push your Dockerfile and any configuration files to your GitHub repository:
Terminal window git add Dockerfile .dockerignoregit commit -m "Add Bugsink Dockerfile configuration"git push origin main -
Log in to the Klutch.sh dashboard.
-
Create a new app and connect your GitHub repository containing the Bugsink Dockerfile. Klutch.sh will automatically detect the Dockerfile in your repository root.
-
Configure the deployment settings:
- Traffic Type: Select HTTP
- Internal Port: Set to
8000(Bugsink’s default port) - Build Context: Leave as root (
.) unless your Dockerfile is in a subdirectory
-
Add all required environment variables as configured in Step 4. Make sure to mark sensitive values as secrets.
-
Attach the persistent volume you created in Step 3 to mount path
/data. -
(Optional) If you need to customize the build or start commands, you can set Nixpacks environment variables:
NIXPACKS_BUILD_CMD: Custom build command (if needed)NIXPACKS_START_CMD: Custom start command (if needed)
For Dockerfile deployments, these are typically not necessary as the Dockerfile defines the build and start process.
-
Click “Deploy” to start the build and deployment process. Klutch.sh will:
- Build your Docker image
- Push it to the registry
- Deploy the container
- Set up HTTPS routing automatically
-
Monitor the build logs in the Klutch.sh dashboard. The initial deployment may take a few minutes.
Once deployment is complete, your Bugsink instance will be available at https://example-app.klutch.sh (replace with your actual app URL).
Step 6: Initial Setup and Configuration
-
Visit your Bugsink app URL (e.g.,
https://example-app.klutch.sh). -
If you set the
CREATE_SUPERUSERenvironment variable, log in with those credentials. Otherwise, you’ll need to create a superuser through the Django admin interface. -
After logging in, navigate to the admin interface to:
- Create your first project
- Configure error tracking settings
- Set up notification preferences
- Generate DSN (Data Source Name) for connecting your applications
-
Follow the Bugsink quickstart guide to configure your applications to send errors to your Bugsink instance.
-
Remove the
CREATE_SUPERUSERenvironment variable from your Klutch.sh app settings after the initial setup for security.
Step 7: Set Up PostgreSQL Database (Production)
For production deployments, using PostgreSQL instead of SQLite is highly recommended for better performance, reliability, and concurrent access.
-
Provision a PostgreSQL database. You have several options:
- Use a managed PostgreSQL service (recommended)
- Deploy PostgreSQL on Klutch.sh as a separate app
- Use an external PostgreSQL provider
-
Create a dedicated database and user for Bugsink:
CREATE DATABASE bugsink_db;CREATE USER bugsink WITH PASSWORD 'your_secure_password';GRANT ALL PRIVILEGES ON DATABASE bugsink_db TO bugsink;ALTER DATABASE bugsink_db OWNER TO bugsink; -
If your PostgreSQL database requires TCP traffic (common for database deployments on Klutch.sh), ensure your database app is configured for TCP traffic on port 8000. You’ll connect to it using the internal port 5432 within the application.
-
Update your Bugsink app’s environment variables with the PostgreSQL connection details (as shown in Step 4).
-
Redeploy your Bugsink app to apply the database configuration. Bugsink will automatically run migrations on startup.
Step 8: Production Best Practices
Security Hardening
-
Strong SECRET_KEY: Use a cryptographically secure random key of at least 50 characters. Never commit it to version control.
-
Database Credentials: Use strong, unique passwords for database users. Store all credentials as secret environment variables in Klutch.sh.
-
HTTPS Only: Ensure
CSRF_TRUSTED_ORIGINSincludes only HTTPS URLs. Klutch.sh provides automatic HTTPS for all apps. -
Disable DEBUG: Always set
DEBUG=falsein production to prevent information disclosure. -
Regular Updates: Keep Bugsink updated by pulling the latest Docker image or updating the version tag in your Dockerfile.
-
Access Control: Use strong passwords for admin accounts and consider implementing two-factor authentication if supported.
Performance Optimization
- Database Indexing: Ensure proper database indexes are in place for frequently queried fields
- Connection Pooling: PostgreSQL connection pooling can improve performance under load
- Cache Configuration: Configure Django’s cache backend (Redis recommended) for better performance
- Media Storage: For high-traffic instances, consider using object storage (S3-compatible) for media files
Backup Strategy
-
Database Backups: Set up automated PostgreSQL backups using your database provider’s backup solution or pg_dump:
Terminal window pg_dump -h postgres-host -U bugsink bugsink_db > bugsink-backup-$(date +%Y%m%d).sql -
Volume Backups: Regularly back up the
/datavolume containing uploaded files and configuration. -
Backup Testing: Periodically test your backups by restoring to a test environment.
Monitoring and Maintenance
- Resource Monitoring: Monitor CPU, memory, and disk usage through the Klutch.sh dashboard
- Log Monitoring: Regularly review application logs for errors and warnings
- Health Checks: Bugsink includes a
/health/readyendpoint for health checking - Database Maintenance: Perform regular PostgreSQL maintenance (VACUUM, ANALYZE)
- Error Retention: Configure retention policies to prevent unlimited error data growth
Step 9: Troubleshooting
Common Issues and Solutions
Application Won’t Start
-
Check the deployment logs in the Klutch.sh dashboard for error messages
-
Verify all required environment variables are set correctly
-
Ensure
SECRET_KEYis at least 50 characters long -
Check that the internal port is set to
8000
Database Connection Errors
-
Verify PostgreSQL credentials are correct
-
Ensure the PostgreSQL host is accessible from your Bugsink app
-
Check that the database exists and the user has proper permissions
-
For Klutch.sh PostgreSQL deployments, ensure TCP traffic is properly configured
502 Bad Gateway or 503 Service Unavailable
-
Check that your app is listening on
0.0.0.0:8000(not justlocalhost) -
Review application logs for startup errors
-
Ensure the health check endpoint is responding
-
Verify environment variables are not causing startup failures
Permission Errors with Persistent Storage
-
Ensure the container user has write permissions to
/data -
Check that the volume is properly mounted
-
Review file ownership within the container (should be owned by the
bugsinkuser)
CSRF Verification Failed
-
Ensure
CSRF_TRUSTED_ORIGINSincludes your app’s domain withhttps://prefix -
Verify
ALLOWED_HOSTSincludes your domain -
Check that cookies are not being blocked by browser settings
Debug Commands
To inspect your deployment:
# View application logs# (Use the Klutch.sh dashboard logs viewer)
# Check database connectivity (from a debug container)psql -h postgres-host -U bugsink -d bugsink_db -c "SELECT version();"
# Verify Django settings (add to Dockerfile temporarily)python manage.py check --deployStep 10: Connecting Applications to Bugsink
After deploying Bugsink, connect your applications to start tracking errors:
-
Log in to your Bugsink dashboard and create a new project.
-
Copy the DSN (Data Source Name) provided for your project.
-
Install the Sentry SDK in your application (Bugsink is Sentry-compatible):
Python:
Terminal window pip install sentry-sdkJavaScript/Node.js:
Terminal window npm install @sentry/nodeOther languages: See Sentry SDK documentation for your language.
-
Configure the SDK with your Bugsink DSN:
Python:
import sentry_sdksentry_sdk.init(dsn="https://your-dsn@example-app.klutch.sh/project-id",traces_sample_rate=1.0,)JavaScript/Node.js:
const Sentry = require("@sentry/node");Sentry.init({dsn: "https://your-dsn@example-app.klutch.sh/project-id",tracesSampleRate: 1.0,}); -
Test the integration by triggering a test error in your application. It should appear in your Bugsink dashboard within seconds.
Scaling Your Bugsink Deployment
As your error tracking needs grow, consider these scaling strategies:
- Vertical Scaling: Increase CPU and memory resources in the Klutch.sh dashboard
- Database Optimization: Upgrade to a larger PostgreSQL instance with more resources
- Storage Expansion: Increase the size of your persistent volume as error data grows
- Load Balancing: Deploy multiple Bugsink instances behind a load balancer for high availability
- Cache Layer: Add Redis for improved performance with session and cache storage
- Media Storage: Migrate to object storage (S3-compatible) for scalable media file storage
Resources
- Bugsink Official Website
- Bugsink Documentation
- Bugsink GitHub Repository
- Bugsink Docker Hub
- Klutch.sh Quick Start Guide
- Klutch.sh Volumes Guide
- Klutch.sh Deployments Guide
- Klutch.sh Networking Guide
Deploying Bugsink on Klutch.sh provides you with a powerful, self-hosted error tracking solution that gives you complete control over your data while leveraging Klutch.sh’s managed infrastructure, automatic HTTPS, and seamless scaling capabilities. With proper configuration and following these best practices, you’ll have a production-ready error tracking system that can grow with your needs.