From 9aa2859452baade90a46e1557a9883e7667c080f Mon Sep 17 00:00:00 2001 From: enitrat Date: Thu, 16 Oct 2025 13:14:14 +0800 Subject: [PATCH] fix: remove reliance on .env in docker image --- .dockerignore | 1 + ingester.dockerfile | 2 -- ingesters/src/config/settings.ts | 9 ++++++++- ingesters/src/utils/paths.ts | 12 +++++------- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.dockerignore b/.dockerignore index cf709889..7b7127c9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ **/node_modules +.env diff --git a/ingester.dockerfile b/ingester.dockerfile index a0b524a3..ecbc5d6d 100644 --- a/ingester.dockerfile +++ b/ingester.dockerfile @@ -14,8 +14,6 @@ WORKDIR /app # Copy ingester files COPY ingesters ./ingesters -# Copy .env file for configuration -COPY .env ./.env # Copy ingester files generated from python COPY python/src/scripts/summarizer/generated ./python/src/scripts/summarizer/generated diff --git a/ingesters/src/config/settings.ts b/ingesters/src/config/settings.ts index 96a5aece..9d04d6f0 100644 --- a/ingesters/src/config/settings.ts +++ b/ingesters/src/config/settings.ts @@ -1,8 +1,15 @@ import { type VectorStoreConfig } from '../types'; import dotenv from 'dotenv'; import { getRepoPath } from '../utils/paths'; +import { existsSync } from 'fs'; -dotenv.config({ path: getRepoPath('.env') }); +// Load .env from repo root if present; otherwise rely on runtime env vars. +const envPath = getRepoPath('.env'); +if (existsSync(envPath)) { + dotenv.config({ path: envPath }); +} else { + dotenv.config(); +} // API Keys from environment variables only export const getOpenaiApiKey = () => process.env.OPENAI_API_KEY; diff --git a/ingesters/src/utils/paths.ts b/ingesters/src/utils/paths.ts index 5ac591d3..0d8212f8 100644 --- a/ingesters/src/utils/paths.ts +++ b/ingesters/src/utils/paths.ts @@ -2,18 +2,16 @@ import path from 'path'; import { existsSync } from 'fs'; /** - * Find the repository root by looking for .git directory + * Find the repository root by looking for package.json and going up the directory tree */ function findRepoRoot(): string { let currentDir = import.meta.dir; // Bun's way to get current directory - // Walk up the directory tree looking for .env + // Walk up the directory tree looking for package.json while (currentDir !== '/') { - if ( - existsSync(path.join(currentDir, '.env')) || - existsSync(path.join(currentDir, '.git')) - ) { - return currentDir; + if (existsSync(path.join(currentDir, 'package.json'))) { + // Go one level up from the package.json location + return path.dirname(currentDir); } currentDir = path.dirname(currentDir); }