ci: add Gitea Actions workflows and deployment automation
Some checks failed
Build and Test / Build Server (Linux) (push) Has been cancelled
Build and Test / Build Agent (Windows) (push) Has been cancelled
Build and Test / Security Audit (push) Has been cancelled
Build and Test / Build Summary (push) Has been cancelled
Run Tests / Test Server (push) Has been cancelled
Run Tests / Test Agent (push) Has been cancelled
Run Tests / Code Coverage (push) Has been cancelled
Run Tests / Lint and Format Check (push) Has been cancelled
Some checks failed
Build and Test / Build Server (Linux) (push) Has been cancelled
Build and Test / Build Agent (Windows) (push) Has been cancelled
Build and Test / Security Audit (push) Has been cancelled
Build and Test / Build Summary (push) Has been cancelled
Run Tests / Test Server (push) Has been cancelled
Run Tests / Test Agent (push) Has been cancelled
Run Tests / Code Coverage (push) Has been cancelled
Run Tests / Lint and Format Check (push) Has been cancelled
- Add build-and-test workflow for automated builds - Add deploy workflow for production deployments - Add test workflow for comprehensive testing - Add deployment automation script with rollback - Add version tagging automation - Add Gitea Actions runner installation script Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
169
scripts/deploy.sh
Executable file
169
scripts/deploy.sh
Executable file
@@ -0,0 +1,169 @@
|
||||
#!/bin/bash
|
||||
# Automated deployment script for GuruConnect
|
||||
# Called by CI/CD pipeline or manually
|
||||
# Usage: ./deploy.sh [package_file.tar.gz]
|
||||
|
||||
set -e
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
echo "========================================="
|
||||
echo "GuruConnect Deployment Script"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
# Configuration
|
||||
DEPLOY_DIR="/home/guru/guru-connect"
|
||||
BACKUP_DIR="/home/guru/deployments/backups"
|
||||
ARTIFACT_DIR="/home/guru/deployments/artifacts"
|
||||
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
|
||||
|
||||
# Detect package file
|
||||
if [ -n "$1" ]; then
|
||||
PACKAGE_FILE="$1"
|
||||
elif [ -f "/tmp/guruconnect-server-latest.tar.gz" ]; then
|
||||
PACKAGE_FILE="/tmp/guruconnect-server-latest.tar.gz"
|
||||
else
|
||||
echo -e "${RED}ERROR: No deployment package specified${NC}"
|
||||
echo "Usage: $0 <package_file.tar.gz>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$PACKAGE_FILE" ]; then
|
||||
echo -e "${RED}ERROR: Package file not found: $PACKAGE_FILE${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Package: $PACKAGE_FILE"
|
||||
echo "Target: $DEPLOY_DIR"
|
||||
echo ""
|
||||
|
||||
# Create backup and artifact directories
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
mkdir -p "$ARTIFACT_DIR"
|
||||
|
||||
# Backup current binary
|
||||
echo "Creating backup..."
|
||||
if [ -f "$DEPLOY_DIR/target/x86_64-unknown-linux-gnu/release/guruconnect-server" ]; then
|
||||
cp "$DEPLOY_DIR/target/x86_64-unknown-linux-gnu/release/guruconnect-server" \
|
||||
"$BACKUP_DIR/guruconnect-server-${TIMESTAMP}"
|
||||
echo -e "${GREEN}Backup created: ${BACKUP_DIR}/guruconnect-server-${TIMESTAMP}${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}No existing binary to backup${NC}"
|
||||
fi
|
||||
|
||||
# Stop service
|
||||
echo ""
|
||||
echo "Stopping GuruConnect service..."
|
||||
if sudo systemctl is-active --quiet guruconnect; then
|
||||
sudo systemctl stop guruconnect
|
||||
echo -e "${GREEN}Service stopped${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}Service not running${NC}"
|
||||
fi
|
||||
|
||||
# Extract new binary
|
||||
echo ""
|
||||
echo "Extracting deployment package..."
|
||||
TEMP_EXTRACT="/tmp/guruconnect-deploy-${TIMESTAMP}"
|
||||
mkdir -p "$TEMP_EXTRACT"
|
||||
tar -xzf "$PACKAGE_FILE" -C "$TEMP_EXTRACT"
|
||||
|
||||
# Deploy binary
|
||||
echo "Deploying new binary..."
|
||||
if [ -f "$TEMP_EXTRACT/guruconnect-server" ]; then
|
||||
mkdir -p "$DEPLOY_DIR/target/x86_64-unknown-linux-gnu/release"
|
||||
cp "$TEMP_EXTRACT/guruconnect-server" \
|
||||
"$DEPLOY_DIR/target/x86_64-unknown-linux-gnu/release/guruconnect-server"
|
||||
chmod +x "$DEPLOY_DIR/target/x86_64-unknown-linux-gnu/release/guruconnect-server"
|
||||
echo -e "${GREEN}Binary deployed${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: Binary not found in package${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Deploy static files if present
|
||||
if [ -d "$TEMP_EXTRACT/static" ]; then
|
||||
echo "Deploying static files..."
|
||||
cp -r "$TEMP_EXTRACT/static" "$DEPLOY_DIR/server/"
|
||||
echo -e "${GREEN}Static files deployed${NC}"
|
||||
fi
|
||||
|
||||
# Deploy migrations if present
|
||||
if [ -d "$TEMP_EXTRACT/migrations" ]; then
|
||||
echo "Deploying database migrations..."
|
||||
cp -r "$TEMP_EXTRACT/migrations" "$DEPLOY_DIR/server/"
|
||||
echo -e "${GREEN}Migrations deployed${NC}"
|
||||
fi
|
||||
|
||||
# Save artifact
|
||||
echo ""
|
||||
echo "Archiving deployment package..."
|
||||
cp "$PACKAGE_FILE" "$ARTIFACT_DIR/guruconnect-server-${TIMESTAMP}.tar.gz"
|
||||
ln -sf "$ARTIFACT_DIR/guruconnect-server-${TIMESTAMP}.tar.gz" \
|
||||
"$ARTIFACT_DIR/guruconnect-server-latest.tar.gz"
|
||||
echo -e "${GREEN}Artifact saved${NC}"
|
||||
|
||||
# Cleanup temp directory
|
||||
rm -rf "$TEMP_EXTRACT"
|
||||
|
||||
# Start service
|
||||
echo ""
|
||||
echo "Starting GuruConnect service..."
|
||||
sudo systemctl start guruconnect
|
||||
sleep 2
|
||||
|
||||
# Verify service started
|
||||
if sudo systemctl is-active --quiet guruconnect; then
|
||||
echo -e "${GREEN}Service started successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: Service failed to start${NC}"
|
||||
echo "Rolling back to previous version..."
|
||||
|
||||
# Rollback
|
||||
if [ -f "$BACKUP_DIR/guruconnect-server-${TIMESTAMP}" ]; then
|
||||
cp "$BACKUP_DIR/guruconnect-server-${TIMESTAMP}" \
|
||||
"$DEPLOY_DIR/target/x86_64-unknown-linux-gnu/release/guruconnect-server"
|
||||
sudo systemctl start guruconnect
|
||||
echo -e "${YELLOW}Rolled back to previous version${NC}"
|
||||
fi
|
||||
|
||||
echo "Check logs: sudo journalctl -u guruconnect -n 50"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Health check
|
||||
echo ""
|
||||
echo "Running health check..."
|
||||
sleep 2
|
||||
if curl -s http://172.16.3.30:3002/health | grep -q "OK"; then
|
||||
echo -e "${GREEN}Health check: PASSED${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}WARNING: Health check failed${NC}"
|
||||
echo "Service may still be starting up..."
|
||||
fi
|
||||
|
||||
# Get version info
|
||||
echo ""
|
||||
echo "Deployment version information:"
|
||||
VERSION=$($DEPLOY_DIR/target/x86_64-unknown-linux-gnu/release/guruconnect-server --version 2>/dev/null || echo "Version info not available")
|
||||
echo "$VERSION"
|
||||
|
||||
echo ""
|
||||
echo "========================================="
|
||||
echo "Deployment Complete!"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
echo "Deployment time: $TIMESTAMP"
|
||||
echo "Backup location: $BACKUP_DIR/guruconnect-server-${TIMESTAMP}"
|
||||
echo "Artifact location: $ARTIFACT_DIR/guruconnect-server-${TIMESTAMP}.tar.gz"
|
||||
echo ""
|
||||
echo "Service status:"
|
||||
sudo systemctl status guruconnect --no-pager | head -15
|
||||
echo ""
|
||||
echo "To view logs: sudo journalctl -u guruconnect -f"
|
||||
echo "To rollback: cp $BACKUP_DIR/guruconnect-server-${TIMESTAMP} target/x86_64-unknown-linux-gnu/release/guruconnect-server && sudo systemctl restart guruconnect"
|
||||
echo ""
|
||||
113
scripts/install-gitea-runner.sh
Executable file
113
scripts/install-gitea-runner.sh
Executable file
@@ -0,0 +1,113 @@
|
||||
#!/bin/bash
|
||||
# Install and configure Gitea Actions Runner
|
||||
# Run as: sudo bash install-gitea-runner.sh
|
||||
|
||||
set -e
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
echo "========================================="
|
||||
echo "Gitea Actions Runner Installation"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
# Check if running as root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo -e "${RED}ERROR: This script must be run as root (sudo)${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Variables
|
||||
RUNNER_VERSION="0.2.11"
|
||||
RUNNER_USER="gitea-runner"
|
||||
RUNNER_HOME="/home/${RUNNER_USER}"
|
||||
GITEA_URL="https://git.azcomputerguru.com"
|
||||
RUNNER_NAME="gururmm-runner"
|
||||
|
||||
echo "Installing Gitea Actions Runner v${RUNNER_VERSION}"
|
||||
echo "Target: ${GITEA_URL}"
|
||||
echo ""
|
||||
|
||||
# Create runner user
|
||||
if ! id "${RUNNER_USER}" &>/dev/null; then
|
||||
echo "Creating ${RUNNER_USER} user..."
|
||||
useradd -m -s /bin/bash "${RUNNER_USER}"
|
||||
echo -e "${GREEN}User created${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}User ${RUNNER_USER} already exists${NC}"
|
||||
fi
|
||||
|
||||
# Download runner binary
|
||||
echo "Downloading Gitea Actions Runner..."
|
||||
cd /tmp
|
||||
wget -q "https://dl.gitea.com/act_runner/${RUNNER_VERSION}/act_runner-${RUNNER_VERSION}-linux-amd64" -O act_runner
|
||||
|
||||
# Install binary
|
||||
echo "Installing binary..."
|
||||
chmod +x act_runner
|
||||
mv act_runner /usr/local/bin/
|
||||
chown root:root /usr/local/bin/act_runner
|
||||
|
||||
# Create runner directory
|
||||
echo "Creating runner directory..."
|
||||
mkdir -p "${RUNNER_HOME}/.runner"
|
||||
chown -R "${RUNNER_USER}:${RUNNER_USER}" "${RUNNER_HOME}/.runner"
|
||||
|
||||
echo ""
|
||||
echo "========================================="
|
||||
echo "Runner Registration"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
echo "To complete setup, you need to register the runner with Gitea:"
|
||||
echo ""
|
||||
echo "1. Go to: ${GITEA_URL}/admin/actions/runners"
|
||||
echo "2. Click 'Create new Runner'"
|
||||
echo "3. Copy the registration token"
|
||||
echo "4. Run as ${RUNNER_USER}:"
|
||||
echo ""
|
||||
echo " sudo -u ${RUNNER_USER} act_runner register \\"
|
||||
echo " --instance ${GITEA_URL} \\"
|
||||
echo " --token YOUR_REGISTRATION_TOKEN \\"
|
||||
echo " --name ${RUNNER_NAME} \\"
|
||||
echo " --labels ubuntu-latest,ubuntu-22.04"
|
||||
echo ""
|
||||
echo "5. Then create systemd service:"
|
||||
echo ""
|
||||
cat > /etc/systemd/system/gitea-runner.service << 'EOF'
|
||||
[Unit]
|
||||
Description=Gitea Actions Runner
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=gitea-runner
|
||||
WorkingDirectory=/home/gitea-runner/.runner
|
||||
ExecStart=/usr/local/bin/act_runner daemon
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
Environment="HOME=/home/gitea-runner"
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
echo "Systemd service created at /etc/systemd/system/gitea-runner.service"
|
||||
echo ""
|
||||
echo "After registration, enable and start the service:"
|
||||
echo " sudo systemctl daemon-reload"
|
||||
echo " sudo systemctl enable gitea-runner"
|
||||
echo " sudo systemctl start gitea-runner"
|
||||
echo " sudo systemctl status gitea-runner"
|
||||
echo ""
|
||||
echo "========================================="
|
||||
echo "Installation Complete!"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
echo -e "${YELLOW}Next Steps:${NC}"
|
||||
echo "1. Register the runner (see instructions above)"
|
||||
echo "2. Start the systemd service"
|
||||
echo "3. Verify runner shows up in Gitea Admin > Actions > Runners"
|
||||
echo ""
|
||||
120
scripts/version-tag.sh
Executable file
120
scripts/version-tag.sh
Executable file
@@ -0,0 +1,120 @@
|
||||
#!/bin/bash
|
||||
# Automated version tagging script
|
||||
# Creates git tags based on semantic versioning
|
||||
# Usage: ./version-tag.sh [major|minor|patch]
|
||||
|
||||
set -e
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m'
|
||||
|
||||
BUMP_TYPE="${1:-patch}"
|
||||
|
||||
echo "========================================="
|
||||
echo "GuruConnect Version Tagging"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
# Validate bump type
|
||||
if [[ ! "$BUMP_TYPE" =~ ^(major|minor|patch)$ ]]; then
|
||||
echo -e "${RED}ERROR: Invalid bump type: $BUMP_TYPE${NC}"
|
||||
echo "Usage: $0 [major|minor|patch]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get current version from latest tag
|
||||
CURRENT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
||||
echo "Current version: $CURRENT_TAG"
|
||||
|
||||
# Parse version
|
||||
if [[ $CURRENT_TAG =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
||||
MAJOR="${BASH_REMATCH[1]}"
|
||||
MINOR="${BASH_REMATCH[2]}"
|
||||
PATCH="${BASH_REMATCH[3]}"
|
||||
else
|
||||
echo -e "${YELLOW}No valid version tag found, starting from v0.1.0${NC}"
|
||||
MAJOR=0
|
||||
MINOR=1
|
||||
PATCH=0
|
||||
fi
|
||||
|
||||
# Bump version
|
||||
case $BUMP_TYPE in
|
||||
major)
|
||||
MAJOR=$((MAJOR + 1))
|
||||
MINOR=0
|
||||
PATCH=0
|
||||
;;
|
||||
minor)
|
||||
MINOR=$((MINOR + 1))
|
||||
PATCH=0
|
||||
;;
|
||||
patch)
|
||||
PATCH=$((PATCH + 1))
|
||||
;;
|
||||
esac
|
||||
|
||||
NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}"
|
||||
|
||||
echo "New version: $NEW_TAG"
|
||||
echo ""
|
||||
|
||||
# Check if tag already exists
|
||||
if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then
|
||||
echo -e "${RED}ERROR: Tag $NEW_TAG already exists${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Show changes since last tag
|
||||
echo "Changes since $CURRENT_TAG:"
|
||||
echo "-------------------------------------------"
|
||||
git log --oneline "${CURRENT_TAG}..HEAD" | head -20
|
||||
echo "-------------------------------------------"
|
||||
echo ""
|
||||
|
||||
# Confirm
|
||||
read -p "Create tag $NEW_TAG? (y/N) " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Cancelled."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Update Cargo.toml versions
|
||||
echo ""
|
||||
echo "Updating Cargo.toml versions..."
|
||||
if [ -f "server/Cargo.toml" ]; then
|
||||
sed -i.bak "s/^version = .*/version = \"${MAJOR}.${MINOR}.${PATCH}\"/" server/Cargo.toml
|
||||
rm server/Cargo.toml.bak 2>/dev/null || true
|
||||
echo -e "${GREEN}Updated server/Cargo.toml${NC}"
|
||||
fi
|
||||
|
||||
if [ -f "agent/Cargo.toml" ]; then
|
||||
sed -i.bak "s/^version = .*/version = \"${MAJOR}.${MINOR}.${PATCH}\"/" agent/Cargo.toml
|
||||
rm agent/Cargo.toml.bak 2>/dev/null || true
|
||||
echo -e "${GREEN}Updated agent/Cargo.toml${NC}"
|
||||
fi
|
||||
|
||||
# Commit version bump
|
||||
echo ""
|
||||
echo "Committing version bump..."
|
||||
git add server/Cargo.toml agent/Cargo.toml 2>/dev/null || true
|
||||
git commit -m "chore: bump version to ${NEW_TAG}" || echo "No changes to commit"
|
||||
|
||||
# Create tag
|
||||
echo ""
|
||||
echo "Creating tag $NEW_TAG..."
|
||||
git tag -a "$NEW_TAG" -m "Release $NEW_TAG"
|
||||
|
||||
echo -e "${GREEN}Tag created successfully${NC}"
|
||||
echo ""
|
||||
echo "To push tag to remote:"
|
||||
echo " git push origin $NEW_TAG"
|
||||
echo ""
|
||||
echo "To push all changes and tag:"
|
||||
echo " git push origin main && git push origin $NEW_TAG"
|
||||
echo ""
|
||||
echo "This will trigger the deployment workflow in CI/CD"
|
||||
echo ""
|
||||
Reference in New Issue
Block a user