From 3defa9abd76999be4f45e408e0d888f753f75b33 Mon Sep 17 00:00:00 2001 From: Hyoseong Jo Date: Sun, 28 Dec 2025 14:55:00 +0900 Subject: [PATCH] =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 6 ------ Dockerfile | 8 +++++++- backend/utils/db.ts | 8 ++++++-- database/.gitkeep | 2 -- nuxt.config.ts | 21 +-------------------- 5 files changed, 14 insertions(+), 31 deletions(-) delete mode 100644 database/.gitkeep diff --git a/.gitignore b/.gitignore index 61bd091..48fcd8f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,13 +13,7 @@ node_modules logs *.log -# Database -database/*.db -database/*.db-shm -database/*.db-wal - # Misc .DS_Store .fleet .idea - diff --git a/Dockerfile b/Dockerfile index bb2fc8e..fd41506 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,8 @@ WORKDIR /app COPY package*.json ./ RUN npm ci COPY . . +# 운영 환경변수로 빌드 +COPY .env.prod .env RUN npm run build FROM node:20-alpine @@ -29,6 +31,9 @@ COPY --from=builder /app/.output /app/.output COPY --from=builder /app/package*.json /app/ RUN npm ci --omit=dev +# 운영 환경변수 복사 +COPY .env.prod /app/.env + # 비root 사용자 RUN addgroup -g 1001 -S nodejs \ && adduser -S nuxt -u 1001 -G nodejs \ @@ -40,4 +45,5 @@ EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1 -CMD ["node", ".output/server/index.mjs"] +# .env 로드 후 실행 +CMD ["sh", "-c", "export $(grep -v '^#' .env | xargs) && node .output/server/index.mjs"] diff --git a/backend/utils/db.ts b/backend/utils/db.ts index 9048e4a..0617183 100644 --- a/backend/utils/db.ts +++ b/backend/utils/db.ts @@ -13,7 +13,7 @@ let pool: pg.Pool | null = null */ export function getPool(): pg.Pool { if (!pool) { - pool = new Pool({ + const config = { host: process.env.DB_HOST || 'localhost', port: parseInt(process.env.DB_PORT || '5432'), database: process.env.DB_NAME || 'osolit_monitor', @@ -22,7 +22,11 @@ export function getPool(): pg.Pool { max: 10, idleTimeoutMillis: 30000, connectionTimeoutMillis: 2000, - }) + } + + console.log(`[DB] Connecting to ${config.host}:${config.port}/${config.database}`) + + pool = new Pool(config) pool.on('error', (err) => { console.error('[DB] Unexpected pool error:', err) diff --git a/database/.gitkeep b/database/.gitkeep deleted file mode 100644 index 82a9dac..0000000 --- a/database/.gitkeep +++ /dev/null @@ -1,2 +0,0 @@ -# This file ensures the database directory is included in git -# The actual .db files are ignored in .gitignore diff --git a/nuxt.config.ts b/nuxt.config.ts index fbd4bd8..be08e85 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -43,44 +43,25 @@ export default defineNuxtConfig({ // 서버 설정 nitro: { preset: 'node-server', - // WebSocket 실험적 기능 활성화 experimental: { websocket: true }, - // 네이티브 모듈은 번들링하지 않고 외부 모듈로 처리 externals: { inline: [] }, - // rollup에서 external로 처리 rollupConfig: { external: ['pg'] }, - // 플러그인 등록 plugins: [ '~/backend/plugins/pubnet-init.ts', '~/backend/plugins/privnet-init.ts' ] }, - // Vite 설정 (네이티브 모듈) + // Vite 설정 vite: { optimizeDeps: { exclude: ['pg'] } - }, - - // 환경변수 설정 - runtimeConfig: { - // 서버 전용 (NUXT_로 시작하는 환경변수 자동 로드) - dbHost: process.env.DB_HOST || 'localhost', - dbPort: process.env.DB_PORT || '5432', - dbName: process.env.DB_NAME || 'osolit_monitor', - dbUser: process.env.DB_USER || 'postgres', - dbPassword: process.env.DB_PASSWORD || '', - autoStartScheduler: process.env.AUTO_START_SCHEDULER || 'false', - // 클라이언트 공개 - public: { - nodeEnv: process.env.NODE_ENV || 'development' - } } })