mnemo_cards/.forgejo/workflows/deploy.yaml
2025-11-21 03:15:12 +03:00

119 lines
No EOL
3.8 KiB
YAML

name: Deploy Mnemo Cards
on:
workflow_dispatch:
push:
branches:
- master
paths:
- 'mnemo_cards_web_v2/**'
- 'mnemo_cards_backend/**'
- 'mnemo_cards_common/**'
- 'mnemo_cards_common_backend/**'
jobs:
deploy-backend:
name: Deploy Backend
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Dependencies
run: |
apt-get update && apt-get install -y rsync openssh-client
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Sync Source Code
run: |
# Sync common packages
rsync -avz --delete --exclude '.*' --exclude 'build' --exclude 'doc' \
mnemo_cards_common \
mnemo_cards_common_backend \
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:~/
# Sync backend project
rsync -avz --delete --exclude '.*' --exclude 'build' --exclude 'server.exe' --exclude 'isar' \
mnemo_cards_backend \
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:~/
# Sync build script
rsync -avz tools/deploy/backend/server_build.sh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:~/mnemo_cards_backend/
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "chmod +x ~/mnemo_cards_backend/server_build.sh"
- name: Trigger Remote Build
run: |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "~/mnemo_cards_backend/server_build.sh"
deploy-web:
name: Deploy Web App
runs-on: ubuntu-latest
needs: deploy-backend
if: always()
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
lfs: false
- name: Configure Git
run: |
git config --global http.postBuffer 524288000
git config --global http.maxRequestBuffer 100M
git config --global core.compression 0
- name: Create Swap File
run: |
fallocate -l 2G /swapfile || dd if=/dev/zero of=/swapfile bs=1M count=2048
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
swapon --show
- name: Install Dependencies
run: |
apt-get update && apt-get install -y rsync openssh-client jq git
- name: Install Flutter 3.35.5
run: |
if [ ! -d /opt/flutter/bin ]; then
echo "Flutter not found, cloning..."
git clone --branch 3.35.5 --depth 1 https://github.com/flutter/flutter.git /opt/flutter
else
echo "Flutter already present in /opt/flutter"
fi
echo "FLUTTER_ROOT=/opt/flutter" >> "$GITHUB_ENV"
echo "/opt/flutter/bin" >> "$GITHUB_PATH"
/opt/flutter/bin/flutter --version
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Build Web App
working-directory: mnemo_cards_web_v2
run: |
flutter pub get
flutter build web --release \
--dart-define=API_BASE_URL=https://api.mnemo-cards.online \
--dart2js-optimization=O4
- name: Deploy Web App
run: |
rsync -avz --delete mnemo_cards_web_v2/build/web/ \
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/var/www/mnemo_cards/
- name: Fix Permissions
run: |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} \
"chown -R www-data:www-data /var/www/mnemo_cards && chmod -R 755 /var/www/mnemo_cards"