diff --git a/Dockerfile b/Dockerfile index b0a845f..88e4377 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file +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"] \ No newline at end of file diff --git a/app/lib/db.ts b/app/lib/db.ts deleted file mode 100644 index bf3a781..0000000 --- a/app/lib/db.ts +++ /dev/null @@ -1,12 +0,0 @@ -// app/lib/db.ts -import { Pool } from 'pg'; - -const pool = new Pool({ - user: 'mega', - host: '127.17.0.1', - database: 'cratespro', - password: 'mega', - port: 30432, -}); - -export default pool; diff --git a/next.config.mjs b/next.config.mjs index 32c05ad..9e01be7 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -2,6 +2,8 @@ // next.config.mjs export default { + output: "standalone", + reactStrictMode: true, async redirects() { return [ { diff --git a/package.json b/package.json index c65ce0b..7ffacb7 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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"