Deploying AgencyOS
Introduction
AgencyOS is a powerful open-source business management platform designed to streamline agency operations, client management, project tracking, invoicing, and team collaboration. Built with modern technologies, AgencyOS provides a comprehensive solution for agencies looking to manage their entire workflow from a single, unified interface.
Deploying AgencyOS on Klutch.sh provides you with a scalable, secure, and production-ready infrastructure for your business operations. With automated Dockerfile detection, persistent storage support, and seamless GitHub integration, Klutch.sh makes it simple to deploy and manage your AgencyOS instance. This guide walks you through the complete deployment process, from initial setup to production configuration, ensuring your business management platform is reliable, performant, and ready to scale.
Whether you’re deploying AgencyOS for the first time or migrating an existing instance, this comprehensive guide covers everything you need: Dockerfile configuration, database setup, persistent storage, environment variables, and production best practices.
Prerequisites
Before deploying AgencyOS on Klutch.sh, ensure you have the following:
- A Klutch.sh account
- A GitHub repository for your AgencyOS project (you can fork the official AgencyOS repository or create your own)
- Basic knowledge of Docker and containerization concepts
- Understanding of environment variables and application configuration
- (Recommended) A managed database instance or plan to set one up for production use
Project Structure
A typical AgencyOS deployment repository should contain:
agencyos-docker/├─ Dockerfile├─ docker-entrypoint.sh├─ config/│ └─ production.json├─ .env.example└─ README.mdFor development, you may also include Docker Compose files for local testing, though Klutch.sh does not support Docker Compose for deployment. The compose file would only be used for local development workflows.
1. Prepare Your AgencyOS Repository
Setting Up Your Repository
-
Fork or clone the AgencyOS repository from the official source, or create a new repository for your customized deployment.
-
Create a Dockerfile in the root of your repository (see detailed examples in the next section).
-
Organize configuration files: Keep sensitive configuration and database files out of your Git repository. Use environment variables and persistent volumes to manage these securely.
-
Connect your repository to GitHub: Push your code to GitHub, which is the supported Git source for Klutch.sh.
For detailed information on repository setup and GitHub integration, see the Klutch.sh Quick Start Guide.
2. Creating a Production-Ready Dockerfile
Klutch.sh automatically detects a Dockerfile if present in the root directory of your repository. When a Dockerfile is detected, Klutch.sh will use it to build your container image, eliminating the need to manually specify Docker as a deployment option.
Basic Dockerfile for AgencyOS
Here’s a foundational Dockerfile for deploying AgencyOS:
FROM node:18-alpine
# Set working directoryWORKDIR /app
# Install dependencies for building native modulesRUN apk add --no-cache python3 make g++ git
# Copy package filesCOPY package*.json ./
# Install dependenciesRUN npm ci --production --silent
# Copy application codeCOPY . .
# Create directory for persistent dataRUN mkdir -p /app/data /app/uploads
# Expose the application portEXPOSE 3000
# Start the applicationCMD ["npm", "start"]Production-Optimized Dockerfile
For a more robust production deployment with health checks and optimized caching:
FROM node:18-alpine AS builder
# Install build dependenciesRUN apk add --no-cache python3 make g++ git
WORKDIR /app
# Copy package filesCOPY package*.json ./
# Install all dependencies (including dev dependencies for build)RUN npm ci --silent
# Copy source codeCOPY . .
# Build the application if neededRUN npm run build || echo "No build step required"
# Production stageFROM node:18-alpine
# Install runtime dependenciesRUN apk add --no-cache tini
# Create non-root userRUN addgroup -g 1001 -S agencyos && \ adduser -S agencyos -u 1001
WORKDIR /app
# Copy built application from builderCOPY --from=builder --chown=agencyos:agencyos /app .
# Create persistent data directoriesRUN mkdir -p /app/data /app/uploads /app/logs && \ chown -R agencyos:agencyos /app
# Switch to non-root userUSER agencyos
# Expose application portEXPOSE 3000
# Use tini for proper signal handlingENTRYPOINT ["/sbin/tini", "--"]
# Start the applicationCMD ["node", "server.js"]Dockerfile with Custom Entrypoint Script
For advanced initialization and configuration management:
FROM node:18-alpine
WORKDIR /app
# Install system dependenciesRUN apk add --no-cache \ python3 \ make \ g++ \ git \ curl \ bash
# Copy package files and install dependenciesCOPY package*.json ./RUN npm ci --production --silent
# Copy application codeCOPY . .
# Copy entrypoint scriptCOPY docker-entrypoint.sh /usr/local/bin/RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Create necessary directoriesRUN mkdir -p /app/data /app/uploads /app/logs /app/config
# Expose portEXPOSE 3000
# Set entrypointENTRYPOINT ["docker-entrypoint.sh"]
# Default commandCMD ["npm", "start"]And the corresponding docker-entrypoint.sh script:
#!/bin/bashset -e
# Wait for database to be readyif [ -n "$DB_HOST" ]; then echo "Waiting for database at $DB_HOST:${DB_PORT:-5432}..." while ! nc -z "$DB_HOST" "${DB_PORT:-5432}"; do sleep 1 done echo "Database is ready!"fi
# Run database migrations if neededif [ "$RUN_MIGRATIONS" = "true" ]; then echo "Running database migrations..." npm run migratefi
# Execute the main commandexec "$@"3. Persistent Storage Configuration
AgencyOS requires persistent storage for uploaded files, user data, database files, and application logs. Klutch.sh provides persistent volumes that survive deployments and restarts.
Recommended Volume Mount Points
Configure the following persistent volumes in the Klutch.sh dashboard:
-
Application Data: Mount path
/app/datafor application database files (if using SQLite) and configuration. Recommended size: 5-10 GB -
File Uploads: Mount path
/app/uploadsfor user-uploaded files, documents, and media. Recommended size: 20-50 GB depending on usage -
Logs: Mount path
/app/logsfor application logs and debugging information. Recommended size: 5 GB -
Configuration: Mount path
/app/configfor persistent configuration files. Recommended size: 1 GB
Setting Up Volumes in Klutch.sh
When creating your app in the Klutch.sh dashboard:
- Navigate to the volume configuration section during app creation
- Click “Add Volume” for each mount path you need
- Specify the mount path (e.g.,
/app/data) - Select the appropriate size for your expected usage
- The volumes will be created and mounted automatically during deployment
For more details on volume management, see the Klutch.sh Volumes Guide.
4. Environment Variables Configuration
AgencyOS requires several environment variables for proper operation. Configure these in the Klutch.sh dashboard under your app’s environment variables section.
Essential Environment Variables
# Application ConfigurationNODE_ENV=productionPORT=3000APP_URL=https://example-app.klutch.sh
# Database Configuration (PostgreSQL)DB_TYPE=postgresqlDB_HOST=your-postgres-hostDB_PORT=5432DB_NAME=agencyosDB_USER=agencyos_userDB_PASSWORD=your-secure-passwordDB_SSL=true
# Session ConfigurationSESSION_SECRET=your-random-session-secret-key-min-32-chars
# File Upload ConfigurationUPLOAD_DIR=/app/uploadsMAX_UPLOAD_SIZE=52428800
# Email Configuration (for notifications)SMTP_HOST=smtp.example.comSMTP_PORT=587SMTP_USER=your-smtp-userSMTP_PASSWORD=your-smtp-passwordSMTP_FROM=noreply@yourdomain.com
# SecurityALLOWED_ORIGINS=https://example-app.klutch.sh,https://yourdomain.comJWT_SECRET=your-jwt-secret-key-min-32-charsOptional Environment Variables
# Redis Configuration (for caching and sessions)REDIS_HOST=your-redis-hostREDIS_PORT=6379REDIS_PASSWORD=your-redis-password
# LoggingLOG_LEVEL=infoLOG_DIR=/app/logs
# FeaturesENABLE_NOTIFICATIONS=trueENABLE_WEBHOOKS=trueENABLE_API=trueSetting Environment Variables in Klutch.sh
- In the Klutch.sh dashboard, navigate to your app settings
- Find the “Environment Variables” section
- Add each variable with its corresponding value
- Mark sensitive values (passwords, secrets) as “Secret” to encrypt them
- Save your changes and redeploy if necessary
Security Best Practices:
- Never commit secrets or passwords to your Git repository
- Use strong, randomly generated values for
SESSION_SECRETandJWT_SECRET - Rotate credentials regularly
- Use the secret/encrypted option in Klutch.sh for all sensitive values
5. Deploying to Klutch.sh
Step-by-Step Deployment Process
-
Push your repository to GitHub: Ensure your Dockerfile and all necessary files are committed and pushed to your GitHub repository.
-
Create a new app in Klutch.sh: Log in to the Klutch.sh dashboard and click “Create New App”.
-
Connect your GitHub repository: Select your AgencyOS repository from the list. Klutch.sh will automatically detect the Dockerfile in your root directory.
-
Configure your app:
- App Name: Choose a descriptive name for your AgencyOS instance
- Branch: Select the branch to deploy (typically
mainorproduction) - Region: Choose the region closest to your users for optimal performance
- Internal Port: Set to
3000(or the port your AgencyOS app listens on)
-
Select traffic type: Choose HTTP for AgencyOS web traffic. This allows Klutch.sh to route incoming HTTP/HTTPS requests to your container on the internal port you specified.
-
Configure compute resources: Select the appropriate instance size based on your expected usage:
- Small: 0.5 CPU, 512 MB RAM (development/testing)
- Medium: 1 CPU, 1 GB RAM (small teams)
- Large: 2 CPU, 2 GB RAM (production)
- X-Large: 4 CPU, 4 GB RAM (high traffic)
-
Add persistent volumes: Configure the volumes as described in section 3:
/app/data- Application data/app/uploads- File uploads/app/logs- Application logs
-
Set environment variables: Add all required environment variables from section 4. Use the Klutch.sh secrets feature for sensitive values.
-
Deploy: Click “Create” to start the deployment. Klutch.sh will:
- Clone your repository
- Build the Docker image using your Dockerfile
- Create the container with your configuration
- Mount the persistent volumes
- Start your application
-
Verify deployment: Once deployment completes, access your AgencyOS instance at the provided URL (e.g.,
https://example-app.klutch.sh).
Deployment Notes
- Automatic Dockerfile detection: Klutch.sh automatically detects and uses your Dockerfile when present in the root directory. You don’t need to specify Docker as a deployment method.
- Build time: Initial deployment may take 3-5 minutes depending on your application size and dependencies.
- Zero-downtime deployments: Subsequent deployments use rolling updates to ensure your app remains available.
6. Database Setup
AgencyOS typically requires a relational database (PostgreSQL, MySQL, or SQLite for development). For production deployments, we strongly recommend using PostgreSQL.
Using PostgreSQL (Recommended for Production)
-
Provision a PostgreSQL database: You can either:
- Use a managed PostgreSQL service from a cloud provider
- Deploy PostgreSQL on Klutch.sh as a separate app
- Use a dedicated database hosting service
-
Create the AgencyOS database:
-
Configure connection: Set the database environment variables in your AgencyOS app (see section 4).
-
Run initial migrations: AgencyOS will typically run migrations automatically on first start, or you may need to run them manually:
CREATE DATABASE agencyos;CREATE USER agencyos_user WITH ENCRYPTED PASSWORD 'your-secure-password';GRANT ALL PRIVILEGES ON DATABASE agencyos TO agencyos_user;npm run migrateFor detailed database deployment instructions, see the PostgreSQL deployment guide.
Using SQLite (Development Only)
For development and testing purposes, you can use SQLite:
DB_TYPE=sqliteDB_PATH=/app/data/agencyos.dbEnsure the /app/data volume is mounted for SQLite to persist data.
Note: SQLite is not recommended for production use due to concurrency limitations and performance constraints.
7. Getting Started with AgencyOS
Once your AgencyOS instance is deployed and accessible, follow these steps to get started:
Initial Setup
-
Access your instance: Navigate to your AgencyOS URL (e.g.,
https://example-app.klutch.sh) -
Complete the setup wizard: On first launch, you’ll be prompted to:
- Create an admin account
- Configure basic organization settings
- Set up your workspace preferences
-
Configure your agency: Set up your agency profile, including:
- Agency name and logo
- Contact information
- Timezone and locale settings
-
Add team members: Invite your team members via email and assign appropriate roles and permissions
-
Create your first project: Test the system by creating a sample project and familiarizing yourself with the interface
Sample Configuration
Here’s a sample configuration JSON that you might place in /app/config/production.json:
{ "app": { "name": "Your Agency Name", "url": "https://example-app.klutch.sh", "timezone": "America/New_York" }, "features": { "notifications": true, "webhooks": true, "api": true, "integrations": true }, "uploads": { "maxSize": 52428800, "allowedTypes": ["image/*", "application/pdf", "application/msword"], "storage": "local" }, "email": { "enabled": true, "provider": "smtp" }, "security": { "sessionTimeout": 3600, "passwordPolicy": { "minLength": 8, "requireUppercase": true, "requireNumbers": true, "requireSpecialChars": true } }}8. Customizing Your Dockerfile for Specific Needs
Changing the Start Command
If you need to customize how AgencyOS starts, you can use Nixpacks environment variables since Klutch.sh uses Nixpacks for builds. However, with a Dockerfile, you have direct control.
To change the start command in your Dockerfile:
# Instead ofCMD ["npm", "start"]
# Use a custom commandCMD ["node", "--max-old-space-size=2048", "server.js"]Custom Build Commands
If your application requires custom build steps:
# Run custom build commandRUN npm run build:production
# Or with environment-specific configurationRUN NODE_ENV=production npm run buildAdding System Dependencies
If AgencyOS requires additional system packages:
# For Alpine-based imagesRUN apk add --no-cache \ imagemagick \ ghostscript \ poppler-utils
# For Debian-based imagesRUN apt-get update && apt-get install -y \ imagemagick \ ghostscript \ poppler-utils && \ rm -rf /var/lib/apt/lists/*9. Production Best Practices
Performance Optimization
-
Use multi-stage builds: Reduce final image size by separating build and runtime stages (see production Dockerfile example in section 2)
-
Enable caching: Configure Redis for session storage and application caching:
- Optimize Node.js: Set appropriate memory limits:
- Monitor resource usage: Use the Klutch.sh dashboard to track CPU, memory, and disk usage. Scale resources as needed.
CACHE_DRIVER=redisREDIS_HOST=your-redis-hostREDIS_PORT=6379NODE_OPTIONS=--max-old-space-size=2048Security Hardening
-
Run as non-root user: Always use a non-privileged user in your Dockerfile (see production example)
-
Enable HTTPS: Klutch.sh automatically provides TLS/SSL for your apps
-
Set secure headers: Configure your application to set security headers:
- Regular updates: Keep your base images and dependencies updated:
- Backup regularly: Implement regular backups of your volumes and database
// In your AgencyOS configurationheaders: { 'X-Frame-Options': 'DENY', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'}# Periodically rebuild with updated base imagedocker pull node:18-alpineScaling Considerations
-
Horizontal scaling: Increase the number of instances in the Klutch.sh dashboard for high availability
-
Database optimization:
- Use connection pooling
- Configure appropriate indexes
- Monitor query performance
-
Separate static assets: Consider using a CDN for static files and uploaded content
-
Session management: Use Redis for distributed session storage when running multiple instances
10. Monitoring and Logging
Application Logs
Access your application logs through the Klutch.sh dashboard:
- Navigate to your app in the Klutch.sh dashboard
- Click on “Logs” to view real-time application output
- Filter logs by time range or search for specific events
- Download logs for offline analysis if needed
Health Checks
Implement health check endpoints in your AgencyOS application:
// Example health check endpointapp.get('/health', (req, res) => { const health = { status: 'up', timestamp: Date.now(), uptime: process.uptime(), database: 'connected' // Check actual DB connection }; res.status(200).json(health);});Monitoring Metrics
Monitor key metrics:
- Response times
- Database query performance
- Memory usage
- CPU utilization
- Disk I/O
- Error rates
11. Troubleshooting Common Issues
Application Won’t Start
- Check logs: Review application logs in the Klutch.sh dashboard for error messages
- Verify environment variables: Ensure all required variables are set correctly
- Database connection: Confirm database is accessible and credentials are correct
- Port configuration: Verify the internal port matches what your application listens on
File Upload Issues
- Check volume mounting: Ensure
/app/uploadsvolume is properly mounted - Verify permissions: Make sure the application user has write access to the upload directory
- Check disk space: Ensure the volume has sufficient space available
- Review file size limits: Confirm
MAX_UPLOAD_SIZEis set appropriately
Performance Problems
- Scale resources: Increase CPU and memory allocation in Klutch.sh dashboard
- Check database: Monitor database performance and optimize slow queries
- Enable caching: Implement Redis caching for frequently accessed data
- Review logs: Look for slow requests or errors causing bottlenecks
Database Connection Errors
- Verify credentials: Double-check database host, port, username, and password
- Network access: Ensure the AgencyOS app can reach the database server
- Connection limits: Check if database connection pool is properly configured
- SSL requirements: If using SSL, ensure certificates are properly configured
12. Backup and Disaster Recovery
Database Backups
-
Automated backups: Set up regular database backups using your database provider’s backup features
-
Manual backup (PostgreSQL example):
- Backup schedule: Implement daily backups with retention policy (e.g., keep 30 days)
pg_dump -h $DB_HOST -U $DB_USER -d $DB_NAME > backup-$(date +%Y%m%d).sqlVolume Backups
- Volume snapshots: Use Klutch.sh volume backup features (when available)
- Export important data: Periodically download critical files from your volumes
- Test restore procedures: Regularly test your backup restoration process
Disaster Recovery Plan
- Document configuration: Keep a copy of all environment variables and settings
- Repository backup: Ensure your GitHub repository is backed up
- Recovery procedure: Document steps to restore from backup
- Test recovery: Periodically test your recovery process in a staging environment
13. Migrating from Another Platform
If you’re migrating an existing AgencyOS instance to Klutch.sh:
-
Backup existing data: Create complete backups of your database and file uploads
-
Export environment variables: Document all current environment variables and configuration
-
Deploy on Klutch.sh: Follow the deployment steps in section 5 to create your new instance
-
Migrate database:
- Create database dump from old instance
- Restore to new PostgreSQL instance
- Update connection strings
-
Transfer files: Upload existing files to the persistent volume:
-
Test thoroughly: Verify all functionality before switching over
-
Update DNS: Point your domain to the new Klutch.sh deployment
-
Monitor: Watch logs and performance during the first few days
# Example using rsync or cloud storagersync -avz /old/uploads/ /app/uploads/14. Custom Domain Configuration
To use a custom domain with your AgencyOS deployment:
-
Add domain in Klutch.sh: Navigate to your app settings and add your custom domain
-
Update DNS records: Configure your DNS provider:
- Add an A record pointing to the Klutch.sh provided IP, or
- Add a CNAME record as instructed by the dashboard
-
Update environment variables: Update
APP_URLto reflect your custom domain: -
SSL/TLS: Klutch.sh automatically provisions and manages SSL certificates for your custom domain
-
Verify: Access your AgencyOS instance via the custom domain to confirm everything works
APP_URL=https://agency.yourdomain.comFor more details, see the Klutch.sh Custom Domains guide.
15. Example: Complete Quickstart
Here’s a complete, copy-paste quickstart to get AgencyOS running on Klutch.sh:
1. Create Repository
mkdir agencyos-dockercd agencyos-dockergit init2. Create Dockerfile
FROM node:18-alpine
WORKDIR /app
RUN apk add --no-cache python3 make g++ git
COPY package*.json ./RUN npm ci --production
COPY . .
RUN mkdir -p /app/data /app/uploads /app/logs
EXPOSE 3000
CMD ["npm", "start"]3. Create .env.example
NODE_ENV=productionPORT=3000APP_URL=https://example-app.klutch.shDB_TYPE=postgresqlDB_HOST=your-db-hostDB_PORT=5432DB_NAME=agencyosDB_USER=agencyos_userDB_PASSWORD=change-meSESSION_SECRET=change-me-min-32-charsJWT_SECRET=change-me-min-32-chars4. Commit and Push
git add .git commit -m "Initial AgencyOS Docker setup"git remote add origin https://github.com/yourusername/agencyos-docker.gitgit push -u origin main5. Deploy on Klutch.sh
- Go to Klutch.sh dashboard
- Click “Create New App”
- Connect your GitHub repository
- Set internal port to
3000 - Select HTTP traffic type
- Add volumes:
/app/data,/app/uploads,/app/logs - Add environment variables from
.env.example - Click “Create”
Your AgencyOS instance will be live in 3-5 minutes at https://example-app.klutch.sh!
Resources
- AgencyOS Official Website
- AgencyOS Documentation
- AgencyOS on GitHub
- Klutch.sh Quick Start Guide
- Klutch.sh Volumes Guide
- Klutch.sh Custom Domains
- Klutch.sh Networking Guide