浏览代码

chore: add config to run production locally

Nicolas Meienberger 1 年之前
父节点
当前提交
4e98f1e294
共有 5 个文件被更改,包括 9 次插入5 次删除
  1. 0 1
      Dockerfile
  2. 4 0
      docker-compose.prod.yml
  3. 1 1
      package.json
  4. 3 0
      src/server/core/Logger/Logger.ts
  5. 1 3
      src/server/core/TipiConfig/TipiConfig.ts

+ 0 - 1
Dockerfile

@@ -26,7 +26,6 @@ COPY ./tsconfig.json ./tsconfig.json
 COPY ./next.config.mjs ./next.config.mjs
 COPY ./public ./public
 COPY ./tests ./tests
-COPY ./.env.example ./.env
 
 RUN npm run build
 

+ 4 - 0
docker-compose.prod.yml

@@ -85,6 +85,10 @@ services:
       traefik.enable: true
       traefik.http.services.dashboard.loadbalancer.server.port: 3000
       traefik.http.middlewares.redirect-to-https.redirectscheme.scheme: https
+      # Local ip
+      traefik.http.routers.dashboard.rule: PathPrefix("/")
+      traefik.http.routers.dashboard.service: dashboard
+      traefik.http.routers.dashboard.entrypoints: web
       # Local domain
       traefik.http.routers.dashboard-local-insecure.rule: Host(`${LOCAL_DOMAIN}`)
       traefik.http.routers.dashboard-local-insecure.entrypoints: web

+ 1 - 1
package.json

@@ -21,7 +21,7 @@
     "start:dev-container": "./.devcontainer/filewatcher.sh && npm run start:dev",
     "start:rc": "docker compose -f docker-compose.rc.yml --env-file .env up --build",
     "start:dev": "npm run prepare && docker compose -f docker-compose.dev.yml up --build",
-    "start:prod": "npm run prepare && docker compose -f docker-compose.prod.yml up --build",
+    "start:prod": "npm run prepare && docker compose --env-file ./.env -f docker-compose.prod.yml up --build",
     "start:pg": "docker run --name test-db -p 5433:5432 -d --rm -e POSTGRES_PASSWORD=postgres postgres:14",
     "version": "echo $npm_package_version",
     "release:rc": "./scripts/deploy/release-rc.sh",

+ 3 - 0
src/server/core/Logger/Logger.ts

@@ -42,6 +42,9 @@ const productionLogger = () => {
         new transports.File({
           filename: path.join(logsFolder, 'app.log'),
         }),
+        new transports.Console({
+          level: 'info',
+        }),
       ],
       exceptionHandlers: [new transports.File({ filename: path.join(logsFolder, 'error.log') })],
     });

+ 1 - 3
src/server/core/TipiConfig/TipiConfig.ts

@@ -16,7 +16,7 @@ const formatErrors = (errors: { fieldErrors: Record<string, string[]> }) =>
 export class TipiConfig {
   private static instance: TipiConfig;
 
-  private config: z.infer<typeof envSchema>;
+  private config: z.infer<typeof envSchema> = {} as z.infer<typeof envSchema>;
 
   constructor() {
     const conf = { ...process.env, ...nextConfig()?.serverRuntimeConfig };
@@ -55,12 +55,10 @@ export class TipiConfig {
       } else {
         const errors = formatErrors(parsedConfig.error.flatten());
         Logger.error(`❌ Invalid env config ${JSON.stringify(errors)}`);
-        throw new Error(`Invalid env config ${JSON.stringify(errors)}`);
       }
     } else {
       const errors = formatErrors(parsedFileConfig.error.flatten());
       Logger.error(`❌ Invalid settings.json file: ${JSON.stringify(errors)}`);
-      throw new Error('Invalid settings.json file');
     }
   }