-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (53 loc) · 1.9 KB
/
Copy pathnode.js.yml
File metadata and controls
69 lines (53 loc) · 1.9 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
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Node.js CI/CD
on:
push:
branches: ['main']
jobs:
# STEP 1: Build the app on GitHub's free, high-performance runners
build:
runs-on: ubuntu-latest # Uses GitHub cloud (7GB+ RAM), won't crash your EC2!
strategy:
matrix:
node-version: [22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
# Force Node to allocate enough memory for compilation on the cloud runner
- name: Compile TypeScript
run: npm run build --if-present
env:
NODE_OPTIONS: '--max-old-space-size=4096'
# Save the compiled dist files to pass to the next step
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: build-assets
path: dist/
# STEP 2: Safely deploy the pre-compiled code onto your EC2 instance
deploy:
needs: build
runs-on: self-hosted # Executes light deployment scripts on your EC2
steps:
- uses: actions/checkout@v4
- name: Download Build Artifacts
uses: actions/download-artifact@v4
with:
name: build-assets
path: dist/
- name: Production Dependencies Only
run: npm ci --omit=dev
- name: Inject Production Environment Variables
run: |
touch .env
echo "${{ secrets.PROD_ENV_FILE }}" > .env
- name: Restart PM2
run: pm2 reload eca-service --update-env
- name: Save PM2 Process List
run: pm2 save