Deploying Sourcehut
Introduction
Sourcehut (sr.ht) is a minimalist, privacy-focused software development platform that provides a complete suite of tools for open-source projects. Unlike feature-heavy platforms like GitHub or GitLab, Sourcehut embraces simplicity and focuses on workflows that have proven effective in major open-source projects like the Linux kernel.
Built with Python, Sourcehut consists of modular services that can be deployed independently or together. The platform prioritizes email-based workflows, mailing lists for code review, and a no-JavaScript interface that works in any browser.
Key highlights of Sourcehut:
- Git Hosting (git.sr.ht): Repository hosting with web interface and SSH access
- Mercurial Support (hg.sr.ht): Full Mercurial repository hosting
- Mailing Lists (lists.sr.ht): Email-based discussions and patch submission
- Issue Tracker (todo.sr.ht): Ticket tracking with email integration
- CI/CD (builds.sr.ht): Continuous integration with build manifests
- Paste Service (paste.sr.ht): Code snippet sharing
- Wiki (man.sr.ht): Documentation hosting with Markdown support
- Privacy-Focused: No tracking, minimal JavaScript, respects user privacy
- Email-First Workflow: Supports email-based patch submission like kernel development
- Federation Ready: Designed for decentralized deployment
- 100% Open Source: Licensed under AGPLv3 with self-hosting encouraged
This guide walks through deploying Sourcehut’s core services on Klutch.sh using Docker.
Why Deploy Sourcehut on Klutch.sh
Deploying Sourcehut on Klutch.sh provides several advantages for hosting your own development platform:
Simplified Deployment: Klutch.sh handles the container orchestration, letting you focus on configuration.
Persistent Storage: Your repositories, issues, and CI artifacts persist across deployments.
HTTPS by Default: Automatic SSL certificates for secure access to all services.
GitHub Integration: Version control your Sourcehut configuration and automatically redeploy on updates.
Scalable Resources: Allocate resources based on your team size and repository count.
Environment Variable Management: Securely store database credentials and API keys.
Custom Domains: Use your own domain for a professional development platform.
High Availability: Keep your development infrastructure accessible around the clock.
Prerequisites
Before deploying Sourcehut on Klutch.sh, ensure you have:
- A Klutch.sh account
- A GitHub account with a repository for your configuration
- PostgreSQL database (can be deployed on Klutch.sh or external)
- Redis instance for caching and queues
- SMTP server for email functionality
- Basic familiarity with Docker and software development workflows
- (Optional) Custom domain with DNS control
Deploying Sourcehut on Klutch.sh
- Select HTTP as the traffic type
- Set the internal port to 5000
Create a GitHub Repository
Create a new GitHub repository for your Sourcehut deployment configuration.
Create Your Dockerfile
Create a Dockerfile for the meta.sr.ht service (user accounts and settings):
FROM alpine:3.18
# Install dependenciesRUN apk add --no-cache \ python3 \ py3-pip \ py3-psycopg2 \ py3-bcrypt \ py3-redis \ git \ postgresql-client
# Install Sourcehut packagesRUN pip3 install --break-system-packages \ srht \ metasrht
# Create configuration directoryRUN mkdir -p /etc/sr.ht
# Copy configurationCOPY config.ini /etc/sr.ht/config.ini
# Expose the web interface portEXPOSE 5000
# Set environment variablesENV SRHT_PATH=/etc/sr.ht
# Health checkHEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:5000/ || exit 1
CMD ["metasrht-web"]Create Configuration File
Create a config.ini file with your Sourcehut settings:
[sr.ht]site-name=Your Sourcehut Instancesite-info=A self-hosted software development platformenvironment=productionowner-name=Your Nameowner-email=admin@example.com
[meta.sr.ht]origin=https://meta.your-domain.comsecret-key=${META_SECRET_KEY}
[git.sr.ht]origin=https://git.your-domain.comrepos=/var/lib/git
[builds.sr.ht]origin=https://builds.your-domain.com
[lists.sr.ht]origin=https://lists.your-domain.com
[todo.sr.ht]origin=https://todo.your-domain.com
[mail]smtp-host=${SMTP_HOST}smtp-port=${SMTP_PORT}smtp-user=${SMTP_USER}smtp-password=${SMTP_PASSWORD}smtp-from=noreply@your-domain.com
[webhooks]private-key=/etc/sr.ht/webhook-private-key
[objects]storage-directory=/var/lib/srhtPush Your Repository to GitHub
Commit and push your Dockerfile and configuration files.
Create a New Project on Klutch.sh
Navigate to the Klutch.sh dashboard and create a new project named “sourcehut” or similar.
Create a New App
Within your project, create a new app for the meta.sr.ht service. Connect your GitHub repository.
Configure HTTP Traffic
In the deployment settings:
Set Environment Variables
Configure the following environment variables:
| Variable | Value |
|---|---|
META_SECRET_KEY | A long random string for session security |
DATABASE_URL | PostgreSQL connection string |
REDIS_URL | Redis connection string |
SMTP_HOST | Your SMTP server hostname |
SMTP_PORT | SMTP port (typically 587) |
SMTP_USER | SMTP username |
SMTP_PASSWORD | SMTP password |
Attach Persistent Volumes
Add the following volumes:
| Mount Path | Recommended Size | Purpose |
|---|---|---|
/var/lib/git | 100 GB | Git repository storage |
/var/lib/srht | 50 GB | Build artifacts and objects |
/var/log/srht | 10 GB | Application logs |
Deploy Your Application
Click Deploy to build and start the Sourcehut service.
Deploy Additional Services
Repeat the deployment process for other Sourcehut services (git.sr.ht, builds.sr.ht, etc.) as needed, each in their own app within the project.
Service Architecture
Sourcehut consists of multiple independent services:
| Service | Purpose | Port |
|---|---|---|
| meta.sr.ht | User accounts and authentication | 5000 |
| git.sr.ht | Git repository hosting | 5001 |
| hg.sr.ht | Mercurial repository hosting | 5002 |
| builds.sr.ht | Continuous integration | 5003 |
| lists.sr.ht | Mailing lists | 5004 |
| todo.sr.ht | Issue tracking | 5005 |
| paste.sr.ht | Code snippets | 5006 |
| man.sr.ht | Wiki/documentation | 5007 |
Initial Configuration
Database Setup
Create databases for each service:
CREATE DATABASE metasrht;CREATE DATABASE gitsrht;CREATE DATABASE buildssrht;CREATE DATABASE listssrht;CREATE DATABASE todosrht;
CREATE USER srht WITH PASSWORD 'your_secure_password';GRANT ALL PRIVILEGES ON DATABASE metasrht TO srht;GRANT ALL PRIVILEGES ON DATABASE gitsrht TO srht;GRANT ALL PRIVILEGES ON DATABASE buildssrht TO srht;GRANT ALL PRIVILEGES ON DATABASE listssrht TO srht;GRANT ALL PRIVILEGES ON DATABASE todosrht TO srht;Creating Admin User
After deploying meta.sr.ht, create an admin account through the web interface or using the CLI tools.
Configuring Git Access
For SSH access to Git repositories, configure your SSH keys through the meta.sr.ht web interface.
Email Workflow Setup
Mailing List Configuration
Sourcehut’s mailing lists support email-based patch submission:
- Create a mailing list through lists.sr.ht
- Configure your email client to send patches
- Use
git send-emailfor patch submission
Email Integration
Configure SMTP settings for:
- Account verification emails
- Password reset functionality
- Mailing list delivery
- Issue notifications
Continuous Integration
Build Manifests
Create .build.yml files in your repositories:
image: alpine/latestpackages: - python3sources: - https://git.your-domain.com/~user/projecttasks: - test: | cd project python3 -m pytestBuild Runners
For CI functionality, deploy builds.sr.ht workers alongside the web service.
Troubleshooting
Service Won’t Start
- Verify database connection strings are correct
- Check that Redis is accessible
- Review logs for configuration errors
Email Not Working
- Confirm SMTP credentials are correct
- Check that the SMTP server allows connections from your deployment
- Verify from address is authorized
Repository Access Denied
- Ensure SSH keys are properly configured
- Check repository permissions
- Verify the user has access to the repository
Additional Resources
- Sourcehut Official Site
- Sourcehut Installation Guide
- Sourcehut Source Code
- Sourcehut Documentation
- Klutch.sh Persistent Volumes
- Klutch.sh Deployments
Conclusion
Deploying Sourcehut on Klutch.sh gives you a powerful, privacy-focused software development platform that respects traditional open-source workflows. With its modular architecture, you can deploy only the services you need, starting with Git hosting and expanding to include mailing lists, CI/CD, and issue tracking. Whether you’re hosting personal projects or supporting a development team, Sourcehut on Klutch.sh provides a minimalist yet fully-featured alternative to mainstream development platforms.