From e905e88d1d63a0fc1777a14cf47df2923d8aae96 Mon Sep 17 00:00:00 2001 From: luorijun Date: Mon, 21 Apr 2025 13:59:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20Dockerfile=EF=BC=8C?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=9E=84=E5=BB=BA=E6=97=B6=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 51 +++++++++++------------- next.config.ts | 11 ----- src/app/(api)/identify/callback/page.tsx | 10 ++++- src/app/(auth)/captcha/route.ts | 2 +- src/app/(auth)/login/captcha.tsx | 3 +- src/app/(root)/page.tsx | 8 ++-- 6 files changed, 39 insertions(+), 46 deletions(-) diff --git a/Dockerfile b/Dockerfile index df87386..80728d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,45 +1,46 @@ # 基础阶段:安装依赖和构建应用 FROM node:22.14-alpine AS base -# 配置 Alpine 镜像源 + +# 配置 alpine 镜像源 & 安装依赖 RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories - -# 安装 pnpm -RUN corepack enable && corepack prepare pnpm@10.5.2 --activate - -# 配置pnpm镜像源 -RUN pnpm config set registry https://registry.npmmirror.com - -# 安装构建依赖项 -RUN apk add --no-cache libc6-compat -WORKDIR /app +RUN apk add cairo pango giflib libjpeg pixman # 依赖缓存阶段 FROM base AS deps +WORKDIR /app + +# 安装依赖 +RUN apk add build-base g++ cairo-dev pango-dev giflib-dev + +# 启用 pnpm & 配置镜像源 +RUN corepack enable pnpm +RUN pnpm config set registry https://registry.npmmirror.com + COPY package.json pnpm-lock.yaml* ./ -RUN pnpm fetch --prod -RUN pnpm install --frozen-lockfile --prod +RUN pnpm install --frozen-lockfile # 构建阶段 FROM base AS builder WORKDIR /app + COPY --from=deps /app/node_modules ./node_modules COPY . . # 环境变量设置 -ENV NEXT_TELEMETRY_DISABLED 1 -ENV NODE_ENV production +ENV NEXT_TELEMETRY_DISABLED=1 # 构建应用 -RUN pnpm build +RUN corepack enable pnpm +RUN pnpm run build # 生产阶段 -FROM node:22.14-alpine AS runner +FROM base AS runner WORKDIR /app # 环境变量设置 -ENV NODE_ENV production -ENV NEXT_TELEMETRY_DISABLED 1 +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 # 添加非 root 用户 RUN addgroup --system --gid 1001 nodejs @@ -47,12 +48,6 @@ RUN adduser --system --uid 1001 nextjs # 复制必要文件 COPY --from=builder /app/public ./public - -# 设置适当的权限 -RUN mkdir .next -RUN chown -R nextjs:nodejs .next - -# 复制构建产物 COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static @@ -63,8 +58,8 @@ USER nextjs EXPOSE 3000 # 设置环境变量 -ENV PORT 3000 -ENV HOSTNAME "0.0.0.0" +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" # 启动命令 -CMD ["node", "server.js"] \ No newline at end of file +CMD ["node", "server.js"] diff --git a/next.config.ts b/next.config.ts index 1d28446..8919db6 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,18 +1,7 @@ import type { NextConfig } from "next" const nextConfig: NextConfig = { - poweredByHeader: false, - reactStrictMode: true, - swcMinify: true, output: "standalone", - images: { - minimumCacheTTL: 60, - formats: ["image/webp"], - }, - experimental: { - optimizeCss: true, - serverComponentsExternalPackages: [], - }, } export default nextConfig diff --git a/src/app/(api)/identify/callback/page.tsx b/src/app/(api)/identify/callback/page.tsx index f094981..b5d933b 100644 --- a/src/app/(api)/identify/callback/page.tsx +++ b/src/app/(api)/identify/callback/page.tsx @@ -1,5 +1,5 @@ 'use client' -import {useEffect, useState} from 'react' +import {Suspense, useEffect, useState} from 'react' import {useSearchParams} from 'next/navigation' import {IdentifyCallback} from '@/actions/auth/identify' import {Card, CardContent} from '@/components/ui/card' @@ -8,6 +8,14 @@ import {CheckCircle, AlertCircle, Loader2} from 'lucide-react' export type PageProps = {} export default function Page(props: PageProps) { + return ( + + + + ) +} + + function Page1() { const params = useSearchParams() const success = params.get('success') === 'true' const id = params.get('id') || '' diff --git a/src/app/(auth)/captcha/route.ts b/src/app/(auth)/captcha/route.ts index bfd29e7..703f15b 100644 --- a/src/app/(auth)/captcha/route.ts +++ b/src/app/(auth)/captcha/route.ts @@ -14,7 +14,7 @@ function generateCaptchaText(length: number = 4): string { } // 哈希验证码文本并使用随机盐值 -function hashCaptcha(text: string): { hash: string; salt: string } { +function hashCaptcha(text: string): { hash: string, salt: string } { const salt = crypto.randomBytes(16).toString('hex') const hash = crypto .createHmac('sha256', salt) diff --git a/src/app/(auth)/login/captcha.tsx b/src/app/(auth)/login/captcha.tsx index 643819b..431a02d 100644 --- a/src/app/(auth)/login/captcha.tsx +++ b/src/app/(auth)/login/captcha.tsx @@ -2,6 +2,7 @@ import {useCallback, useEffect, useState} from 'react' import {Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle} from '@/components/ui/dialog' import {Button} from '@/components/ui/button' import {Input} from '@/components/ui/input' +import Image from 'next/image' export type CaptchaProps = { showCaptcha: boolean @@ -44,7 +45,7 @@ export default function Captcha(props: CaptchaProps) {
-