Add CI/CD deployment pipeline with Forgejo Actions

- Add .forgejo/workflows/deploy.yml for automated deployment
- Include rollback mechanism with image tagging
- Add health check verification (http://127.0.0.1:3100/health)
- Create manual rollback script for emergency use
- Add deployment documentation and setup instructions
- Supports auto-rollback on deployment failure
This commit is contained in:
openclawd 2026-02-15 11:02:43 +00:00
parent 0453176544
commit 7d3525fe57
4 changed files with 290 additions and 0 deletions

72
scripts/rollback.sh Executable file
View file

@ -0,0 +1,72 @@
#!/bin/bash
set -e
echo "🔄 DocFast Rollback Script"
echo "=========================="
# Check if we're on the server
if [ ! -d "/root/docfast" ]; then
echo "❌ This script should be run on the production server"
exit 1
fi
cd /root/docfast
# List available rollback images
echo "📋 Available rollback images:"
ROLLBACK_IMAGES=$(docker images --format "table {{.Repository}}:{{.Tag}}\t{{.CreatedAt}}" | grep "docfast-docfast:rollback-" | head -10)
if [ -z "$ROLLBACK_IMAGES" ]; then
echo "❌ No rollback images available"
exit 1
fi
echo "$ROLLBACK_IMAGES"
echo ""
# Get the most recent rollback image
LATEST_ROLLBACK=$(docker images --format "{{.Repository}}:{{.Tag}}" | grep "docfast-docfast:rollback-" | head -n1)
if [ -z "$LATEST_ROLLBACK" ]; then
echo "❌ No rollback image found"
exit 1
fi
echo "🎯 Will rollback to: $LATEST_ROLLBACK"
echo ""
# Confirm rollback
read -p "⚠️ Are you sure you want to rollback? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "❌ Rollback cancelled"
exit 1
fi
echo "🛑 Stopping current services..."
docker compose down --timeout 30
echo "🔄 Rolling back to $LATEST_ROLLBACK..."
docker tag $LATEST_ROLLBACK docfast-docfast:latest
echo "▶️ Starting services..."
docker compose up -d
echo "⏱️ Waiting for service to be ready..."
for i in {1..20}; do
if curl -f -s http://127.0.0.1:3100/health > /dev/null; then
echo "✅ Rollback successful! Service is healthy."
break
fi
if [ $i -eq 20 ]; then
echo "❌ Rollback failed - service is not responding"
exit 1
fi
echo "⏳ Attempt $i/20 - waiting 3 seconds..."
sleep 3
done
echo "📊 Service status:"
docker compose ps
echo "🎉 Rollback completed successfully!"

41
scripts/setup-secrets.sh Executable file
View file

@ -0,0 +1,41 @@
#!/bin/bash
echo "🔐 Forgejo Repository Secrets Setup"
echo "===================================="
# Source credentials to get Forgejo token
source /home/openclaw/.openclaw/workspace/.credentials/docfast.env
# Repository secrets to set up
REPO_URL="https://git.cloonar.com/api/v1/repos/openclawd/docfast/actions/secrets"
echo "Setting up repository secrets for CI/CD..."
# Server host
echo "📡 Setting SERVER_HOST..."
curl -X PUT "$REPO_URL/SERVER_HOST" \
-H "Authorization: token $FORGEJO_TOKEN" \
-H "Content-Type: application/json" \
-d '{"data":"167.235.156.214"}' \
--silent
# Server user
echo "👤 Setting SERVER_USER..."
curl -X PUT "$REPO_URL/SERVER_USER" \
-H "Authorization: token $FORGEJO_TOKEN" \
-H "Content-Type: application/json" \
-d '{"data":"root"}' \
--silent
# SSH Private Key
echo "🔑 Setting SSH_PRIVATE_KEY..."
SSH_KEY_CONTENT=$(cat /home/openclaw/.ssh/docfast | jq -Rs .)
curl -X PUT "$REPO_URL/SSH_PRIVATE_KEY" \
-H "Authorization: token $FORGEJO_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"data\":$SSH_KEY_CONTENT}" \
--silent
echo "✅ Repository secrets have been configured!"
echo ""
echo "🔍 To verify, check: https://git.cloonar.com/openclawd/docfast/settings/actions/secrets"