Deploy with Docker
Docker is the recommended deployment method for OpenCodeHub. This guide covers everything from basic setup to production-ready configurations.
Prerequisites
Section titled “Prerequisites”- Docker Engine 24.0+
- Docker Compose v2.20+
- 2GB RAM minimum (4GB recommended)
- 20GB disk space
# Verify installationdocker --versiondocker compose versionQuick Start (Development)
Section titled “Quick Start (Development)”For testing or development, use the minimal configuration:
# Clone the repositorygit clone https://github.com/swadhinbiswas/OpencodeHub.gitcd OpenCodeHub
# Copy environment filecp .env.example .env
# Start with Docker Composedocker compose up -d
# View logsdocker compose logs -fAccess at http://localhost:3000
Production Setup
Section titled “Production Setup”1. Create Directory Structure
Section titled “1. Create Directory Structure”mkdir -p /opt/opencodehub/{data,postgres,redis}cd /opt/opencodehub2. Create docker-compose.yml
Section titled “2. Create docker-compose.yml”version: '3.8'
services: app: image: ghcr.io/swadhinbiswas/opencodehub:latest # Or build from source: # build: . restart: unless-stopped ports: - "3000:3000" environment: - NODE_ENV=production env_file: - .env volumes: - ./data:/app/data depends_on: postgres: condition: service_healthy redis: condition: service_started healthcheck: test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"] interval: 30s timeout: 10s retries: 3 start_period: 40s
postgres: image: postgres:16-alpine restart: unless-stopped environment: POSTGRES_DB: opencodehub POSTGRES_USER: opencodehub POSTGRES_PASSWORD: ${DATABASE_PASSWORD} volumes: - ./postgres:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U opencodehub"] interval: 10s timeout: 5s retries: 5
redis: image: redis:7-alpine restart: unless-stopped command: redis-server --requirepass ${REDIS_PASSWORD} volumes: - redis_data:/data
volumes: redis_data:3. Create Production .env
Section titled “3. Create Production .env”# Generate secure secretsJWT_SECRET=$(openssl rand -hex 32)SESSION_SECRET=$(openssl rand -hex 32)INTERNAL_HOOK_SECRET=$(openssl rand -hex 32)DATABASE_PASSWORD=$(openssl rand -hex 16)REDIS_PASSWORD=$(openssl rand -hex 16)
cat > .env << EOF# ApplicationNODE_ENV=productionPORT=3000SITE_URL=https://git.yourcompany.com
# Security (NEVER commit these!)JWT_SECRET=${JWT_SECRET}SESSION_SECRET=${SESSION_SECRET}INTERNAL_HOOK_SECRET=${INTERNAL_HOOK_SECRET}
# DatabaseDATABASE_DRIVER=postgresDATABASE_URL=postgresql://opencodehub:${DATABASE_PASSWORD}@postgres:5432/opencodehubDATABASE_PASSWORD=${DATABASE_PASSWORD}
# RedisREDIS_URL=redis://:${REDIS_PASSWORD}@redis:6379REDIS_PASSWORD=${REDIS_PASSWORD}
# Storage (use local for best performance)STORAGE_TYPE=localSTORAGE_PATH=/app/data/reposEOF4. Start Services
Section titled “4. Start Services”docker compose up -d
# Verify all services are healthydocker compose ps
# Initialize databasedocker compose exec app bun run db:push
# Create admin userdocker compose exec app bun run scripts/seed-admin.tsUsing with Nginx (Recommended)
Section titled “Using with Nginx (Recommended)”See the Nginx Deployment Guide for reverse proxy configuration.
Quick Nginx Setup
Section titled “Quick Nginx Setup”server { listen 80; server_name git.yourcompany.com; return 301 https://$host$request_uri;}
server { listen 443 ssl http2; server_name git.yourcompany.com;
ssl_certificate /etc/letsencrypt/live/git.yourcompany.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/git.yourcompany.com/privkey.pem;
client_max_body_size 500M;
location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket support proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }}Docker Swarm Deployment
Section titled “Docker Swarm Deployment”For high availability:
version: '3.8'
services: app: image: ghcr.io/swadhinbiswas/opencodehub:latest deploy: replicas: 3 update_config: parallelism: 1 delay: 10s restart_policy: condition: on-failure # ... rest of configdocker stack deploy -c docker-compose.yml opencodehubBackup & Restore
Section titled “Backup & Restore”Backup
Section titled “Backup”#!/bin/bashDATE=$(date +%Y%m%d)BACKUP_DIR=/backups/opencodehub
mkdir -p $BACKUP_DIR
# Backup PostgreSQLdocker compose exec -T postgres pg_dump -U opencodehub opencodehub | gzip > $BACKUP_DIR/db_$DATE.sql.gz
# Backup repositoriestar -czf $BACKUP_DIR/repos_$DATE.tar.gz -C /opt/opencodehub/data .
# Keep last 7 daysfind $BACKUP_DIR -name "*.gz" -mtime +7 -deleteRestore
Section titled “Restore”# Restore databasegunzip -c db_backup.sql.gz | docker compose exec -T postgres psql -U opencodehub opencodehub
# Restore repositoriestar -xzf repos_backup.tar.gz -C /opt/opencodehub/dataTroubleshooting
Section titled “Troubleshooting”Container won’t start
Section titled “Container won’t start”# Check logsdocker compose logs app
# Common issues:# 1. Database not ready - increase healthcheck start_period# 2. Port in use - change ports mapping# 3. Missing env vars - check .env fileDatabase connection issues
Section titled “Database connection issues”# Verify PostgreSQL is accessibledocker compose exec app nc -zv postgres 5432
# Check database existsdocker compose exec postgres psql -U opencodehub -lOut of disk space
Section titled “Out of disk space”# Clean Docker resourcesdocker system prune -a --volumes
# Check disk usagedocker system df