도커 파일 및 스크립트 파일 위치 정리
This commit is contained in:
24
docker/dev/backend.Dockerfile
Normal file
24
docker/dev/backend.Dockerfile
Normal file
@@ -0,0 +1,24 @@
|
||||
# 개발용 백엔드 Dockerfile
|
||||
FROM node:20-bookworm-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 시스템 패키지 설치
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends openssl ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# package.json 복사 및 의존성 설치 (개발 의존성 포함)
|
||||
COPY package*.json ./
|
||||
RUN npm ci --prefer-offline --no-audit
|
||||
|
||||
# 소스 코드는 볼륨 마운트로 처리
|
||||
# Prisma 클라이언트 생성용 스키마만 복사
|
||||
COPY prisma ./prisma
|
||||
RUN npx prisma generate
|
||||
|
||||
# 포트 노출
|
||||
EXPOSE 8080
|
||||
|
||||
# 개발 서버 시작 (nodemon 사용)
|
||||
CMD ["npm", "run", "dev"]
|
||||
34
docker/dev/docker-compose.backend.mac.yml
Normal file
34
docker/dev/docker-compose.backend.mac.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
services:
|
||||
# Node.js 백엔드
|
||||
backend:
|
||||
build:
|
||||
context: ../../backend-node
|
||||
dockerfile: ../docker/dev/backend.Dockerfile
|
||||
container_name: pms-backend-mac
|
||||
ports:
|
||||
- "8080:8080"
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
- PORT=8080
|
||||
- DATABASE_URL=postgresql://postgres:ph0909!!@39.117.244.52:11132/plm
|
||||
- JWT_SECRET=ilshin-plm-super-secret-jwt-key-2024
|
||||
- JWT_EXPIRES_IN=24h
|
||||
- CORS_ORIGIN=http://localhost:9771
|
||||
- CORS_CREDENTIALS=true
|
||||
- LOG_LEVEL=debug
|
||||
volumes:
|
||||
- ../../backend-node:/app # 개발 모드: 코드 변경 시 자동 반영
|
||||
- /app/node_modules
|
||||
networks:
|
||||
- pms-network
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 60s
|
||||
|
||||
networks:
|
||||
pms-network:
|
||||
driver: bridge
|
||||
22
docker/dev/docker-compose.frontend.mac.yml
Normal file
22
docker/dev/docker-compose.frontend.mac.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
services:
|
||||
# Next.js 프론트엔드만
|
||||
frontend:
|
||||
build:
|
||||
context: ../../frontend
|
||||
dockerfile: ../docker/dev/frontend.Dockerfile
|
||||
container_name: pms-frontend-mac
|
||||
ports:
|
||||
- "9771:3000"
|
||||
environment:
|
||||
- NEXT_PUBLIC_API_URL=http://localhost:8080/api
|
||||
volumes:
|
||||
- ../../frontend:/app
|
||||
- /app/node_modules
|
||||
- /app/.next
|
||||
networks:
|
||||
- pms-network
|
||||
restart: unless-stopped
|
||||
|
||||
networks:
|
||||
pms-network:
|
||||
driver: bridge
|
||||
20
docker/dev/frontend.Dockerfile
Normal file
20
docker/dev/frontend.Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
||||
# Node.js 18 기반 이미지 사용
|
||||
FROM node:18-alpine
|
||||
|
||||
# 작업 디렉토리 설정
|
||||
WORKDIR /app
|
||||
|
||||
# package.json과 package-lock.json 복사
|
||||
COPY package*.json ./
|
||||
|
||||
# 의존성 설치 (개발 의존성 포함) - 최적화 옵션 추가
|
||||
RUN npm ci --prefer-offline --no-audit
|
||||
|
||||
# 소스 코드 복사
|
||||
COPY . .
|
||||
|
||||
# 포트 노출
|
||||
EXPOSE 3000
|
||||
|
||||
# 개발 서버 시작
|
||||
CMD ["npm", "run", "dev"]
|
||||
51
docker/prod/backend.Dockerfile
Normal file
51
docker/prod/backend.Dockerfile
Normal file
@@ -0,0 +1,51 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
# Base image (Debian-based for glibc + OpenSSL compatibility)
|
||||
FROM node:20-bookworm-slim AS base
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
# Install OpenSSL and required certs
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends openssl ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Dependencies stage (install deps and generate Prisma client)
|
||||
FROM base AS deps
|
||||
COPY package*.json ./
|
||||
RUN npm ci --omit=dev --prefer-offline --no-audit && npm cache clean --force
|
||||
# Copy prisma schema and generate client (glibc target will be detected)
|
||||
COPY prisma ./prisma
|
||||
ENV PRISMA_SKIP_POSTINSTALL_GENERATE=true
|
||||
RUN npx prisma generate
|
||||
|
||||
# Build stage (compile TypeScript)
|
||||
FROM node:20-bookworm-slim AS build
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm ci --prefer-offline --no-audit && npm cache clean --force
|
||||
COPY tsconfig.json ./
|
||||
COPY src ./src
|
||||
COPY prisma ./prisma
|
||||
RUN npx prisma generate
|
||||
RUN npm run build
|
||||
|
||||
# Runtime image - base 이미지 재사용으로 중복 설치 제거
|
||||
FROM base AS runner
|
||||
ENV NODE_ENV=production
|
||||
|
||||
# Create non-root user
|
||||
RUN groupadd -r appgroup && useradd -r -g appgroup appuser
|
||||
|
||||
# Copy node_modules with generated Prisma client
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
# Copy built files
|
||||
COPY --from=build /app/dist ./dist
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
|
||||
# Create logs directory and set permissions
|
||||
RUN mkdir -p logs && chown -R appuser:appgroup logs && chmod -R 755 logs
|
||||
|
||||
EXPOSE 8080
|
||||
USER appuser
|
||||
CMD ["node", "dist/app.js"]
|
||||
32
docker/prod/docker-compose.backend.prod.yml
Normal file
32
docker/prod/docker-compose.backend.prod.yml
Normal file
@@ -0,0 +1,32 @@
|
||||
services:
|
||||
# Node.js 백엔드 (운영용)
|
||||
backend:
|
||||
build:
|
||||
context: ../../backend-node
|
||||
dockerfile: ../docker/prod/backend.Dockerfile # 운영용 Dockerfile
|
||||
container_name: pms-backend-prod
|
||||
ports:
|
||||
- "8080:8080"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- PORT=8080
|
||||
- DATABASE_URL=postgresql://postgres:ph0909!!@39.117.244.52:11132/plm
|
||||
- JWT_SECRET=ilshin-plm-super-secret-jwt-key-2024
|
||||
- JWT_EXPIRES_IN=24h
|
||||
- CORS_ORIGIN=http://localhost:9771
|
||||
- CORS_CREDENTIALS=true
|
||||
- LOG_LEVEL=info
|
||||
# 운영용에서는 볼륨 마운트 없음 (보안상 이유)
|
||||
networks:
|
||||
- pms-network
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 60s
|
||||
|
||||
networks:
|
||||
pms-network:
|
||||
driver: bridge
|
||||
25
docker/prod/docker-compose.frontend.prod.yml
Normal file
25
docker/prod/docker-compose.frontend.prod.yml
Normal file
@@ -0,0 +1,25 @@
|
||||
services:
|
||||
# Next.js 프론트엔드만
|
||||
frontend:
|
||||
build:
|
||||
context: ../../frontend
|
||||
dockerfile: ../docker/prod/frontend.Dockerfile
|
||||
args:
|
||||
- NEXT_PUBLIC_API_URL=http://192.168.0.70:8080/api
|
||||
container_name: pms-frontend-linux
|
||||
ports:
|
||||
- "5555:5555"
|
||||
environment:
|
||||
- NEXT_PUBLIC_API_URL=http://192.168.0.70:8080/api
|
||||
volumes:
|
||||
- ./frontend:/app
|
||||
- /app/node_modules
|
||||
- /app/.next
|
||||
networks:
|
||||
- pms-network
|
||||
restart: unless-stopped
|
||||
|
||||
networks:
|
||||
pms-network:
|
||||
driver: bridge
|
||||
external: true
|
||||
60
docker/prod/frontend.Dockerfile
Normal file
60
docker/prod/frontend.Dockerfile
Normal file
@@ -0,0 +1,60 @@
|
||||
# Multi-stage build for Next.js
|
||||
FROM node:18-alpine AS base
|
||||
|
||||
# curl 설치 (헬스체크용)
|
||||
RUN apk add --no-cache curl
|
||||
|
||||
# Install dependencies only when needed
|
||||
FROM base AS deps
|
||||
RUN apk add --no-cache libc6-compat
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
COPY package.json package-lock.json* ./
|
||||
RUN npm ci
|
||||
|
||||
# Rebuild the source code only when needed
|
||||
FROM base AS builder
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
# Disable telemetry during the build
|
||||
ENV NEXT_TELEMETRY_DISABLED 1
|
||||
|
||||
# Build the application
|
||||
ENV DISABLE_ESLINT_PLUGIN=true
|
||||
RUN npm run build
|
||||
|
||||
# Production image, copy all the files and run next
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV production
|
||||
ENV NEXT_TELEMETRY_DISABLED 1
|
||||
|
||||
# curl이 runner 스테이지에도 필요 (헬스체크용)
|
||||
RUN apk add --no-cache curl
|
||||
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
# Copy the Next.js build output
|
||||
COPY --from=builder /app/public ./public
|
||||
|
||||
# Production 모드에서는 .next 폴더 전체를 복사
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
|
||||
|
||||
# node_modules 복사 (production dependencies)
|
||||
COPY --from=deps --chown=nextjs:nodejs /app/node_modules ./node_modules
|
||||
|
||||
USER nextjs
|
||||
|
||||
EXPOSE 5555
|
||||
|
||||
ENV PORT 5555
|
||||
ENV HOSTNAME "0.0.0.0"
|
||||
|
||||
# Next.js start 명령어 사용
|
||||
CMD ["npm", "start"]
|
||||
Reference in New Issue
Block a user