lysine commited on
Commit
e8fab4b
·
1 Parent(s): 66dcdd2

Enable clustering

Browse files
Files changed (3) hide show
  1. Dockerfile +5 -1
  2. processes.json +8 -0
  3. src/server.ts +3 -1
Dockerfile CHANGED
@@ -3,6 +3,9 @@ FROM node:18
3
  # Set up a new user named "user" with user ID 1000
4
  RUN useradd -o -u 1000 user
5
 
 
 
 
6
  # Switch to the "user" user
7
  USER user
8
 
@@ -26,4 +29,5 @@ RUN cat .env
26
  RUN npm run build
27
 
28
  EXPOSE 7860
29
- CMD [ "npm", "run", "start" ]
 
 
3
  # Set up a new user named "user" with user ID 1000
4
  RUN useradd -o -u 1000 user
5
 
6
+ # Install pm2
7
+ RUN npm install pm2 -g
8
+
9
  # Switch to the "user" user
10
  USER user
11
 
 
29
  RUN npm run build
30
 
31
  EXPOSE 7860
32
+ # CMD [ "npm", "run", "start" ]
33
+ CMD ["pm2-runtime", "processes.json"]
processes.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "script": "dist/server.js",
4
+ "instances": "max",
5
+ "exec_mode": "cluster",
6
+ "node_args": "--experimental-specifier-resolution=node"
7
+ }
8
+ ]
src/server.ts CHANGED
@@ -37,5 +37,7 @@ app.get('*', (_req, res) => {
37
  });
38
 
39
  app.listen(PORT, () => {
40
- console.log(`Server listening at http://localhost:${PORT}`);
 
 
41
  });
 
37
  });
38
 
39
  app.listen(PORT, () => {
40
+ console.log(
41
+ `[${process.env.pm_id ?? ''}]Server listening at http://localhost:${PORT}`
42
+ );
43
  });