Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 48 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
FROM node:22.12.0-alpine3.19 AS builder
## exmaple: https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
FROM node:22.12.0-alpine3.19 AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

COPY package*.json ./
# set mirror for npm
# RUN npm config set registry https://registry.npmmirror.com

# RUN apt-get update && apt-get install -y python3 python3-pip build-essential
# RUN ln -s /usr/bin/python3 /usr/bin/python

RUN npm ci
# Install dependencies based on the preferred package manager
COPY ./package*.json ./
RUN npm install

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY ./ .

COPY . .
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED=1

RUN npm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED=1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# 使用轻量级的 Node.js 镜像
FROM node:22.12.0-alpine3.19 AS runner
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

# 设置工作目录
WORKDIR /app
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

# 复制构建好的文件
COPY --from=builder /app ./
USER nextjs

# 暴露应用运行的端口
EXPOSE 3000

# 启动应用
CMD ["npm", "start"]
ENV PORT=3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]
12 changes: 0 additions & 12 deletions app/lib/db.ts

This file was deleted.

2 changes: 2 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// next.config.mjs
export default {
output: "standalone",
reactStrictMode: true,
async redirects() {
return [
{
Expand Down
14 changes: 5 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@
"@fortawesome/react-fontawesome": "^0.2.2",
"@heroicons/react": "^2.2.0",
"@tailwindcss/forms": "^0.5.7",
"@vercel/postgres": "^0.10.0",
"antd": "^5.22.3",
"antd": "^5.22.4",
"autoprefixer": "10.4.20",
"bcrypt": "^5.1.1",
"clsx": "^2.1.1",
"d3": "^7.9.0",
"next": "^15.0.4",
"next-auth": "4.24.10",
"pg": "^8.12.0",
"next": "^15.1.0",
"next-auth": "4.24.11",
"postcss": "8.4.49",
"react": "18.3.1",
"react-dom": "18.3.1",
"tailwindcss": "3.4.16",
"typescript": "5.7.2",
"use-debounce": "^10.0.1",
"zod": "^3.23.8"
"use-debounce": "^10.0.1"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",
Expand All @@ -35,7 +31,7 @@
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"eslint": "9.16.0",
"eslint-config-next": "^15.0.4"
"eslint-config-next": "^15.1.0"
},
"engines": {
"node": ">=20.12.0"
Expand Down
Loading