-
Notifications
You must be signed in to change notification settings - Fork 4
85 lines (70 loc) · 2.53 KB
/
Copy pathdeploy_frontend.yml
File metadata and controls
85 lines (70 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Build and Deploy Frontend
on:
push:
branches:
- main
- dev
workflow_dispatch:
concurrency:
group: deploy
cancel-in-progress: true
permissions:
contents: write
jobs:
deploy:
if: github.ref == 'refs/heads/main' || contains(github.event.head_commit.message, '[deploy]')
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- name: Checkout Source Code
uses: actions/checkout@v3
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install Packages
run: npm install
working-directory: frontend
- name: Build
env:
REACT_APP_DOMAIN: ${{ github.ref == 'refs/heads/main' && 'https://arena.xlang.ai' || 'https://arena-dev.xlang.ai' }}
run: CI=false npm run build
working-directory: frontend
- name: Upload to Server
uses: appleboy/scp-action@master
with:
host: ${{ github.ref == 'refs/heads/main' && secrets.SERVER_HOST || secrets.DEV_SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
source: 'frontend/build/.'
target: '~/agent_arena_frontend_temp'
strip_components: 2
- name: Deploy and Setup Permissions
uses: appleboy/ssh-action@master
with:
host: ${{ github.ref == 'refs/heads/main' && secrets.SERVER_HOST || secrets.DEV_SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
# Create backup
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/tmp/frontend_backup_${TIMESTAMP}"
sudo mkdir -p ${BACKUP_DIR}
sudo cp -r /var/www/html/* ${BACKUP_DIR}/ 2>/dev/null || true
# Deploy new version
sudo rm -rf /var/www/html/*
sudo mv ~/agent_arena_frontend_temp/* /var/www/html/
sudo rm -rf ~/agent_arena_frontend_temp
# Set permissions
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
# Verify deployment
if [ ! -f /var/www/html/index.html ]; then
echo "Deployment verification failed, rolling back..."
sudo rm -rf /var/www/html/*
sudo cp -r ${BACKUP_DIR}/* /var/www/html/
exit 1
fi