From 19d25e5528963ad970839350e5ef952fad284709 Mon Sep 17 00:00:00 2001 From: shuim Date: Sat, 19 Sep 2026 23:57:21 +0900 Subject: [PATCH] =?UTF-8?q?perf:=20NAS=20=EB=8F=84=EC=BB=A4=20=EB=B9=8C?= =?UTF-8?q?=EB=93=9C=20=EC=8B=9C=EA=B0=84=20=EB=8B=A8=EC=B6=95=20=E2=80=94?= =?UTF-8?q?=20CPU=20=EC=A0=84=EC=9A=A9=20torch=20+=20=EB=B9=8C=EB=93=9C=20?= =?UTF-8?q?=EC=BA=90=EC=8B=9C=20=EB=A7=88=EC=9A=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DS1517+(Atom C2538)에서 빌드가 30분 이상 걸리던 원인 두 가지를 제거. 1. PyTorch CPU 전용 휠 사용 (backend) PyPI 기본 torch 휠은 nvidia-cublas/cudnn 등 CUDA 패키지를 수 GB 함께 내려받는데 NAS에는 GPU가 없어 전부 불필요했다. download.pytorch.org/whl/cpu 에서 먼저 설치하면 requirements.txt 의 torch 줄은 충족되어 건너뛴다. ml_ensemble 은 이미 지연 임포트라 동작 동일. 2. pip/npm 캐시를 빌드 간 재사용 (backend, mcp-server, frontend) --no-cache-dir 제거하고 RUN --mount=type=cache 로 전환. requirements.txt 가 바뀌어도 받아둔 휠은 재다운로드하지 않는다. Jenkinsfile 에 DOCKER_BUILDKIT/COMPOSE_DOCKER_CLI_BUILD 추가. 부수: frontend Dockerfile 의 FromAsCasing 경고 정리 (as build → AS build). 세 Dockerfile 모두 docker build --check 통과. Co-Authored-By: Claude Opus 5 --- .claude/settings.local.json | 5 ++++- Jenkinsfile | 3 +++ backend/Dockerfile | 13 ++++++++++++- frontend/Dockerfile | 8 +++++--- mcp-server/Dockerfile | 6 ++++-- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.claude/settings.local.json b/.claude/settings.local.json index c43e5c7..bfc00ac 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -176,7 +176,10 @@ "Bash(/usr/bin/head -c 300 /tmp/stock.html)", "Bash(/usr/bin/curl -sk -o /dev/null -w \" /api/v1/market-data/prices → HTTP %{http_code}\\\\n\" --max-time 10 \"https://stock.shium.net/api/v1/market-data/prices?codes=005930\")", "Bash(/usr/bin/tail -5)", - "Bash(/usr/bin/head -2)" + "Bash(/usr/bin/head -2)", + "Bash(/usr/bin/cat backend/Dockerfile)", + "Bash(/usr/bin/cat backend/requirements.txt)", + "Bash(docker --version)" ] }, "enableAllProjectMcpServers": true, diff --git a/Jenkinsfile b/Jenkinsfile index ad116c1..3995d30 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,6 +4,9 @@ pipeline { environment { DEPLOY_DIR = '/volume1/docker/autostock' ENV_FILE = "${DEPLOY_DIR}/.env" + // Dockerfile 의 pip/npm 캐시 마운트(RUN --mount=type=cache)를 쓰려면 BuildKit 필요 + DOCKER_BUILDKIT = '1' + COMPOSE_DOCKER_CLI_BUILD = '1' } options { diff --git a/backend/Dockerfile b/backend/Dockerfile index a2523d6..9db07e7 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1 FROM python:3.11-slim WORKDIR /app @@ -13,7 +14,17 @@ RUN apt-get update && apt-get install -y \ # Python 의존성 설치 (requirements.txt 변경 시에만 재설치 — Docker 캐시 활용) COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt + +# PyTorch는 CPU 전용 휠로 먼저 설치. +# PyPI 기본 torch 휠은 NVIDIA CUDA 패키지(nvidia-cublas, nvidia-cudnn 등)를 +# 수 GB 함께 내려받지만 NAS에 GPU가 없어 전부 불필요하다. +# 여기서 먼저 깔아두면 아래 requirements.txt 의 torch 줄은 이미 충족되어 건너뛴다. +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install torch --index-url https://download.pytorch.org/whl/cpu + +# 나머지 의존성 — pip 캐시를 빌드 간 재사용 (BuildKit 필요) +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install -r requirements.txt # 애플리케이션 코드 복사 (코드 변경 시에만 이 레이어 갱신) COPY . . diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 3afa6da..75ac597 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,11 +1,13 @@ +# syntax=docker/dockerfile:1 # Build stage -FROM node:20-alpine as build +FROM node:20-alpine AS build WORKDIR /app -# 의존성 설치 +# 의존성 설치 — npm 캐시를 빌드 간 재사용 (BuildKit 필요) COPY package*.json ./ -RUN npm install +RUN --mount=type=cache,target=/root/.npm \ + npm install # 애플리케이션 빌드 COPY . . diff --git a/mcp-server/Dockerfile b/mcp-server/Dockerfile index 8979d6a..791eb6c 100644 --- a/mcp-server/Dockerfile +++ b/mcp-server/Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1 FROM python:3.11-slim WORKDIR /app @@ -9,9 +10,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certifi && npm install -g @anthropic-ai/claude-code \ && apt-get purge -y curl && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* -# Python 의존성 설치 +# Python 의존성 설치 — pip 캐시를 빌드 간 재사용 (BuildKit 필요) COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install -r requirements.txt # 애플리케이션 코드 복사 COPY . .