This repository contains Terraform configurations to deploy the CrowdLlama DHT server on Linode cloud infrastructure.
CrowdLlama is a distributed system that leverages the open-source Ollama project to run LLM inference tasks across multiple nodes using peer-to-peer (P2P) networking. This infrastructure focuses on deploying the DHT (Distributed Hash Table) server component.
The deployment includes:
- Linode Instance: Ubuntu 22.04 server running the DHT component
- Docker & Docker Compose: Containerized deployment with automatic updates
- Watchtower: Automatically updates containers when new images are pushed to GHCR
- Firewall: Configured to allow SSH (port 22) and DHT traffic (port 9000)
- Systemd Service: Ensures the DHT server starts automatically on boot
- Linode Account: You need a Linode account with API access
- Linode API Token: Generate a token at https://cloud.linode.com/profile/tokens
- Terraform: Install Terraform (version >= 1.0)
- GitHub Repository: Ensure your CrowdLlama repository has GitHub Actions enabled
git clone <your-infra-repo>
cd infra
# Copy the example configuration
cp terraform.tfvars.example terraform.tfvars
# Edit the configuration with your values
nano terraform.tfvars
Edit terraform.tfvars
with your specific values:
# Required
linode_token = "your-linode-api-token"
root_password = "your-secure-root-password"
# Optional (defaults shown)
environment = "prod"
linode_region = "us-east"
linode_instance_type = "g6-standard-1"
# Initialize Terraform
terraform init
# Plan the deployment
terraform plan
# Apply the configuration
terraform apply
After deployment, you can:
# Get the server IP
terraform output dht_server_ip
# SSH into the server
terraform output dht_server_ssh_command
# Check service status
ssh root@<server-ip> "systemctl status crowdllama-dht"
The deployment expects Docker images to be available at:
ghcr.io/matiasinsaurralde/crowdllama/dht:latest
To build and push new Docker images:
-
Tag your release:
git tag v1.0.0 git push origin v1.0.0
-
GitHub Actions will automatically:
- Build the Docker image from
Dockerfile.dht
- Push to GitHub Container Registry (GHCR)
- Tag with version and
latest
- Build the Docker image from
-
Watchtower will automatically:
- Detect new images every 5 minutes
- Pull and restart containers with new images
- Clean up old images
Available Linode instance types:
g6-standard-1
: 1 CPU, 2GB RAM (default)g6-standard-2
: 2 CPU, 4GB RAMg6-standard-4
: 4 CPU, 8GB RAM
Available Linode regions:
us-east
: Newark, NJus-west
: Fremont, CAus-central
: Dallas, TXus-southeast
: Atlanta, GAus-southwest
: Dallas, TXap-west
: Singaporeap-southeast
: Sydney, Australiaap-south
: Mumbai, Indiaap-northeast
: Tokyo, Japaneu-central
: Frankfurt, Germanyeu-west
: London, UK
To enable DNS records:
create_dns_record = true
domain_id = 12345 # Your Linode domain ID
dns_subdomain = "dht"
# Check service status
systemctl status crowdllama-dht
# View logs
journalctl -u crowdllama-dht -f
# Restart service
systemctl restart crowdllama-dht
# View container logs
docker-compose -f /opt/crowdllama/docker-compose.yml logs -f
# View specific service logs
docker-compose -f /opt/crowdllama/docker-compose.yml logs -f dht
# View Watchtower logs
docker-compose -f /opt/crowdllama/docker-compose.yml logs -f watchtower
The deployment includes a firewall with the following rules:
-
Inbound:
- SSH (TCP 22): Allowed from anywhere
- DHT (TCP/UDP 9000): Allowed from anywhere
-
Outbound:
- All traffic allowed
- SSH Key Authentication: Consider setting up SSH keys instead of password authentication
- Restrict SSH Access: Limit SSH access to specific IP ranges in production
- Regular Updates: Keep the system updated with security patches
- Monitoring: Set up monitoring and alerting for the DHT service
-
Container won't start:
docker-compose -f /opt/crowdllama/docker-compose.yml logs dht
-
Port 9000 not accessible:
# Check if port is listening netstat -tlnp | grep 9000 # Check firewall status ufw status
-
Watchtower not updating:
# Check Watchtower logs docker-compose -f /opt/crowdllama/docker-compose.yml logs watchtower # Manually pull latest image docker pull ghcr.io/matiasinsaurralde/crowdllama/dht:latest
# Stop all containers
docker-compose -f /opt/crowdllama/docker-compose.yml down
# Start all containers
docker-compose -f /opt/crowdllama/docker-compose.yml up -d
# Rebuild and restart
docker-compose -f /opt/crowdllama/docker-compose.yml up -d --build
To test the Docker Compose setup locally:
# Clone the CrowdLlama repository
git clone https://github.com/matiasinsaurralde/crowdllama.git
cd crowdllama
# Build the DHT image
docker build -f Dockerfile.dht -t crowdllama/dht:latest .
# Run locally
docker-compose up -d
- Fork the repository
- Create a feature branch
- Make your changes
- Test the deployment
- Submit a pull request
This project is licensed under the MIT License. See the LICENSE file for details.
For issues related to:
- Infrastructure: Create an issue in this repository
- CrowdLlama: Create an issue in the main repository