Deploying Gogs
Introduction
Gogs (Go Git Service) is a painless, self-hosted Git service written in Go. It’s designed to be lightweight, easy to install, and simple to use. Gogs provides a GitHub-like web interface for managing Git repositories, making it an excellent choice for individuals, teams, and organizations who want to host their own Git repositories without the complexity of larger solutions.
Gogs stands out for its:
- Lightweight Design: Minimal system requirements with low memory and CPU usage
- Easy Installation: Simple setup process with minimal dependencies
- Cross-Platform: Runs on Windows, macOS, Linux, and ARM
- Fast Performance: Written in Go for optimal speed and efficiency
- GitHub-Like Interface: Familiar web UI for repository management
- Self-Hosted Control: Complete ownership of your code and data
- Active Development: Regular updates and an active community
- Multiple Database Support: Works with SQLite, MySQL, PostgreSQL, and more
This comprehensive guide walks you through deploying Gogs on Klutch.sh using Docker, including detailed installation steps, sample configurations, database setup, persistent storage configuration, and production-ready best practices.
Prerequisites
Before you begin, ensure you have the following:
- A Klutch.sh account
- A GitHub account with a repository for your Gogs project
- Docker installed locally for testing (optional but recommended)
- Basic understanding of Docker, Git, and web applications
Installation and Setup
Step 1: Create Your Project Directory
First, create a new directory for your Gogs deployment project:
mkdir gogs-klutchcd gogs-klutchgit initStep 2: Create the Dockerfile (SQLite - Development)
Create a Dockerfile in your project root directory for a quick development setup using SQLite:
FROM gogs/gogs:latest
# Set working directoryWORKDIR /data
# Expose the default Gogs HTTP portEXPOSE 3000
# Expose the SSH port for Git operationsEXPOSE 22
# The official Gogs image includes an entrypoint# Data will be stored in /data (mount as volume)Note: This minimal Dockerfile uses the official Gogs image with SQLite for quick testing. For production deployments, see the PostgreSQL or MySQL configuration below.
Step 3: Production Dockerfile with Database Support
For a production-ready setup, create a Dockerfile that’s optimized for external database connections:
FROM gogs/gogs:0.13.0
# Set environment for productionENV USER=gitENV GOGS_CUSTOM=/data/gogs
# Create necessary directoriesRUN mkdir -p /data/git /data/gogs/conf /data/gogs/log
# Expose HTTP portEXPOSE 3000
# Expose SSH port for Git operationsEXPOSE 22
# Volume for persistent dataVOLUME ["/data"]
# The official Gogs image includes the correct entrypoint# No need to override itStep 4: Create Configuration Template
Create an app.ini.example file to document the configuration structure:
[server]PROTOCOL = httpDOMAIN = example-app.klutch.shROOT_URL = https://example-app.klutch.sh/HTTP_PORT = 3000DISABLE_SSH = falseSSH_PORT = 22OFFLINE_MODE = false
[database]DB_TYPE = postgresHOST = postgres-app.klutch.sh:8000NAME = gogsUSER = gogsPASSWD = your-secure-password
[repository]ROOT = /data/git/gogs-repositories
[security]INSTALL_LOCK = falseSECRET_KEY = change-this-to-a-random-string
[service]REGISTER_EMAIL_CONFIRM = falseENABLE_NOTIFY_MAIL = falseDISABLE_REGISTRATION = falseENABLE_CAPTCHA = trueREQUIRE_SIGNIN_VIEW = false
[mailer]ENABLED = false
[log]MODE = fileLEVEL = InfoROOT_PATH = /data/gogs/log
[session]PROVIDER = file
[picture]DISABLE_GRAVATAR = falseENABLE_FEDERATED_AVATAR = falseSecurity Note: Never commit actual passwords or secret keys to your repository. Use environment variables in the Klutch.sh dashboard.
Step 5: Create Environment Configuration
Create a .env.example file to document required environment variables:
# Gogs ConfigurationGOGS_DOMAIN=example-app.klutch.shGOGS_ROOT_URL=https://example-app.klutch.sh/
# Database Configuration (PostgreSQL recommended for production)GOGS_DB_TYPE=postgresGOGS_DB_HOST=postgres-host:5432GOGS_DB_NAME=gogsGOGS_DB_USER=gogsGOGS_DB_PASSWORD=your-secure-password-here
# SecurityGOGS_SECRET_KEY=generate-a-random-secret-key-here
# SSH ConfigurationGOGS_SSH_PORT=22GOGS_DISABLE_SSH=false
# Optional: Email ConfigurationGOGS_MAILER_ENABLED=falseGOGS_MAILER_HOST=smtp.example.com:587GOGS_MAILER_USER=noreply@example.comGOGS_MAILER_PASSWD=your-email-passwordStep 6: Create Startup Script (Optional)
For advanced configuration, create a custom start.sh script:
#!/bin/bashset -e
# Create config directory if it doesn't existmkdir -p /data/gogs/conf
# Generate app.ini from environment variables if it doesn't existif [ ! -f /data/gogs/conf/app.ini ]; then cat > /data/gogs/conf/app.ini <<EOF[server]PROTOCOL = httpDOMAIN = ${GOGS_DOMAIN:-localhost}ROOT_URL = ${GOGS_ROOT_URL:-http://localhost:3000/}HTTP_PORT = 3000SSH_PORT = ${GOGS_SSH_PORT:-22}DISABLE_SSH = ${GOGS_DISABLE_SSH:-false}
[database]DB_TYPE = ${GOGS_DB_TYPE:-sqlite3}HOST = ${GOGS_DB_HOST:-127.0.0.1:5432}NAME = ${GOGS_DB_NAME:-gogs}USER = ${GOGS_DB_USER:-root}PASSWD = ${GOGS_DB_PASSWORD}
[repository]ROOT = /data/git/gogs-repositories
[security]INSTALL_LOCK = falseSECRET_KEY = ${GOGS_SECRET_KEY:-please-change-this}
[service]DISABLE_REGISTRATION = false
[log]MODE = fileLEVEL = InfoROOT_PATH = /data/gogs/logEOFfi
# Start Gogsexec /app/gogs/docker/start.sh /bin/s6-svscan /app/gogs/docker/s6/Note: Make the script executable: chmod +x start.sh
Step 7: Test Locally (Optional)
Before deploying to Klutch.sh, test your Gogs setup locally:
# Build the Docker imagedocker build -t my-gogs .
# Run with SQLite for quick testingdocker run -d \ --name gogs-test \ -p 3000:3000 \ -p 2222:22 \ -v gogs-data:/data \ my-gogs
# View logsdocker logs -f gogs-test
# Access Gogs at http://localhost:3000
# Stop and remove when donedocker stop gogs-testdocker rm gogs-testdocker volume rm gogs-dataStep 8: Create Documentation
Create a README.md file with usage instructions:
# Gogs Git Service Deployment
Self-hosted Git service on Klutch.sh with Docker.
## Features
- Lightweight Git service- Web-based repository management- SSH and HTTP(S) Git access- User and organization support- Issue tracking- Pull requests and code review- Wiki for each repository- Activity timeline
## Initial Setup
After deployment, visit your Gogs URL to complete the installation wizard:
1. Navigate to `https://example-app.klutch.sh`2. Complete the installation form: - Database settings (pre-filled if using environment variables) - Repository root path: `/data/git/gogs-repositories` - Application URL: `https://example-app.klutch.sh` - Create admin account3. Click "Install Gogs"
## Git Operations
### Clone via HTTPSgit clone https://example-app.klutch.sh/username/repository.git
### Clone via SSHgit clone ssh://git@example-app.klutch.sh:22/username/repository.git
## Admin Panel
Access the admin panel at: `https://example-app.klutch.sh/admin`Step 9: Push to GitHub
Commit your Dockerfile and configuration files to your GitHub repository:
git add Dockerfile .env.example app.ini.example README.mdgit commit -m "Add Gogs Dockerfile and configuration"git remote add origin https://github.com/yourusername/gogs-klutch.gitgit push -u origin mainDeploying to Klutch.sh
Now that your Gogs project is ready and pushed to GitHub, follow these steps to deploy it on Klutch.sh with persistent storage and proper configuration.
Deployment Steps
-
Log in to Klutch.sh
Navigate to klutch.sh/app and sign in to your account.
-
Create a New Project
Go to Create Project and give your project a meaningful name (e.g., “Gogs Git Service”).
-
Create a New App
Navigate to Create App and configure the following settings:
-
Select Your Repository
- Choose GitHub as your Git source
- Select the repository containing your Dockerfile
- Choose the branch you want to deploy (usually
mainormaster)
-
Configure Traffic Type
- Traffic Type: Select HTTP (Gogs serves a web interface via HTTP)
- Internal Port: Set to
3000(the default port that Gogs listens on)
Note: For SSH Git operations, Gogs also uses port 22 internally, but HTTP traffic is sufficient for the web interface.
-
Set Environment Variables
Add the following environment variables for your Gogs configuration:
Required Variables:
GOGS_DOMAIN: Your Gogs domain (e.g.,example-app.klutch.sh)GOGS_ROOT_URL: Full URL to your Gogs instance (e.g.,https://example-app.klutch.sh/)
Database Variables (for PostgreSQL - recommended):
GOGS_DB_TYPE:postgres(ormysql,sqlite3)GOGS_DB_HOST: PostgreSQL host with port (e.g.,postgres-app.klutch.sh:8000)GOGS_DB_NAME: Database name (e.g.,gogs)GOGS_DB_USER: Database username (e.g.,gogs)GOGS_DB_PASSWORD: Strong database password
Security Variables:
GOGS_SECRET_KEY: Random secret key for session encryption (generate a long random string)
Optional Variables:
GOGS_SSH_PORT: SSH port (default:22)GOGS_DISABLE_SSH: Set totrueto disable SSH (default:false)GOGS_DISABLE_REGISTRATION: Set totrueto disable new user registration
Security Note: Always use strong, unique passwords and secret keys for production deployments.
-
Attach a Persistent Volume
This is critical for ensuring your Git repositories and Gogs data persist across deployments:
- In the Volumes section, click “Add Volume”
- Mount Path: Enter
/data(this is where Gogs stores all its data including repositories, configuration, and logs) - Size: Choose an appropriate size based on your expected repository storage needs (e.g., 10GB for small teams, 50GB+ for larger organizations)
Important: Gogs requires persistent storage to maintain your repositories, user data, and configuration between container restarts.
-
Configure Additional Settings
- Region: Select the region closest to your users for optimal latency
- Compute Resources: Choose CPU and memory based on your team size (minimum 512MB RAM recommended, 1GB+ for larger teams)
- Instances: Start with 1 instance (scale horizontally as needed)
-
Deploy Your Application
Click “Create” to start the deployment. Klutch.sh will:
- Automatically detect your Dockerfile in the repository root
- Build the Docker image
- Attach the persistent volume
- Start your Gogs container
- Assign a URL for external access
-
Complete Initial Setup
Once deployment is complete, you’ll receive a URL like
example-app.klutch.sh. Navigate to this URL to complete the Gogs installation wizard:https://example-app.klutch.shFollow the installation wizard to:
- Verify database configuration
- Set up the admin account
- Configure basic settings
- Complete the installation
Database Configuration
Gogs supports multiple database backends. Here’s how to configure each:
SQLite (Development Only)
SQLite is the simplest option and requires no additional setup, but it’s not recommended for production use with multiple users.
Configuration:
- Set
GOGS_DB_TYPE=sqlite3 - No additional environment variables needed
- Database file stored in
/data/gogs/data/gogs.db
Pros:
- No external database required
- Zero configuration
- Good for single-user or testing
Cons:
- Limited concurrent access
- Not suitable for teams
- Slower with large repositories
PostgreSQL (Recommended)
PostgreSQL is the recommended database for production deployments due to its reliability and performance.
Setup Steps:
-
Deploy a PostgreSQL instance on Klutch.sh (follow the PostgreSQL guide)
-
Create a database and user for Gogs:
CREATE DATABASE gogs;CREATE USER gogs WITH PASSWORD 'your-secure-password';GRANT ALL PRIVILEGES ON DATABASE gogs TO gogs; -
Configure Gogs environment variables:
Terminal window GOGS_DB_TYPE=postgresGOGS_DB_HOST=postgres-app.klutch.sh:8000GOGS_DB_NAME=gogsGOGS_DB_USER=gogsGOGS_DB_PASSWORD=your-secure-password
Connection String Format:
postgres://gogs:password@postgres-app.klutch.sh:8000/gogs?sslmode=disableMySQL/MariaDB
MySQL and MariaDB are also well-supported and offer excellent performance.
Setup Steps:
-
Deploy a MySQL instance on Klutch.sh
-
Create a database and user:
CREATE DATABASE gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;CREATE USER 'gogs'@'%' IDENTIFIED BY 'your-secure-password';GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'%';FLUSH PRIVILEGES; -
Configure Gogs environment variables:
Terminal window GOGS_DB_TYPE=mysqlGOGS_DB_HOST=mysql-app.klutch.sh:8000GOGS_DB_NAME=gogsGOGS_DB_USER=gogsGOGS_DB_PASSWORD=your-secure-password
Important: Use utf8mb4 character set for full Unicode support including emojis.
Environment Variables Reference
Complete list of Gogs environment variables you can configure in Klutch.sh:
| Variable | Description | Required | Default |
|---|---|---|---|
GOGS_DOMAIN | Domain name for Gogs instance | Yes | localhost |
GOGS_ROOT_URL | Full URL including protocol | Yes | http://localhost:3000/ |
GOGS_DB_TYPE | Database type (sqlite3, postgres, mysql) | No | sqlite3 |
GOGS_DB_HOST | Database host and port | No* | 127.0.0.1:5432 |
GOGS_DB_NAME | Database name | No* | gogs |
GOGS_DB_USER | Database username | No* | root |
GOGS_DB_PASSWORD | Database password | No* | Empty |
GOGS_SECRET_KEY | Secret key for encryption | Yes | Random |
GOGS_SSH_PORT | SSH port for Git operations | No | 22 |
GOGS_DISABLE_SSH | Disable SSH access | No | false |
GOGS_DISABLE_REGISTRATION | Disable new user registration | No | false |
GOGS_REQUIRE_SIGNIN | Require login to view pages | No | false |
GOGS_MAILER_ENABLED | Enable email notifications | No | false |
GOGS_MAILER_HOST | SMTP host and port | No* | Empty |
GOGS_MAILER_USER | SMTP username | No* | Empty |
GOGS_MAILER_PASSWD | SMTP password | No* | Empty |
*Required when using external database or email features
Git Operations
After your Gogs instance is deployed, you can perform all standard Git operations:
Creating a Repository
- Log in to your Gogs web interface
- Click the ”+” icon in the top right
- Select “New Repository”
- Fill in repository details and click “Create Repository”
Cloning via HTTPS
git clone https://example-app.klutch.sh/username/repository.gitcd repositoryCloning via SSH
For SSH access, configure your SSH key first in Gogs settings, then:
git clone ssh://git@example-app.klutch.sh:22/username/repository.gitcd repositoryPushing Changes
git add .git commit -m "Your commit message"git push origin mainAdding SSH Keys
-
Generate SSH key (if you don’t have one):
Terminal window ssh-keygen -t ed25519 -C "your-email@example.com" -
Copy your public key:
Terminal window cat ~/.ssh/id_ed25519.pub -
Add to Gogs:
- Navigate to Settings → SSH Keys
- Click “Add Key”
- Paste your public key
- Click “Add Key”
Production Best Practices
Security Recommendations
- Strong Passwords: Use a password manager to generate strong, random passwords for database and admin accounts
- Secret Key: Generate a long, random secret key using:
openssl rand -base64 64 - HTTPS Only: Klutch.sh provides HTTPS by default; ensure
GOGS_ROOT_URLuseshttps:// - Disable Registration: After creating necessary accounts, set
GOGS_DISABLE_REGISTRATION=trueto prevent unauthorized signups - Regular Backups: Implement a backup strategy for your Git repositories using volume snapshots
- Update Regularly: Keep Gogs updated to the latest version for security patches
- Use External Database: PostgreSQL or MySQL instead of SQLite for production
- Enable 2FA: Configure two-factor authentication for admin accounts
- Restrict Admin Panel: Limit access to the admin panel to trusted users only
Performance Optimization
- Database Indexing: Ensure your database has proper indexes (automatic with PostgreSQL/MySQL)
- Repository Size: Monitor repository sizes and implement size limits if necessary
- Cache Configuration: Gogs includes built-in caching; ensure it’s properly configured
- Resource Allocation: Monitor CPU and memory usage and scale accordingly
- Git LFS: Consider enabling Git Large File Storage for repositories with large binary files
- Horizontal Scaling: For large teams, scale horizontally behind a load balancer
Monitoring and Maintenance
Monitor your Gogs deployment for:
- Response Times: Ensure Git operations and web interface are responsive
- Storage Usage: Watch repository storage growth and volume capacity
- Memory Usage: Gogs should use minimal memory; monitor for memory leaks
- Database Performance: Monitor database query performance and connection pool
- Error Logs: Check
/data/gogs/logfor errors or warnings - User Activity: Review admin logs for suspicious activity
Data Management
- Regular Backups: Create automated backups of
/datavolume - Repository Archives: Export important repositories periodically
- Database Dumps: For external databases, schedule regular dumps
- Retention Policies: Define data retention policies for old repositories
- Migration Testing: Test your backup and restore procedures regularly
Email Configuration
For production use, configure email notifications:
GOGS_MAILER_ENABLED=trueGOGS_MAILER_HOST=smtp.gmail.com:587GOGS_MAILER_USER=your-email@gmail.comGOGS_MAILER_PASSWD=your-app-passwordGOGS_MAILER_FROM=noreply@example.comEmail enables:
- User registration confirmation
- Password reset
- Repository notifications
- Issue and pull request updates
Advanced Configuration
Custom Configuration File
For advanced settings not covered by environment variables, create a custom app.ini:
-
Create a custom configuration:
Terminal window mkdir -p custom/confnano custom/conf/app.ini -
Add custom settings (example):
[repository.upload]ENABLED = trueALLOWED_TYPES =FILE_MAX_SIZE = 50MAX_FILES = 5[attachment]ENABLED = trueMAX_SIZE = 4MAX_FILES = 5[picture]DISABLE_GRAVATAR = false[webhook]QUEUE_LENGTH = 1000DELIVER_TIMEOUT = 5 -
Mount the custom directory as a volume in your Dockerfile
Using Git LFS
To enable Git Large File Storage:
-
Install Git LFS in your Dockerfile:
RUN apk add --no-cache git-lfs -
Configure in
app.ini:[server]LFS_START_SERVER = trueLFS_CONTENT_PATH = /data/git/lfs
Webhook Configuration
Gogs supports webhooks for CI/CD integration:
- Navigate to Repository Settings → Webhooks
- Click “Add Webhook”
- Choose webhook type (Gogs, Slack, Discord, etc.)
- Enter payload URL
- Select events to trigger webhook
- Click “Add Webhook”
Backup Automation
Create a backup script:
#!/bin/bashBACKUP_DIR="/backup"TIMESTAMP=$(date +%Y%m%d_%H%M%S)
# Backup Git repositoriestar -czf $BACKUP_DIR/gogs-repos-$TIMESTAMP.tar.gz /data/git
# Backup Gogs datatar -czf $BACKUP_DIR/gogs-data-$TIMESTAMP.tar.gz /data/gogs
# Backup database (if using PostgreSQL)pg_dump -h $GOGS_DB_HOST -U $GOGS_DB_USER $GOGS_DB_NAME > $BACKUP_DIR/gogs-db-$TIMESTAMP.sql
# Remove backups older than 30 daysfind $BACKUP_DIR -name "gogs-*" -mtime +30 -deleteTroubleshooting
Cannot Access Gogs Web Interface
- Verify your app is running in the Klutch.sh dashboard
- Check that the internal port is set to 3000
- Ensure HTTP traffic type is selected
- Review application logs for startup errors
- Verify
GOGS_ROOT_URLmatches your actual URL
Database Connection Errors
- Verify database credentials are correct
- Check database host is accessible from Gogs container
- Ensure database exists and user has proper permissions
- For PostgreSQL, verify port 8000 is used (Klutch.sh default for TCP traffic)
- Test database connection separately
Git Push/Pull Fails
- Check SSH keys are properly added to Gogs
- Verify repository permissions for the user
- Ensure
/data/githas sufficient space - Check Git URL format is correct
- Review Gogs logs for detailed error messages
SSH Access Not Working
- Verify
GOGS_DISABLE_SSHis not set totrue - Check SSH port configuration matches your setup
- Ensure SSH keys are added to your Gogs user profile
- Test SSH connection:
ssh -T git@example-app.klutch.sh -p 22 - Review Gogs SSH logs
Data Not Persisting
- Confirm the persistent volume is attached at
/data - Check the volume has sufficient space
- Verify Gogs is writing to the correct directory
- Review volume mount configuration in Klutch.sh
Performance Issues
- Monitor CPU and memory usage in Klutch.sh dashboard
- Check database query performance
- Review repository sizes for large repos
- Consider increasing compute resources
- Enable caching if not already active
Installation Wizard Keeps Appearing
This means INSTALL_LOCK is not set:
- Complete the installation wizard properly
- Ensure
/datavolume is persistent - Check that
/data/gogs/conf/app.iniexists and hasINSTALL_LOCK = true
Migrating from GitHub/GitLab
Gogs supports importing repositories from other Git services:
Import from GitHub
- In Gogs, click ”+” → “New Migration”
- Select “GitHub”
- Enter GitHub repository URL
- Provide GitHub access token (if private repo)
- Click “Migrate Repository”
Import from GitLab
- In Gogs, click ”+” → “New Migration”
- Select “GitLab”
- Enter GitLab repository URL
- Provide GitLab access token (if private repo)
- Click “Migrate Repository”
Bulk Migration
For bulk migrations, use the Gogs API:
curl -X POST https://example-app.klutch.sh/api/v1/repos/migrate \ -H "Authorization: token YOUR_GOGS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "clone_addr": "https://github.com/username/repo.git", "uid": 1, "repo_name": "migrated-repo" }'Upgrading Gogs
To upgrade Gogs to a new version:
-
Check the Gogs releases page for the latest version
-
Update the version in your Dockerfile:
FROM gogs/gogs:0.13.0 -
Commit and push the changes:
Terminal window git add Dockerfilegit commit -m "Upgrade Gogs to version 0.13.0"git push -
Klutch.sh will automatically rebuild and redeploy your application
-
Your data will be preserved in the persistent volume
-
Review the release notes for any breaking changes or migration steps
Important: Always backup your data before upgrading, especially for major version changes.
Additional Resources
- Klutch.sh Documentation
- Gogs GitHub Repository
- Official Gogs Documentation
- Klutch.sh Volumes Guide
- Klutch.sh Networking Guide
- Gogs Docker Image
- Gogs Docker Configuration
Conclusion
Deploying Gogs to Klutch.sh with Docker provides a lightweight, self-hosted Git service with full control over your code repositories. By following this guide, you’ve set up a production-ready Gogs instance with persistent storage, proper database configuration, and security best practices. Your Git service is now ready to host unlimited repositories for your team, with a familiar GitHub-like interface and powerful Git features, all while maintaining complete control over your source code and data.