Skip to content

Deploy and Keep Active #71

Deploy and Keep Active

Deploy and Keep Active #71

Workflow file for this run

name: Deploy and Keep Active
on:
push:
branches: [ main ]
# Runs automatically every day at 0:00 UTC (8:00 AM Beijing Time)
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Deploy and Log Setup
uses: google-github-actions/ssh-compute@v0
with:
instance_name: interactive-brokers-quant-instance
zone: us-east1-c
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
command: |
cd ${{ secrets.DEPLOY_PATH || '/home/zwlddx0815/ib-docker' }}
sudo git fetch --all
sudo git reset --hard origin/main
# Write environment configurations
echo "TWS_USERID='${{ secrets.TWS_USERID }}'" > .env
echo "TWS_PASSWORD='${{ secrets.TWS_PASSWORD }}'" >> .env
echo "TOTP_SECRET='${{ secrets.TOTP_SECRET }}'" >> .env
echo "VNC_SERVER_PASSWORD='${{ secrets.VNC_SERVER_PASSWORD }}'" >> .env
echo "TRADING_MODE='${{ secrets.TRADING_MODE }}'" >> .env
# Build image (cached after first build, fast on subsequent runs)
sudo docker compose build
# Restart containers
sudo docker compose down
sudo docker compose up -d
# Wait for the container to stabilize
echo "Waiting for container to stabilize..."
sleep 30
# --- Start Bot and ensure it runs as a daemon ---
# 1. Kill any existing bot processes to avoid conflicts
sudo docker exec ib-gateway pkill -f 2fa_bot.py || true
# 2. Start the bot using nohup for background persistence
sudo docker exec -d ib-gateway bash -c "nohup python3 /home/ibgateway/2fa_bot.py > /home/ibgateway/2fa.log 2>&1 &"
# 3. Verify bot started successfully
sleep 5
sudo docker exec ib-gateway pgrep -f 2fa_bot.py && echo "✅ Bot started successfully." || echo "⚠️ Warning: Bot may not have started, check logs."
echo "✅ Deployment complete. Bot is monitoring the login window."
echo "Run 'docker exec ib-gateway tail -f /home/ibgateway/2fa.log' for real-time status."