name: Rollback Deployment on: workflow_dispatch: inputs: environment: description: 'Environment to rollback' required: true type: choice options: - production - development version: description: 'Version/tag to rollback to (leave empty for previous)' required: false type: string jobs: rollback: name: Rollback to Previous Version runs-on: ubuntu-latest environment: name: ${{ github.event.inputs.environment }} steps: - name: Set up SSH run: | mkdir -p ~/.ssh chmod 700 ~/.ssh echo "${{ secrets.VPS_SSH_KEY }}" > ~/.ssh/deploy_key chmod 600 ~/.ssh/deploy_key ssh-keyscan -p ${{ secrets.VPS_PORT }} ${{ secrets.VPS_HOST }} >> ~/.ssh/known_hosts 2>/dev/null - name: Rollback deployment run: | ssh -i ~/.ssh/deploy_key -p ${{ secrets.VPS_PORT }} ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} bash -s << 'ENDSSH' set -e cd /opt/littleshop VERSION="${{ github.event.inputs.version }}" if [ -z "$VERSION" ]; then echo "No version specified, using 'previous' tag" # Tag previous version if it exists docker tag localhost:5000/littleshop:previous localhost:5000/littleshop:latest || { echo "❌ No previous version found to rollback to" exit 1 } docker tag localhost:5000/telebot:previous localhost:5000/telebot:latest || { echo "❌ No previous TeleBot version found to rollback to" exit 1 } else echo "Rolling back to version: $VERSION" docker tag localhost:5000/littleshop:$VERSION localhost:5000/littleshop:latest || { echo "❌ Version $VERSION not found for LittleShop" exit 1 } docker tag localhost:5000/telebot:$VERSION localhost:5000/telebot:latest || { echo "❌ Version $VERSION not found for TeleBot" exit 1 } fi # Stop current containers echo "Stopping current containers..." docker-compose down --remove-orphans docker stop telebot-service 2>/dev/null || true docker rm telebot-service 2>/dev/null || true # Start with rolled back version echo "Starting with previous version..." docker-compose up -d # Start TeleBot docker run -d \ --name telebot-service \ --restart unless-stopped \ --network silverpay_silverpay-network \ -e ASPNETCORE_URLS=http://+:5010 \ -e LittleShop__ApiUrl=http://littleshop:5000 \ -e LittleShop__UseTor=false \ -e Privacy__EnableTor=true \ -e Privacy__TorSocksHost=tor-gateway \ -e Privacy__TorSocksPort=9050 \ localhost:5000/telebot:latest docker network connect littleshop_littleshop-network telebot-service # Health check echo "Waiting for services to start..." sleep 30 echo "Running health checks..." for i in 1 2 3 4 5 6; do if curl -f -s http://localhost:5100/api/catalog/products > /dev/null 2>&1; then echo "✅ Rollback successful - health check passed" exit 0 fi echo "Health check attempt $i/6 failed, waiting..." sleep 10 done echo "❌ Rollback health check failed" docker logs littleshop --tail 50 docker logs telebot-service --tail 30 exit 1 ENDSSH - name: Cleanup if: always() run: | rm -f ~/.ssh/deploy_key