mnemo_cards/tools/deploy/install-forgejo-runner.sh

110 lines
2.8 KiB
Bash

#!/bin/bash
# Script to install and setup Forgejo Actions Runner
# This is required for Actions to run
set -e
SERVER_IP="147.45.152.129"
SERVER_USER="root"
echo "🚀 Installing Forgejo Actions Runner..."
echo ""
echo "⚠️ You will need a registration token from Forgejo Admin panel!"
echo " Get it from: https://code.mnemo-cards.online/admin/actions/runners"
echo ""
read -p "Do you have the registration token ready? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Please get the token first, then run this script again."
exit 1
fi
read -p "Enter the registration token: " TOKEN
if [ -z "$TOKEN" ]; then
echo "❌ Token cannot be empty!"
exit 1
fi
echo ""
echo "📦 Installing runner on server..."
ssh "$SERVER_USER@$SERVER_IP" << EOF
set -e
echo "📥 Downloading act_runner..."
cd /tmp
wget -q --show-progress https://dl.gitea.com/act_runner/0.2.6/act_runner-0.2.6-linux-amd64 -O act_runner
chmod +x act_runner
mv act_runner /usr/local/bin/
echo "✅ act_runner installed"
act_runner --version
echo ""
echo "📝 Creating runner directory..."
mkdir -p /var/lib/forgejo-runner
cd /var/lib/forgejo-runner
echo ""
echo "🔐 Registering runner with token..."
/usr/local/bin/act_runner register --no-interactive \\
--instance https://code.mnemo-cards.online \\
--token $TOKEN \\
--name default-runner \\
--labels ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye
echo ""
echo "⚙️ Creating systemd service..."
cat > /etc/systemd/system/forgejo-runner.service << 'SERVICE'
[Unit]
Description=Forgejo Actions Runner
After=network.target
Wants=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/var/lib/forgejo-runner
ExecStart=/usr/local/bin/act_runner daemon --config /var/lib/forgejo-runner/.runner
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
SERVICE
echo ""
echo "🔄 Enabling and starting service..."
systemctl daemon-reload
systemctl enable forgejo-runner
systemctl start forgejo-runner
echo ""
echo "✅ Runner setup complete!"
echo ""
echo "📊 Status:"
systemctl status forgejo-runner --no-pager -l || true
echo ""
echo "📝 Runner logs (last 20 lines):"
journalctl -u forgejo-runner -n 20 --no-pager || true
EOF
echo ""
echo "✅ Done! Forgejo Actions Runner is now running!"
echo ""
echo "🔍 Check runner status:"
echo " ssh root@$SERVER_IP 'systemctl status forgejo-runner'"
echo ""
echo "📝 View logs:"
echo " ssh root@$SERVER_IP 'journalctl -u forgejo-runner -f'"
echo ""
echo "🌐 Verify in Forgejo:"
echo " https://code.mnemo-cards.online/admin/actions/runners"
echo " You should see 'default-runner' online"