-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.node
More file actions
59 lines (44 loc) · 1.68 KB
/
Copy pathDockerfile.node
File metadata and controls
59 lines (44 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# ビルドステージ
FROM node:22-alpine AS builder
WORKDIR /app
# package*.jsonをコピー(package-lock.jsonも含む)
COPY package*.json ./
# 全ての依存関係をインストール(devDependenciesを含む)
RUN npm ci || npm install
# アプリケーションのソースをコピー
COPY . .
# フレームワーク検出とビルド
RUN if [ -f package.json ]; then \
if grep -q '"next"' package.json; then \
echo "Building Next.js app..." && npm run build; \
elif grep -q '"@react-router/dev"' package.json || grep -q '"react-router"' package.json; then \
echo "Building React Router app..." && npm run build; \
else \
echo "Building HonoX app..." && npm run build; \
fi \
fi
# 存在しないディレクトリを作成(COPYエラーを防ぐため)
RUN mkdir -p dist .next build public
# 実行ステージ
FROM node:22-alpine
WORKDIR /app
# package*.jsonをコピー
COPY package*.json ./
# 本番用の依存関係のみインストール
RUN npm ci --only=production || npm install --production
# フレームワーク別の成果物をコピー
# 全てのフレームワークのビルド成果物をコピー(ビルダーステージですべて作成済み)
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/build ./build
COPY --from=builder /app/public ./public
# ビルド時引数でポートを受け取る
ARG PORT=3000
# 環境変数
ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV PORT=$PORT
# ポートを公開(デフォルト3000、ビルド時に変更可能)
EXPOSE $PORT
# すべてのフレームワークで npm start を使用
CMD ["npm", "start"]