-
Notifications
You must be signed in to change notification settings - Fork 1
127 lines (111 loc) · 5.13 KB
/
deploy.yml
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
122
123
124
125
126
127
name: Deploy Application
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: |
cd db
npm ci
cd ../backend
npm ci
cd ../frontend
npm ci
cd ../smartWalletTelBot
npm ci
- name: Create env files
run: |
echo "DATABASE_URL=${{ secrets.DB_URL }}" >> db/.env
echo "TEL_BOT_DATABASE_URL=${{ secrets.TEL_BOT_DATABASE_URL }}" >> db/.env
echo "VITE_BACKEND_URL=${{ secrets.VITE_BACKEND_URL }}" > frontend/.env
echo "VITE_TELEGRAM_BOT_SERVER_URL=${{ secrets.VITE_TELEGRAM_BOT_SERVER_URL }}" >> frontend/.env
echo "VITE_SMART_WALLET_AI_URL=${{ secrets.VITE_SMART_WALLET_AI_URL }}" >> frontend/.env
echo "FRONTEND_URL=${{ secrets.FRONTEND_URL }}" > backend/.env
echo "BOT_TOKEN=${{ secrets.BOT_TOKEN }}" > smartWalletTelBot/.env
echo "PROGRAM_ID=${{ secrets.PROGRAM_ID }}" >> smartWalletTelBot/.env
- name: Build applications
run: |
cd db
npm run generate
npm run build
cd ../backend
npm run build
cd ../frontend
npm run build
cd ../smartWalletTelBot
npm run build
- name: Setup SSH key
env:
PRIVATE_KEY: ${{ secrets.SERVER_SSH_PRIVATE_KEY }}
run: |
mkdir -p ~/.ssh
echo "$PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
- name: Deploy to server
env:
HOST: ${{ secrets.SERVER_HOST }}
USER: ${{ secrets.SERVER_USER }}
run: |
# Test SSH connection
ssh -v -o StrictHostKeyChecking=no $USER@$HOST echo "SSH connection successful"
# Deploy db files
ssh -o StrictHostKeyChecking=no $USER@$HOST 'mkdir -p /workplace/smart_wallet/db/dist'
scp -o StrictHostKeyChecking=no -r db/dist/* $USER@$HOST:/workplace/smart_wallet/db/dist/
scp -o StrictHostKeyChecking=no db/package.json db/package-lock.json $USER@$HOST:/workplace/smart_wallet/db/
scp -o StrictHostKeyChecking=no db/.env $USER@$HOST:/workplace/smart_wallet/db/
scp -o StrictHostKeyChecking=no -r db/prisma $USER@$HOST:/workplace/smart_wallet/db/
# Extract BOT_KEYPAIR from environment variable and write to bot_keypair.json
echo "${{ secrets.BOT_KEYPAIR }}" > smartWalletTelBot/bot_keypair.json
scp -o StrictHostKeyChecking=no smartWalletTelBot/bot_keypair.json $USER@$HOST:/workplace/smart_wallet/smartWalletTelBot/bot_keypair.json
# Deploy smartWalletTelBot files
ssh -o StrictHostKeyChecking=no $USER@$HOST 'mkdir -p /workplace/smart_wallet/smartWalletTelBot/dist'
scp -o StrictHostKeyChecking=no -r smartWalletTelBot/dist/* $USER@$HOST:/workplace/smart_wallet/smartWalletTelBot/dist/
scp -o StrictHostKeyChecking=no smartWalletTelBot/package.json smartWalletTelBot/package-lock.json $USER@$HOST:/workplace/smart_wallet/smartWalletTelBot/
scp -o StrictHostKeyChecking=no smartWalletTelBot/.env $USER@$HOST:/workplace/smart_wallet/smartWalletTelBot/
# Deploy backend files
ssh -o StrictHostKeyChecking=no $USER@$HOST 'mkdir -p /workplace/smart_wallet/backend/dist'
scp -o StrictHostKeyChecking=no -r backend/dist/* $USER@$HOST:/workplace/smart_wallet/backend/dist/
scp -o StrictHostKeyChecking=no backend/package.json backend/package-lock.json $USER@$HOST:/workplace/smart_wallet/backend/
scp -o StrictHostKeyChecking=no backend/.env $USER@$HOST:/workplace/smart_wallet/backend/
# Run Prisma migrations and restart backend
ssh -o StrictHostKeyChecking=no $USER@$HOST << 'EOF'
cd /workplace/smart_wallet/db
npm ci
# Generate Prisma client
npm run generate
# Run Prisma migrations
npm run migrate:smartwallet
npm run migrate:telbot
cd /workplace/smart_wallet/backend
npm install
# Install pm2 if not installed
if ! command -v pm2 &> /dev/null
then
echo "pm2 could not be found, installing globally"
npm install -g pm2
fi
pm2 restart backend-app || pm2 start dist/index.js --name backend-app
cd /workplace/smart_wallet/smartWalletTelBot
npm ci
pm2 restart smartWalletTelBot || pm2 start dist/index.js --name smartWalletTelBot
pm2 restart smartWalletTelBot-server || pm2 start dist/server.js --name smartWalletTelBot-server
EOF
# Deploy frontend files
scp -o StrictHostKeyChecking=no -r frontend/dist/* $USER@$HOST:/workplace/smart_wallet/frontend/
scp -o StrictHostKeyChecking=no frontend/.env $USER@$HOST:/workplace/smart_wallet/frontend/
- name: Clean up
run: |
rm db/.env frontend/.env backend/.env smartWalletTelBot/.env smartWalletTelBot/bot_keypair.json