-
Notifications
You must be signed in to change notification settings - Fork 3
81 lines (72 loc) · 2.68 KB
/
deploy-frontend.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
name: Build and Deploy Nuxt Frontend
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16.20.2'
- name: Install dependencies
run: |
cd frontend
npm install
- name: Build Nuxt frontend
run: |
cd frontend
npm run build
- name: List build directory (for debugging)
run: |
ls -la frontend/.output
- name: Compress build artifacts
run: |
cd frontend
tar -czf nuxt-build.tar.gz .output
- name: List compressed file (for debugging)
run: |
ls -la frontend/nuxt-build.tar.gz
- name: Upload Nuxt build artifacts
uses: actions/upload-artifact@v3
with:
name: nuxt-build
path: frontend/nuxt-build.tar.gz
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download Nuxt build artifacts
uses: actions/download-artifact@v3
with:
name: nuxt-build
path: .
- name: Deploy Nuxt frontend
env:
SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_KEY }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
run: |
echo "$SSH_PRIVATE_KEY" > deploy_key
chmod 600 deploy_key
scp -o StrictHostKeyChecking=no -i deploy_key nuxt-build.tar.gz [email protected]:/tmp/nuxt-build.tar.gz || { echo 'SCP failed'; exit 1; }
ssh -o StrictHostKeyChecking=no -i deploy_key [email protected] '
export NVM_DIR="$HOME/.nvm" &&
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" &&
nvm use 16.20.2 &&
echo "$SSH_PASSWORD" | sudo -S mkdir -p /usr/share/nginx/html/ibminscut &&
echo "$SSH_PASSWORD" | sudo -S tar -xzf /tmp/nuxt-build.tar.gz -C /usr/share/nginx/html/ibminscut &&
echo "$SSH_PASSWORD" | sudo -S chown -R www-data:www-data /usr/share/nginx/html/ibminscut &&
echo "$SSH_PASSWORD" | sudo -S chmod -R 755 /usr/share/nginx/html/ibminscut &&
rm /tmp/nuxt-build.tar.gz &&
cd /usr/share/nginx/html/ibminscut/.output/server &&
echo "$SSH_PASSWORD" | sudo -S npm install --production &&
pm2 restart nuxt-app || pm2 start npm --name "nuxt-app" -- run start
' || { echo 'SSH command failed'; exit 1; }
rm deploy_key