This tutorial will guide you through deploying the CodeAgent program on Ubuntu systems.
- Ubuntu 18.04 or higher
- At least 2GB RAM
- At least 10GB available disk space
- Network connection
First, update system packages:
sudo apt update
sudo apt upgrade -y# Install Git
sudo apt install git -y
# Verify installation
git --version
# Configure Git (optional)
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"sudo apt remove docker docker-engine docker.io containerd runcsudo apt install apt-transport-https ca-certificates curl gnupg lsb-release -ycurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpgecho "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullsudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io -ysudo systemctl start docker
sudo systemctl enable dockersudo usermod -aG docker $USER
# Re-login or execute the following command to make changes effective
newgrp dockerdocker --version
docker run hello-world# Download latest version of Go (adjust according to latest version number)
wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz# Remove old version (if exists)
sudo rm -rf /usr/local/go
# Extract to /usr/local
sudo tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz# Add to ~/.bashrc
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrcgo version# Clone project
git clone https://github.com/your-username/codeagent.git
cd codeagent
# Or if project is in private repository
git clone git@github.com:your-username/codeagent.git
cd codeagentdocker build -f Dockerfile.claude -t codeagent-claude:latest .docker build -f Dockerfile.gemini -t codeagent-gemini:latest .cp config.example.yaml config.yamlnano config.yamlConfiguration example:
# CodeAgent configuration file
server:
port: 8080
host: "0.0.0.0"
# GitHub configuration
github:
token: "your-github-token"
webhook_secret: "your-webhook-secret"
# AI service configuration
ai:
# Claude configuration
claude:
enabled: true
api_key: "your-claude-api-key"
model: "claude-3-sonnet-20240229"
# Gemini configuration
gemini:
enabled: true
api_key: "your-gemini-api-key"
model: "gemini-pro"
# Workspace directory configuration
workspace:
# Important: Avoid using /tmp directory on macOS, may cause Docker mount issues
# Recommended paths:
# - macOS: /private/tmp/codeagent-workspace
# - Linux: /var/tmp/codeagent-workspace
# - Cross-platform: ~/tmp/codeagent-workspace
base_path: "/private/tmp/codeagent-workspace" # Recommended for macOS
cleanup_after_hours: 24cp env.example .env
nano .env# Compile project
go build -o codeagent ./cmd/codeagent
# Run program
./codeagent# Run Claude version
docker run -d \
--name codeagent-claude \
-p 8080:8080 \
-v $(pwd)/config.yaml:/app/config.yaml \
-v $(pwd)/workspace:/app/workspace \
codeagent-claude:latest
# Run Gemini version
docker run -d \
--name codeagent-gemini \
-p 8080:8080 \
-v $(pwd)/config.yaml:/app/config.yaml \
-v $(pwd)/workspace:/app/workspace \
codeagent-gemini:latest# Check if program is running
ps aux | grep codeagent
# Check if port is listening
netstat -tlnp | grep 8080
# If using Docker
docker ps# Test health check endpoint
curl http://localhost:8080/health
# Test GitHub webhook endpoint
curl -X POST http://localhost:8080/webhook/github \
-H "Content-Type: application/json" \
-d '{"test": "data"}'sudo nano /etc/systemd/system/codeagent.serviceService file content:
[Unit]
Description=CodeAgent Service
After=network.target
[Service]
Type=simple
User=your-username
WorkingDirectory=/path/to/codeagent
ExecStart=/path/to/codeagent/codeagent
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable codeagent
sudo systemctl start codeagent
sudo systemctl status codeagentsudo apt install nginx -ysudo nano /etc/nginx/sites-available/codeagentConfiguration content:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:8080;
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;
}
}sudo ln -s /etc/nginx/sites-available/codeagent /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx# Allow SSH
sudo ufw allow ssh
# Allow HTTP/HTTPS
sudo ufw allow 80
sudo ufw allow 443
# If directly exposing CodeAgent port
sudo ufw allow 8080
# Enable firewall
sudo ufw enable# If using systemd
sudo journalctl -u codeagent -f
# If running directly
tail -f /path/to/codeagent/logs/codeagent.log
# If using Docker
docker logs -f codeagent-claudesudo nano /etc/logrotate.d/codeagentConfiguration content:
/path/to/codeagent/logs/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
create 644 your-username your-username
}
-
Docker permission issues
sudo chmod 666 /var/run/docker.sock
-
macOS /tmp directory mount issues
# Issue: /workspace directory is empty in container # Cause: macOS's /tmp is a symlink, Docker mount may have issues # Solution: Use /private/tmp or ~/tmp directory # Modify configuration file workspace: base_path: "/private/tmp/codeagent-workspace" # Recommended # or base_path: "~/tmp/codeagent-workspace" # Cross-platform
-
Port occupied
sudo netstat -tlnp | grep 8080 sudo kill -9 <PID>
-
GitHub Token permission issues
- Ensure GitHub Token has sufficient permissions
- Check if Token is expired
-
AI API connection issues
- Check network connection
- Verify API Key is correct
- Check if API quota is exhausted
# Enable debug logging
export LOG_LEVEL=debug
./codeagent
# Or use Docker
docker run -it --rm \
-e LOG_LEVEL=debug \
-v $(pwd)/config.yaml:/app/config.yaml \
codeagent-claude:latest# Backup configuration files
cp config.yaml config.yaml.backup
# Backup workspace directory
tar -czf workspace-backup-$(date +%Y%m%d).tar.gz workspace/# Restore configuration files
cp config.yaml.backup config.yaml
# Restore workspace directory
tar -xzf workspace-backup-20231201.tar.gzcd codeagent
git pull origin main
go build -o codeagent ./cmd/codeagent
sudo systemctl restart codeagentdocker build -f Dockerfile.claude -t codeagent-claude:latest .
docker stop codeagent-claude
docker rm codeagent-claude
docker run -d --name codeagent-claude -p 8080:8080 codeagent-claude:latestYour CodeAgent is now successfully deployed and running. You can access it through:
- Local access: http://localhost:8080
- Remote access: http://your-server-ip:8080
- Domain access: http://your-domain.com (if Nginx is configured)
Remember to regularly check logs and monitor system status to ensure the service is running properly.