Deploying a Gitness App
Introduction
Gitness is a powerful open-source development platform that provides integrated source control (Git), CI/CD pipelines, and container registry capabilities all in one unified solution. Built by Harness, Gitness offers developers a self-hosted alternative to platforms like GitLab and GitHub, with a focus on simplicity and performance. This comprehensive guide demonstrates how to deploy Gitness on Klutch.sh using a Dockerfile, covering everything from initial setup to production configuration with persistent storage, environment variables, and security best practices.
Whether you’re setting up a private code repository for your team, building automated CI/CD pipelines, or managing container images, Gitness provides the tools you need. Deploying on Klutch.sh gives you a managed infrastructure with automatic scaling, secure HTTPS endpoints, and persistent volume support to ensure your code and configuration are never lost.
Prerequisites
- A Klutch.sh account
- A GitHub repository for your Gitness deployment configuration
- Basic familiarity with Docker, Git, and environment variables
- (Optional) PostgreSQL database for production deployments (SQLite works for testing)
- Understanding of persistent storage for code repositories and build artifacts
Project Structure
A minimal repository layout for deploying Gitness on Klutch.sh:
gitness-deploy/├─ Dockerfile├─ docker-entrypoint.sh├─ .gitignore└─ README.mdThis structure keeps your deployment configuration version-controlled and reproducible.
1) Dockerfile for Gitness
Gitness provides an official Docker image that we’ll use as the base. Here’s a production-ready Dockerfile:
FROM harness/gitness:latest
# Set working directoryWORKDIR /data
# Expose Gitness HTTP portEXPOSE 3000
# Create data directory for persistenceRUN mkdir -p /data
# Default command will start Gitness serverCMD ["gitness", "server"]For a more customized setup with specific version pinning:
FROM harness/gitness:3.0.0
# Install additional tools if neededUSER rootRUN apk add --no-cache \ git \ openssh-client \ ca-certificates
# Set up directory structureRUN mkdir -p /data/repos /data/config /data/logs
# Switch back to gitness user for securityUSER gitness
WORKDIR /data
EXPOSE 3000
# Health check to ensure service is runningHEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3000/healthz || exit 1
CMD ["gitness", "server"]2) Environment Variables
Configure these environment variables in your Klutch.sh dashboard under the app settings:
Basic Configuration
# Server configurationGITNESS_HTTP_PORT=3000GITNESS_URL_BASE=https://example-app.klutch.sh
# Database configuration (SQLite for testing)GITNESS_DATABASE_DRIVER=sqliteGITNESS_DATABASE_DATASOURCE=/data/gitness.db
# SecurityGITNESS_TOKEN_SECRET=your-random-secret-key-hereGITNESS_ADMIN_PASSWORD=strong-admin-passwordProduction Configuration with PostgreSQL
For production deployments, use PostgreSQL instead of SQLite:
# Server configurationGITNESS_HTTP_PORT=3000GITNESS_URL_BASE=https://git.yourdomain.com
# PostgreSQL databaseGITNESS_DATABASE_DRIVER=postgresGITNESS_DATABASE_DATASOURCE=postgres://user:password@postgres-host:5432/gitness?sslmode=disable
# Security and secretsGITNESS_TOKEN_SECRET=generate-a-secure-random-stringGITNESS_ADMIN_PASSWORD=secure-admin-password-hereGITNESS_ADMIN_EMAIL=admin@yourdomain.com
# Git configurationGITNESS_GIT_HOOK_PATH=/data/hooksGITNESS_GIT_ROOT=/data/repos
# LoggingGITNESS_LOG_LEVEL=infoImportant Security Notes:
- Always use strong, randomly generated values for
GITNESS_TOKEN_SECRET - Store sensitive values as secrets in Klutch.sh dashboard
- Never commit passwords or tokens to your Git repository
- Rotate secrets regularly in production environments
3) Persistent Storage Configuration
Gitness requires persistent storage for Git repositories, database files, and configuration. Configure volumes in your Klutch.sh dashboard:
Volume Mount Paths
- Size: Minimum 10GB, recommend 50GB+ for production
- This stores: Git repositories, SQLite database (if used), logs, and configuration
- Size: Based on expected repository sizes, recommend 100GB+ for active development
- Stores all Git repository data
- Size: 20GB+ depending on CI/CD usage
- Stores pipeline artifacts and cache
Primary Data Volume: Mount a persistent volume to /data
Repository Storage: If using separate volume for repositories: /data/repos
Build Artifacts (optional): /data/artifacts
Setting Up Volumes on Klutch.sh
- Mount Path:
/data - Size:
50GB(adjust based on needs)
Navigate to your app in the Klutch.sh dashboard
In the app settings, locate the “Volumes” section
Click “Add Volume” and configure:
Save the volume configuration
Volume Best Practices:
- Start with at least 10GB and monitor usage
- Set up monitoring alerts for disk usage
- Plan for growth — repository data increases over time
- Regular backups of the
/datavolume are essential
4) Deploying to Klutch.sh
Follow these steps to deploy Gitness on Klutch.sh:
- Log in to the Klutch.sh dashboard
- Click “Create New App”
- Select your GitHub repository containing the Dockerfile
- Choose the branch (typically
mainormaster) - Klutch.sh will automatically detect your Dockerfile
- No additional build configuration needed
- In the networking section, specify the internal port:
3000 - Select traffic type: HTTP (Gitness serves web traffic)
- Navigate to the “Environment Variables” section
- Add the variables from section 2 above
- Mark sensitive variables (passwords, secrets) as “Secret”
- In the “Volumes” section, add a new volume
- Mount path:
/data - Size:
50GB(minimum) - Review all settings
- Click “Deploy”
- Klutch.sh will build the Docker image and start your container
- Once deployed, access via the provided URL:
https://example-app.klutch.sh - Complete the initial setup wizard
- Create your admin account using the credentials from environment variables
Prepare Your Repository
# Create a new repositorymkdir gitness-deploycd gitness-deploy
# Create Dockerfilecat > Dockerfile << 'EOF'FROM harness/gitness:latestWORKDIR /dataRUN mkdir -p /dataEXPOSE 3000CMD ["gitness", "server"]EOF
# Initialize git and push to GitHubgit initgit add Dockerfilegit commit -m "Add Gitness Dockerfile"git remote add origin https://github.com/yourusername/gitness-deploy.gitgit push -u origin mainCreate App in Klutch.sh
Configure Build Settings
Set Container Port
Add Environment Variables
Attach Persistent Volume
Deploy the Application
Access Your Gitness Instance
5) Initial Setup and Configuration
After deployment, complete the Gitness setup:
- Navigate to your app URL:
https://example-app.klutch.sh - You should see the Gitness login page
- Log in with the admin credentials set in environment variables
- If this is first run, you may need to complete the setup wizard
- Go to Settings → Git Configuration
- Set your Git username and email
- Configure SSH keys if using SSH for Git operations
- Click “New Repository”
- Enter repository name and description
- Choose visibility (public or private)
- Initialize with README if desired
Access the Web Interface
Initial Admin Setup
Configure Git Settings
Create Your First Repository
Test Repository Access
# Clone your new repositorygit clone https://example-app.klutch.sh/username/repository.git
# Add some filescd repositoryecho "# My Project" > README.mdgit add README.mdgit commit -m "Initial commit"git push origin main6) Sample Code and Getting Started
Creating Your First Pipeline
Gitness includes built-in CI/CD capabilities. Here’s a sample pipeline configuration (.gitness.yml):
version: 1
pipelines: - name: build-and-test stages: - name: build steps: - name: build-app type: run spec: container: node:18-alpine script: | npm install npm run build
- name: test steps: - name: run-tests type: run spec: container: node:18-alpine script: | npm test
- name: deploy when: branch: - main steps: - name: deploy-to-prod type: run spec: container: alpine:latest script: | echo "Deploying to production..." # Add your deployment commands hereSample Webhook Configuration
Configure webhooks to trigger external services:
# Using curl to create a webhookcurl -X POST https://example-app.klutch.sh/api/v1/repos/{owner}/{repo}/webhooks \ -H "Authorization: Bearer YOUR_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "name": "my-webhook", "url": "https://your-service.com/webhook", "events": ["push", "pull_request"], "active": true }'Using Gitness API
Gitness provides a RESTful API for automation:
// Example: Fetch repositories using Node.jsconst axios = require('axios');
const gitnessUrl = 'https://example-app.klutch.sh';const token = 'your-api-token';
async function listRepositories() { try { const response = await axios.get(`${gitnessUrl}/api/v1/repos`, { headers: { 'Authorization': `Bearer ${token}` } }); console.log('Repositories:', response.data); } catch (error) { console.error('Error fetching repositories:', error.message); }}
listRepositories();Git Command Examples
# Clone a repositorygit clone https://example-app.klutch.sh/username/my-project.git
# Add Gitness as a remote to existing projectgit remote add gitness https://example-app.klutch.sh/username/my-project.gitgit push gitness main
# Configure git credentials for Gitnessgit config --global credential.helper storegit config --global user.name "Your Name"git config --global user.email "your.email@example.com"7) Custom Domain Configuration
To use your own domain with Gitness:
- Navigate to your app settings
- Go to “Domains” section
- Click “Add Custom Domain”
- Enter your domain:
git.yourdomain.com - Add a CNAME record in your DNS provider:
git.yourdomain.com → example-app.klutch.sh
- Or use an A record if provided by Klutch.sh
- Update the
GITNESS_URL_BASEenvironment variable:Terminal window GITNESS_URL_BASE=https://git.yourdomain.com - Redeploy the app for changes to take effect
- Klutch.sh automatically provisions SSL certificates
- Access your custom domain to verify HTTPS works
Add Custom Domain in Klutch.sh
Configure DNS
Update Gitness Configuration
Verify SSL Certificate
8) Database Setup and Migration
Using PostgreSQL for Production
For production environments, PostgreSQL is recommended over SQLite:
- Deploy a PostgreSQL instance on Klutch.sh or use external provider
- Note the connection details: host, port, username, password, database name
- Gitness automatically handles schema migrations on startup
- First run will initialize the database schema
- Subsequent runs will migrate as needed
- Set up regular PostgreSQL backups
- Use
pg_dumpfor manual backups:Terminal window pg_dump -h postgres-host -U username -d gitness > gitness-backup.sql
Provision PostgreSQL Database
Update Environment Variables
GITNESS_DATABASE_DRIVER=postgresGITNESS_DATABASE_DATASOURCE=postgres://username:password@host:5432/gitness?sslmode=requireDatabase Migration
Backup Configuration
Migrating from SQLite to PostgreSQL
If you started with SQLite and want to migrate:
# Export from SQLite (if tools are available)sqlite3 /data/gitness.db .dump > gitness-export.sql
# Import to PostgreSQLpsql -h postgres-host -U username -d gitness < gitness-export.sqlNote: Migration may require data transformation. Test thoroughly before production migration.
9) Networking and Port Configuration
Gitness uses HTTP traffic on port 3000 by default:
Internal Port Configuration
When configuring your app in Klutch.sh:
- Internal Port:
3000(the port Gitness listens on inside the container) - Traffic Type: Select “HTTP” in the Klutch.sh dashboard
SSH Git Access (Optional)
For SSH-based Git operations:
- For SSH access, you’ll need TCP traffic
- In the Klutch.sh dashboard, navigate to your app’s networking settings
- Select traffic type: “TCP”
- External port: Users connect to port 8000
- Internal port: Set to
2222(where Gitness SSH listens in the container) - This creates a mapping where external connections to port 8000 are routed to the container’s internal port 2222
Configure SSH Port in Gitness
GITNESS_SSH_PORT=2222Update Dockerfile to Expose SSH Port
FROM harness/gitness:latestWORKDIR /dataEXPOSE 3000 2222CMD ["gitness", "server"]Configure TCP Traffic in Klutch.sh
Client Configuration
# Configure SSH to use custom portgit clone ssh://git@example-app.klutch.sh:8000/username/repo.git10) Security Best Practices
Authentication and Access Control
- Use complex passwords for admin account
- Store credentials securely in password manager
- Rotate passwords regularly
- Configure 2FA in user settings
- Require 2FA for admin accounts
- Generate API tokens with minimal required permissions
- Set expiration dates for tokens
- Rotate tokens regularly
- Never commit tokens to repositories
- Create users with appropriate permissions
- Use teams and organizations for access management
- Regularly audit user access
Strong Admin Credentials
Enable Two-Factor Authentication
API Token Management
User Access Control
Network Security
# Use HTTPS onlyGITNESS_URL_BASE=https://git.yourdomain.com
# If using PostgreSQL, enable SSLGITNESS_DATABASE_DATASOURCE=postgres://user:pass@host:5432/gitness?sslmode=requireContainer Security
- Keep the Gitness image updated to latest stable version
- Regularly scan for vulnerabilities
- Use read-only root filesystem where possible
- Run as non-root user (Gitness image handles this)
11) Monitoring and Maintenance
Health Checks
Gitness provides health check endpoints:
# Check service healthcurl https://example-app.klutch.sh/healthz
# Check database connectivitycurl https://example-app.klutch.sh/api/v1/system/healthLogging
Access logs through Klutch.sh dashboard or configure external logging:
# Set log levelGITNESS_LOG_LEVEL=debug # Use 'info' for production
# Log formatGITNESS_LOG_FORMAT=jsonMonitoring Metrics
Key metrics to monitor:
- Disk usage on
/datavolume - Database connection pool status
- API response times
- Git operation latency
- Pipeline execution times
Backup Strategy
- Back up the
/datavolume daily - Retain backups for 30+ days
- Test restore procedures regularly
- For PostgreSQL: automated daily backups
- For SQLite: backup
/data/gitness.dbfile - Consider mirroring critical repositories to external Git service
- Automated backup jobs can push to backup remote
Regular Volume Backups
Database Backups
Repository Mirrors
12) Troubleshooting
Common Issues and Solutions
Issue: Cannot access Gitness web interface
- Ensure
GITNESS_HTTP_PORT=3000 - Check
GITNESS_URL_BASEmatches your domain - Internal port should be
3000 - Traffic type should be HTTP
Check if container is running:
# View logs in Klutch.sh dashboardVerify environment variables are set correctly:
Confirm port configuration:
Issue: Git push fails with authentication error
Verify credentials:
git credential reject# Then try push again with correct credentialsCheck user permissions in Gitness dashboard
Generate new personal access token if needed
Issue: Database connection errors
Verify database credentials in environment variables
Check network connectivity between Gitness and database:
# If both Gitness and PostgreSQL are deployed on Klutch.sh,# they can communicate using internal networking if in the same project# Use the PostgreSQL app's internal hostname (e.g., postgres-app-name.internal)# Refer to Klutch.sh networking documentation for service discoveryReview database logs for connection issues
Verify database exists and user has proper permissions
Issue: Disk space errors
Check volume usage in Klutch.sh dashboard
Increase volume size if needed
Clean up old pipeline artifacts:
# Access container and rundu -sh /data/*# Remove unnecessary filesIssue: Pipeline fails to execute
Check pipeline syntax in .gitness.yml
Review pipeline logs in Gitness UI
Verify container images are accessible
Check environment variables required by pipeline steps
13) Scaling and Performance
Vertical Scaling
For larger teams or repositories:
- Navigate to your app settings
- Go to the “Resources” or “Instance” section
- Select a larger instance type with more CPU and memory
- Recommended for production: 2+ CPU cores, 4GB+ RAM
- Increase volume size as repositories grow
- Monitor disk usage regularly
- Plan capacity based on repository growth rate
Increase instance size in Klutch.sh dashboard:
Adjust storage:
Database Optimization
# For PostgreSQL, enable connection poolingGITNESS_DATABASE_DATASOURCE=postgres://user:pass@host:5432/gitness?sslmode=require&pool_max_conns=20
# Set appropriate cache sizesGITNESS_CACHE_SIZE=1000Performance Tuning
# Adjust Git performance settingsGITNESS_GIT_CACHE_SIZE=512MBGITNESS_GIT_MAX_CONNECTIONS=100
# Pipeline concurrencyGITNESS_PIPELINE_MAX_WORKERS=1014) Integration Examples
Integrate with Slack
# Add webhook in Gitness for Slack notificationscurl -X POST https://example-app.klutch.sh/api/v1/repos/{owner}/{repo}/webhooks \ -H "Authorization: Bearer YOUR_TOKEN" \ -d '{ "url": "https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK", "events": ["push", "pull_request", "pipeline"] }'Integrate with Existing CI/CD
# Trigger external CI/CD on Gitness eventsversion: 1
pipelines: - name: trigger-external-ci stages: - name: notify steps: - name: webhook type: run spec: container: curlimages/curl:latest script: | curl -X POST https://ci.example.com/trigger \ -d '{"repo": "$GITNESS_REPO", "sha": "$GITNESS_COMMIT"}'15) Upgrading Gitness
To upgrade to a new version of Gitness:
- Klutch.sh will automatically rebuild with new image
- Or trigger manual deploy from dashboard
- Check version in Gitness UI
- Test key functionality
- Review logs for any migration issues
- Always backup data before major version upgrades
- Test upgrade in staging environment first
Update Dockerfile
FROM harness/gitness:3.1.0 # Update to new versionWORKDIR /dataEXPOSE 3000CMD ["gitness", "server"]Commit and Push Changes
git add Dockerfilegit commit -m "Upgrade Gitness to v3.1.0"git push origin mainDeploy Update in Klutch.sh
Verify Upgrade
Backup Before Upgrading
16) Advanced Configuration
Custom Git Hooks
# Configure custom Git hooksGITNESS_GIT_HOOK_PATH=/data/hooks
# Create hook scripts in volume# /data/hooks/pre-receive# /data/hooks/post-receiveLDAP Integration
# Configure LDAP authenticationGITNESS_AUTH_LDAP_ENABLED=trueGITNESS_AUTH_LDAP_HOST=ldap.example.comGITNESS_AUTH_LDAP_PORT=389GITNESS_AUTH_LDAP_BASE_DN=dc=example,dc=comGITNESS_AUTH_LDAP_BIND_DN=cn=admin,dc=example,dc=comGITNESS_AUTH_LDAP_BIND_PASSWORD=secretOAuth Integration
# Configure OAuth provider (GitHub, GitLab, etc.)GITNESS_OAUTH_ENABLED=trueGITNESS_OAUTH_PROVIDER=githubGITNESS_OAUTH_CLIENT_ID=your-client-idGITNESS_OAUTH_CLIENT_SECRET=your-client-secretResources
- Gitness Official Documentation
- Gitness GitHub Repository
- Harness Developer Hub
- Klutch.sh Getting Started Guide
- Klutch.sh Volumes Documentation
- Klutch.sh Custom Domains Guide
- Docker Best Practices
Conclusion
Deploying Gitness on Klutch.sh provides a powerful, self-hosted development platform with integrated Git hosting, CI/CD pipelines, and container registry capabilities. With proper configuration of persistent storage, environment variables, and security settings, you can create a production-ready environment for your development team. The combination of Gitness’s comprehensive features and Klutch.sh’s managed infrastructure ensures reliable, scalable, and secure code management and continuous integration workflows.
For additional help, consult the Klutch.sh documentation or reach out to the community forums for support.