-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (48 loc) · 1.84 KB
/
Copy pathDockerfile
File metadata and controls
64 lines (48 loc) · 1.84 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
60
61
62
63
64
# ==============================================
# マルチステージビルド:Next.js standalone
# ==============================================
# ── ベースイメージ ──
FROM node:26-alpine AS base
RUN npm install -g pnpm@11.8.0
# ── 依存関係インストール ──
FROM base AS deps
WORKDIR /app
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile
# ── アプリケーションビルド ──
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# ビルド時に必要な環境変数を設定
# NEXT_PUBLIC_ 変数はクライアントバンドルへ埋め込まれる
# MONGO_URI はビルド時に必要(MongoDB 接続確認のため)
ARG NEXT_PUBLIC_API_URL=http://localhost:3000/carshare-viewer
ARG MONGO_URI=mongodb://db:27017/
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
ENV MONGO_URI=${MONGO_URI}
RUN pnpm build
# ── 実行ステージ ──
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# scripts を含める(Node.js スクリプトとして実行)
COPY scripts ./scripts
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
# node_modules も必要な場合がある(scripts 内で tsx や依存を使用するため)
COPY --from=deps /app/node_modules ./node_modules
COPY package.json tsconfig.json ./
# standalone 出力・静的ファイル・公開アセットをコピー
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
RUN mkdir -p /app/crontabs && \
chmod +x /usr/local/bin/entrypoint.sh && \
chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME=0.0.0.0
CMD ["/usr/local/bin/entrypoint.sh"]