refactor: update deployment process to use git clone for VPS
This commit is contained in:
@@ -21,6 +21,7 @@ jobs:
|
|||||||
VPS_USERNAME: ${{ secrets.VPS_USERNAME }}
|
VPS_USERNAME: ${{ secrets.VPS_USERNAME }}
|
||||||
VPS_SSH_KEY: ${{ secrets.VPS_SSH_KEY }}
|
VPS_SSH_KEY: ${{ secrets.VPS_SSH_KEY }}
|
||||||
ENV_FILE: ${{ secrets.ENV_FILE }}
|
ENV_FILE: ${{ secrets.ENV_FILE }}
|
||||||
|
REPO_URL: ${{ github.server_url }}/${{ github.repository }}.git
|
||||||
run: |
|
run: |
|
||||||
# 1. Setup SSH Key
|
# 1. Setup SSH Key
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
@@ -28,31 +29,33 @@ jobs:
|
|||||||
chmod 600 ~/.ssh/id_ed25519
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts
|
ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
# 2. Ensure target directory exists on VPS
|
# 2. Deploy using git clone and docker
|
||||||
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
|
|
||||||
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no "$VPS_USERNAME@$VPS_HOST" "
|
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
|
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
|
if command -v docker-compose &> /dev/null; then
|
||||||
|
docker-compose down || true
|
||||||
docker-compose up -d --build
|
docker-compose up -d --build
|
||||||
else
|
else
|
||||||
|
docker compose down || true
|
||||||
docker compose up -d --build
|
docker compose up -d --build
|
||||||
fi
|
fi
|
||||||
"
|
"
|
||||||
|
|||||||
Reference in New Issue
Block a user