-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (101 loc) · 4.06 KB
/
Copy pathdeploy.yml
File metadata and controls
121 lines (101 loc) · 4.06 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: Deploy Production
on:
push:
branches: [ "main" ]
env:
BINARY_NAME: server
jobs:
build_and_deploy:
name: Build & Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# This fixes the "pkg-config" error for the frontend build on the host runner.
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libssl-dev
# FRONTEND BUILD (Leptos)
- name: Install Rust Toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown, x86_64-unknown-linux-musl
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
- name: Install Trunk
uses: jetli/trunk-action@v0.4.0
- name: Build Frontend
working-directory: ./client
env:
API_URL: "https://trycli.com"
WS_URL: "wss://trycli.com"
run: trunk build --release
# BACKEND BUILD (Axum)
- name: Install Cross
uses: taiki-e/install-action@cross
- name: Build Backend (Static Binary)
# ⚠️ CHANGE: Run from root to ensure workspace lockfile is respected
# and point to the server binary explicitly.
env:
SQLX_OFFLINE: true # <--- ADD THIS LINE
run: cross build --release --target x86_64-unknown-linux-musl --bin server
# DEPLOYMENT
- name: Prepare Deployment Package
run: |
mkdir deploy_package
# ⚠️ FIX: Path is now 'target/...' not 'server/target/...'
cp target/x86_64-unknown-linux-musl/release/${{ env.BINARY_NAME }} deploy_package/server_bin
# Frontend 'dist' is still inside client/ because trunk ran there
cp -r client/dist deploy_package/dist
- name: Deploy to Azure VM
id: deploy_scp_primary
continue-on-error: true
uses: appleboy/scp-action@master
with:
host: ${{ secrets.VPS_HOST }}
port: ${{ secrets.VPS_PORT || 22 }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "deploy_package/*"
target: "/home/trycliuser/deploy_tmp"
strip_components: 1
timeout: 120s
- name: Retry Deploy to Azure VM
if: steps.deploy_scp_primary.outcome == 'failure'
uses: appleboy/scp-action@master
with:
host: ${{ secrets.VPS_HOST }}
port: ${{ secrets.VPS_PORT || 22 }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "deploy_package/*"
target: "/home/trycliuser/deploy_tmp"
strip_components: 1
timeout: 120s
- name: Restart Application
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VPS_HOST }}
port: ${{ secrets.VPS_PORT || 22 }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
# 1. Update Backend Binary
mkdir -p /home/trycliuser/trycli/target/release
cp /home/trycliuser/deploy_tmp/server_bin /home/trycliuser/trycli/target/release/server
chmod +x /home/trycliuser/trycli/target/release/server
# 2. Update Frontend Files
mkdir -p /home/trycliuser/trycli/client/dist
rm -rf /home/trycliuser/trycli/client/dist/*
cp -r /home/trycliuser/deploy_tmp/dist/* /home/trycliuser/trycli/client/dist/
# 3. Inject Environment Variables from GitHub Secrets
cat << EOF > /home/trycliuser/trycli/server/.env
DATABASE_URL=${{ secrets.DATABASE_URL }}
GITHUB_CLIENT_ID=${{ secrets.OAUTH_CLIENT_ID }}
GITHUB_CLIENT_SECRET=${{ secrets.OAUTH_CLIENT_SECRET }}
API_URL=https://trycli.com
FRONTEND_URL=https://trycli.com
EOF
chmod 600 /home/trycliuser/trycli/server/.env
# 4. Restart Backend Service
sudo systemctl restart trycli