-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (92 loc) · 3.21 KB
/
build-and-deploy.yaml
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
name: Build and Deploy
on:
push:
branches:
- live
- main
- 'renovate/**'
jobs:
build:
name: Build
runs-on: ubuntu-latest
env:
NEXT_TELEMETRY_DISABLED: 1
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4
name: Setup NodeJS
with:
node-version-file: '.tool-versions'
- uses: pnpm/action-setup@d882d12c64e032187b2edb46d3a0d003b7a43598 # v2.4.0
name: Install pnpm
id: pnpm-install
with:
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
name: "Next JS Cache"
with:
path: |
~/.npm
${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- run: pnpm build
- run: |
mkdir dist
mkdir -p app/standalone/public
cp ./package.json app
cp -r .next/standalone app
cp .next/static app/standalone/.next/ -r
cp -r public/* app/standalone/public/
cp ecosystem.config.js app
tar -cJf dist/standalone-dist.tar.xz app
name: Create artifact
- name: Upload artifact
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4
with:
name: nodejs-app
path: ./dist/standalone-dist.tar.xz
retention-days: 3
deploy:
needs: 'build'
name: Deploy to server
if: github.ref == 'refs/heads/live'
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 # v4
with:
name: nodejs-app
- name: Copy artifact to the server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
source: "standalone-dist.tar.xz"
target: "/srv/http/pnf/"
- name: Setup Node JS
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
rm -rf app && tar --overwrite -xf standalone-dist.tar.xz
cd app && pm2 restart ecosystem.config.js