Skip to content

Commit 48770a0

Browse files
committed
Add production deploy workflow and PM2 config
Introduce a GitHub Actions CD workflow (.github/workflows/cd_prod.yml) that runs tests on push to main and deploys to the production server (vlcdhprdp01). The workflow sets up Node.js, caches npm, runs tests, then checks out the repo on the target host, ensures log files exist, pulls latest code, installs deps, manages the app with PM2, and performs a health check. Add ecosystem.config.js with a PM2 app definition for 'inbox' including development and production environment variables (production MongoDB URL and other settings).
1 parent 74cdf49 commit 48770a0

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

.github/workflows/cd_prod.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Deploy Inbox to Production
2+
on:
3+
push:
4+
branches: main
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
environment: production
9+
steps:
10+
- uses: actions/checkout@master
11+
- name: Setup Node.js
12+
uses: actions/setup-node@master
13+
with:
14+
node-version: "24"
15+
- name: Cache node modules
16+
uses: actions/cache@master
17+
with:
18+
path: ~/.npm
19+
key: ${{ runner.os }}-build-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
20+
restore-keys: |
21+
${{ runner.os }}-build-cache-node-modules-
22+
${{ runner.os }}-build-
23+
${{ runner.os }}-
24+
- name: Install dependencies and run tests
25+
run: |
26+
npm install
27+
npm test
28+
29+
deploy:
30+
needs: test
31+
environment: production
32+
strategy:
33+
matrix:
34+
machines:
35+
- vlcdhprdp01
36+
runs-on: ${{ matrix.machines }}
37+
steps:
38+
- uses: actions/checkout@master
39+
- name: Deploy the app on the server
40+
run: |
41+
if [[ ! -e /srv/node/logs/inbox.txt ]]; then
42+
mkdir -p /srv/node/logs
43+
touch /srv/node/logs/inbox.txt
44+
fi
45+
cd /srv/node/inbox/
46+
pm2 delete inbox || true
47+
git stash
48+
git checkout main
49+
git pull
50+
npm install
51+
pm2 start ecosystem.config.js --env production --cwd .
52+
- name: Wait for service to be ready
53+
run: sleep 5
54+
- name: Run health check
55+
run: |
56+
curl -f http://localhost:3000/health || exit 1

ecosystem.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export default {
2+
apps: [
3+
{
4+
name: 'inbox',
5+
script: './server.js',
6+
instances: 1,
7+
autorestart: true,
8+
watch: false,
9+
max_memory_restart: '1G',
10+
env: {
11+
NODE_ENV: 'development',
12+
PORT: 3000,
13+
MONGODB_URL: 'mongodb://localhost:27017/inbox',
14+
MONGODB_COLLECTION: 'messages',
15+
ID_ROOT: 'http://inbox.rerum.io'
16+
},
17+
env_production: {
18+
NODE_ENV: 'production',
19+
PORT: 3000,
20+
MONGODB_URL: 'mongodb://vlcdhimgp01:27017/inbox?readPreference=primary&appname=MongoDB%20Compass&ssl=false',
21+
MONGODB_COLLECTION: 'messages',
22+
ID_ROOT: 'http://inbox.rerum.io'
23+
}
24+
}
25+
]
26+
}

0 commit comments

Comments
 (0)