50 lines
1.7 KiB
YAML
50 lines
1.7 KiB
YAML
name: Deploy Bot on NAS
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, dev ]
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Install dependencies
|
|
run: apk add --no-cache rsync openssh-client
|
|
|
|
- name: Checkout
|
|
run: |
|
|
git clone --depth 1 --branch ${{ github.ref_name }} \
|
|
${{ github.server_url }}/${{ github.repository }}.git .
|
|
|
|
- name: Set deployment path
|
|
run: |
|
|
if [ "${{ github.ref_name }}" = "main" ]; then
|
|
echo "DEPLOY_PATH=/share/CACHEDEV1_DATA/discord-bot-prod" >> $GITHUB_ENV
|
|
elif [ "${{ github.ref_name }}" = "dev" ]; then
|
|
echo "DEPLOY_PATH=/share/CACHEDEV1_DATA/discord-bot-dev" >> $GITHUB_ENV
|
|
else
|
|
echo "Unsupported branch" && exit 1
|
|
fi
|
|
|
|
- name: Configure SSH
|
|
run: |
|
|
mkdir -p /root/.ssh
|
|
echo "${{ secrets.NAS_SSH_KEY }}" > /root/.ssh/id_deploy
|
|
chmod 600 /root/.ssh/id_deploy
|
|
|
|
- name: Sync files to NAS
|
|
run: |
|
|
rsync -av --delete \
|
|
-e "ssh -i /root/.ssh/id_deploy -o StrictHostKeyChecking=no" \
|
|
--exclude='.git' \
|
|
--exclude='.env' \
|
|
--exclude='data/' \
|
|
--exclude='screenshots/' \
|
|
--exclude='logs/' \
|
|
./ Elewyn@192.168.1.208:${{ env.DEPLOY_PATH }}/
|
|
|
|
- name: Restart bot on NAS
|
|
run: |
|
|
ssh -i /root/.ssh/id_deploy -o StrictHostKeyChecking=no \
|
|
Elewyn@192.168.1.208 \
|
|
"cd ${{ env.DEPLOY_PATH }} && /share/CACHEDEV1_DATA/.qpkg/container-station/usr/bin/docker compose down || true && /share/CACHEDEV1_DATA/.qpkg/container-station/usr/bin/docker compose up --build -d"
|