97 lines
3.2 KiB
YAML
97 lines
3.2 KiB
YAML
name: Deploy Mnemo Cards
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches:
|
|
- master
|
|
|
|
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() # Run even if backend fails (optional, but usually good to separate)
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0 # Fetch all history for all tags and branches
|
|
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: Install Dependencies
|
|
run: |
|
|
apt-get update && apt-get install -y rsync openssh-client
|
|
|
|
- name: Setup Flutter
|
|
uses: https://github.com/subosito/flutter-action@v2
|
|
with:
|
|
flutter-version: '3.19.2' # Adjust version as needed
|
|
channel: 'stable'
|
|
|
|
- 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
|
|
run: |
|
|
cd mnemo_cards_web_v2
|
|
flutter pub get
|
|
flutter build web --release --dart-define=API_BASE_URL=https://api.memo-cards.online:8444 --dart2js-optimization=O4
|
|
|
|
- name: Deploy Web App
|
|
run: |
|
|
# Sync build artifacts
|
|
rsync -avz --delete 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"
|