Ver código fonte

feat: 支持 cicd

dbfu 5 dias atrás
pai
commit
95bdbef124
3 arquivos alterados com 304 adições e 779 exclusões
  1. 6 1
      Dockerfile
  2. 28 15
      main.js
  3. 270 763
      pnpm-lock.yaml

+ 6 - 1
Dockerfile

@@ -4,8 +4,12 @@ WORKDIR /app
 
 COPY pnpm-lock.yaml .
 COPY package.json .
+COPY .npmrc .
 
-RUN --mount=type=cache,target=/pnpm/store pnpm install
+RUN --mount=type=cache,target=/root/.pnpm-store \
+    pnpm config set store-dir /root/.pnpm-store && \
+    pnpm config set node-linker=isolated && \
+    pnpm install --production
 
 COPY . .
 
@@ -13,6 +17,7 @@ FROM registry.cn-hangzhou.aliyuncs.com/dbfu/pm2:latest
 
 WORKDIR /app
 
+
 COPY --from=builder /app/ ./
 ENV TZ="Asia/Shanghai"
 

+ 28 - 15
main.js

@@ -6,17 +6,29 @@ const fs = require('fs');
 const md5 = require('md5.js');
 
 async function initDatabase() {
-  const connection = await mysql2.createConnection({
-    host: config.DATABASE_HOST,
-    port: config.DATABASE_PORT,
-    user: config.DATABASE_USER,
-    password: config.DATABASE_PASSWORD,
-    multipleStatements: true,
-  });
 
   const dbName = config.DATABASE_NAME;
 
-  await connection.connect();
+  async function connectDB() {
+    try {
+      const connection = await mysql2.createConnection({
+        host: config.DATABASE_HOST,
+        port: config.DATABASE_PORT,
+        user: config.DATABASE_USER,
+        password: config.DATABASE_PASSWORD,
+        multipleStatements: true,
+      });
+
+      await connection.connect();
+
+      return connection;
+    } catch (error) {
+      console.log(error);
+      process.exit(1);
+    }
+  }
+
+  const connection = await connectDB();
 
   async function createUserIfNotExists() {
     await connection.query(`USE \`${dbName}\`;`);
@@ -80,13 +92,14 @@ async function initDatabase() {
   }
 }
 async function main() {
-
-  await initDatabase();
-
-
-  app.listen(SERVER_PORT, () => {
-    console.log(`Marsview服务已启动 ${SERVER_HOST}:${SERVER_PORT}`);
-  });
+  try {
+    await initDatabase();
+    app.listen(SERVER_PORT, () => {
+      console.log(`Marsview服务已启动 ${SERVER_HOST}:${SERVER_PORT}`);
+    });
+  } catch {
+    process.exit(1);
+  }
 }
 
 main();

Diferenças do arquivo suprimidas por serem muito extensas
+ 270 - 763
pnpm-lock.yaml


Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff