From b9d75ce9a058eb2a80854f595cb19d681cb5d3ce Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Tue, 19 May 2026 15:52:47 +0700 Subject: [PATCH] refactor: update deployment process to use git clone for VPS --- .github/workflows/deploy.yml | 43 +++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 96fc7ee..d44c8a5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -21,6 +21,7 @@ jobs: VPS_USERNAME: ${{ secrets.VPS_USERNAME }} VPS_SSH_KEY: ${{ secrets.VPS_SSH_KEY }} ENV_FILE: ${{ secrets.ENV_FILE }} + REPO_URL: ${{ github.server_url }}/${{ github.repository }}.git run: | # 1. Setup SSH Key mkdir -p ~/.ssh @@ -28,31 +29,33 @@ jobs: chmod 600 ~/.ssh/id_ed25519 ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts - # 2. Ensure target directory exists on VPS - ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no "$VPS_USERNAME@$VPS_HOST" "mkdir -p /opt/imphenbot" - - # 3. Rsync codebase (differential transfer) - rsync -e "ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no" -avz \ - --exclude='node_modules' \ - --exclude='.git' \ - --exclude='.github' \ - --exclude='recordings' \ - --exclude='dist' \ - --exclude='.env' \ - --exclude='*.db' \ - --exclude='*.db-shm' \ - --exclude='*.db-wal' \ - --exclude='test_out.nut' \ - ./ "$VPS_USERNAME@$VPS_HOST:/opt/imphenbot/" - - # 4. Inject Environment Variables and Build/Restart Containers + # 2. Deploy using git clone and docker ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no "$VPS_USERNAME@$VPS_HOST" " - cd /opt/imphenbot || exit + set -e + APP_DIR=/opt/imphenbot + + # Clone or update repository + if [ -d \"\$APP_DIR/.git\" ]; then + echo 'Repository exists, pulling latest changes...' + cd \$APP_DIR + git fetch origin master + git reset --hard origin/master + else + echo 'Cloning repository...' + mkdir -p \$APP_DIR + git clone -b master --depth 1 $REPO_URL \$APP_DIR + cd \$APP_DIR + fi + + # Inject environment variables echo \"$ENV_FILE\" > .env - # Build and restart containers using available docker compose command + + # Build and start containers with docker compose if command -v docker-compose &> /dev/null; then + docker-compose down || true docker-compose up -d --build else + docker compose down || true docker compose up -d --build fi "