Update Docker configuration and add Gitea CI/CD workflows
- Change Docker image in docker-compose.prod.yml to use 'portfolio-app:latest'. - Add new scripts for Gitea deployment and setup of Gitea runner. - Introduce CI/CD workflows for automated testing, security scanning, and deployment in Gitea. - Enhance package.json with new deployment scripts for Gitea integration.
This commit is contained in:
192
scripts/setup-gitea-runner.sh
Executable file
192
scripts/setup-gitea-runner.sh
Executable file
@@ -0,0 +1,192 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Gitea Runner Setup Script
|
||||
# Installiert und konfiguriert einen lokalen Gitea Runner
|
||||
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
GITEA_URL="${GITEA_URL:-http://localhost:3000}"
|
||||
RUNNER_NAME="${RUNNER_NAME:-portfolio-runner}"
|
||||
RUNNER_LABELS="${RUNNER_LABELS:-ubuntu-latest,self-hosted,portfolio}"
|
||||
RUNNER_WORK_DIR="${RUNNER_WORK_DIR:-/tmp/gitea-runner}"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Logging function
|
||||
log() {
|
||||
echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if running as root
|
||||
if [[ $EUID -eq 0 ]]; then
|
||||
error "This script should not be run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "🚀 Setting up Gitea Runner for Portfolio"
|
||||
|
||||
# Check if Gitea URL is accessible
|
||||
log "🔍 Checking Gitea server accessibility..."
|
||||
if ! curl -f "$GITEA_URL" > /dev/null 2>&1; then
|
||||
error "Cannot access Gitea server at $GITEA_URL"
|
||||
error "Please make sure Gitea is running and accessible"
|
||||
exit 1
|
||||
fi
|
||||
success "✅ Gitea server is accessible"
|
||||
|
||||
# Create runner directory
|
||||
log "📁 Creating runner directory..."
|
||||
mkdir -p "$RUNNER_WORK_DIR"
|
||||
cd "$RUNNER_WORK_DIR"
|
||||
|
||||
# Download Gitea Runner
|
||||
log "📥 Downloading Gitea Runner..."
|
||||
RUNNER_VERSION="latest"
|
||||
RUNNER_ARCH="linux-amd64"
|
||||
|
||||
# Get latest version
|
||||
if [ "$RUNNER_VERSION" = "latest" ]; then
|
||||
RUNNER_VERSION=$(curl -s https://api.github.com/repos/woodpecker-ci/woodpecker/releases/latest | grep -o '"tag_name": "[^"]*' | grep -o '[^"]*$')
|
||||
fi
|
||||
|
||||
RUNNER_URL="https://github.com/woodpecker-ci/woodpecker/releases/download/${RUNNER_VERSION}/woodpecker-agent_${RUNNER_VERSION}_${RUNNER_ARCH}.tar.gz"
|
||||
|
||||
log "Downloading from: $RUNNER_URL"
|
||||
curl -L -o woodpecker-agent.tar.gz "$RUNNER_URL"
|
||||
|
||||
# Extract runner
|
||||
log "📦 Extracting Gitea Runner..."
|
||||
tar -xzf woodpecker-agent.tar.gz
|
||||
chmod +x woodpecker-agent
|
||||
|
||||
success "✅ Gitea Runner downloaded and extracted"
|
||||
|
||||
# Create systemd service
|
||||
log "⚙️ Creating systemd service..."
|
||||
sudo tee /etc/systemd/system/gitea-runner.service > /dev/null <<EOF
|
||||
[Unit]
|
||||
Description=Gitea Runner for Portfolio
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$USER
|
||||
WorkingDirectory=$RUNNER_WORK_DIR
|
||||
ExecStart=$RUNNER_WORK_DIR/woodpecker-agent
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
Environment=WOODPECKER_SERVER=$GITEA_URL
|
||||
Environment=WOODPECKER_AGENT_SECRET=
|
||||
Environment=WOODPECKER_LOG_LEVEL=info
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Reload systemd
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
success "✅ Systemd service created"
|
||||
|
||||
# Instructions for manual registration
|
||||
log "📋 Manual registration required:"
|
||||
echo ""
|
||||
echo "1. Go to your Gitea instance: $GITEA_URL"
|
||||
echo "2. Navigate to: Settings → Actions → Runners"
|
||||
echo "3. Click 'Create new Runner'"
|
||||
echo "4. Copy the registration token"
|
||||
echo "5. Run the following command:"
|
||||
echo ""
|
||||
echo " cd $RUNNER_WORK_DIR"
|
||||
echo " ./woodpecker-agent register --server $GITEA_URL --token YOUR_TOKEN"
|
||||
echo ""
|
||||
echo "6. After registration, start the service:"
|
||||
echo " sudo systemctl enable gitea-runner"
|
||||
echo " sudo systemctl start gitea-runner"
|
||||
echo ""
|
||||
echo "7. Check status:"
|
||||
echo " sudo systemctl status gitea-runner"
|
||||
echo ""
|
||||
|
||||
# Create helper scripts
|
||||
log "📝 Creating helper scripts..."
|
||||
|
||||
# Start script
|
||||
cat > "$RUNNER_WORK_DIR/start-runner.sh" << 'EOF'
|
||||
#!/bin/bash
|
||||
echo "Starting Gitea Runner..."
|
||||
sudo systemctl start gitea-runner
|
||||
sudo systemctl status gitea-runner
|
||||
EOF
|
||||
|
||||
# Stop script
|
||||
cat > "$RUNNER_WORK_DIR/stop-runner.sh" << 'EOF'
|
||||
#!/bin/bash
|
||||
echo "Stopping Gitea Runner..."
|
||||
sudo systemctl stop gitea-runner
|
||||
EOF
|
||||
|
||||
# Status script
|
||||
cat > "$RUNNER_WORK_DIR/status-runner.sh" << 'EOF'
|
||||
#!/bin/bash
|
||||
echo "Gitea Runner Status:"
|
||||
sudo systemctl status gitea-runner
|
||||
echo ""
|
||||
echo "Logs (last 20 lines):"
|
||||
sudo journalctl -u gitea-runner -n 20 --no-pager
|
||||
EOF
|
||||
|
||||
# Logs script
|
||||
cat > "$RUNNER_WORK_DIR/logs-runner.sh" << 'EOF'
|
||||
#!/bin/bash
|
||||
echo "Gitea Runner Logs:"
|
||||
sudo journalctl -u gitea-runner -f
|
||||
EOF
|
||||
|
||||
chmod +x "$RUNNER_WORK_DIR"/*.sh
|
||||
|
||||
success "✅ Helper scripts created"
|
||||
|
||||
# Create environment file
|
||||
cat > "$RUNNER_WORK_DIR/.env" << EOF
|
||||
# Gitea Runner Configuration
|
||||
GITEA_URL=$GITEA_URL
|
||||
RUNNER_NAME=$RUNNER_NAME
|
||||
RUNNER_LABELS=$RUNNER_LABELS
|
||||
RUNNER_WORK_DIR=$RUNNER_WORK_DIR
|
||||
EOF
|
||||
|
||||
log "📋 Setup Summary:"
|
||||
echo " • Runner Directory: $RUNNER_WORK_DIR"
|
||||
echo " • Gitea URL: $GITEA_URL"
|
||||
echo " • Runner Name: $RUNNER_NAME"
|
||||
echo " • Labels: $RUNNER_LABELS"
|
||||
echo " • Helper Scripts: $RUNNER_WORK_DIR/*.sh"
|
||||
echo ""
|
||||
|
||||
log "🎯 Next Steps:"
|
||||
echo "1. Register the runner in Gitea web interface"
|
||||
echo "2. Enable and start the service"
|
||||
echo "3. Test with a workflow run"
|
||||
echo ""
|
||||
|
||||
success "🎉 Gitea Runner setup completed!"
|
||||
log "📁 All files are in: $RUNNER_WORK_DIR"
|
||||
Reference in New Issue
Block a user