125 lines
No EOL
4 KiB
YAML
125 lines
No EOL
4 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
|
|
container: ghcr.io/cirruslabs/flutter:3.35.5
|
|
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 52428800
|
|
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 jq git
|
|
|
|
- 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: Setup Swap
|
|
run: |
|
|
SWAP_SIZE=2048 # 2GB
|
|
CURRENT_SWAP=$(free -m | awk '/^Swap:/ {print $2}' || echo "0")
|
|
|
|
if [ "$CURRENT_SWAP" -lt "$SWAP_SIZE" ]; then
|
|
echo "Creating ${SWAP_SIZE}MB swap file..."
|
|
dd if=/dev/zero of=/tmp/swapfile bs=1M count=$SWAP_SIZE status=progress
|
|
chmod 600 /tmp/swapfile
|
|
mkswap /tmp/swapfile
|
|
swapon /tmp/swapfile
|
|
echo "Swap activated: $(free -m | awk '/^Swap:/ {print $2}')MB"
|
|
else
|
|
echo "Swap already available: ${CURRENT_SWAP}MB"
|
|
fi
|
|
|
|
- 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: Remove Swap
|
|
if: always()
|
|
run: |
|
|
if [ -f /tmp/swapfile ]; then
|
|
echo "Removing swap file..."
|
|
swapoff /tmp/swapfile 2>/dev/null || true
|
|
rm -f /tmp/swapfile
|
|
echo "Swap removed"
|
|
fi
|
|
|
|
- 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" |