Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add docker deployment support #39

Merged
merged 5 commits into from
Mar 27, 2023
Merged

Conversation

AprilNEA
Copy link
Contributor

@AprilNEA AprilNEA commented Mar 26, 2023

使用 Docker 构建本项目

Todo

  • 添加 README.md 说明
  • 发布 Docker 镜像
  • 分阶段构建减小镜像体积

@vercel
Copy link

vercel bot commented Mar 26, 2023

Someone is attempting to deploy a commit to a Personal Account owned by @Yidadaa on Vercel.

@Yidadaa first needs to authorize it.

@Yidadaa Yidadaa linked an issue Mar 26, 2023 that may be closed by this pull request
@x-dr
Copy link

x-dr commented Mar 26, 2023

分阶段构建减小镜像体积可以参考官方例子next.js example

  • 先在next.config.js 添加一行output: 'standalone'指定了构建输出的形式
const nextConfig = {
  experimental: {
    appDir: true,
  },
  output: 'standalone',
  webpack(config) {
    config.module.rules.push({
      test: /\.svg$/,
      use: ["@svgr/webpack"],
    }); // 针对 SVG 的处理规则

    return config;
  }
};
Dockerfile
FROM node:18-alpine 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

# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
  elif [ -f package-lock.json ]; then npm ci; \
  elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
  else echo "Lockfile not found." && exit 1; \
  fi


# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
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 yarn build

# If using npm comment out above and use below instead
# 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

# 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

USER nextjs

EXPOSE 3000

ENV PORT 3000

CMD ["node", "server.js"]

构建运行

docker build -t nextjs-docker .
docker run -p 3000:3000 nextjs-docker

@AprilNEA
Copy link
Contributor Author

AprilNEA commented Mar 27, 2023

尝试了,但出现构建错误,对于使用了appDir实验性功能的Nextjs,该 Dockerfile可能不适用

@AprilNEA
Copy link
Contributor Author

AprilNEA commented Mar 27, 2023

Docker 镜像已发布,docker pull aprilnea/chatgpt-next-web

@Yidadaa
Copy link
Collaborator

Yidadaa commented Mar 27, 2023

感谢,我今晚验证后会合并此 PR。

@x-dr
Copy link

x-dr commented Mar 27, 2023

尝试了,但出现构建错误,对于使用了appDir实验性功能的Nextjs,该 Dockerfile可能不适用

应该是缺少git

@Chanzhaoyu
Copy link

Chanzhaoyu commented Mar 27, 2023

感谢,我今晚验证后会合并此 PR。

你应该自己发布 Docker 镜像来保证自动推送的可控性

@Yidadaa
Copy link
Collaborator

Yidadaa commented Mar 27, 2023

@Chanzhaoyu 我会引入一个 github action 来自动发布。

@Chanzhaoyu
Copy link

@Chanzhaoyu 我会引入一个 github action 来自动发布。

是的

@vercel
Copy link

vercel bot commented Mar 27, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
chat-gpt-next-web ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 27, 2023 at 2:42PM (UTC)

@Yidadaa Yidadaa merged commit 8f87a68 into ChatGPTNextWeb:main Mar 27, 2023
@AprilNEA AprilNEA deleted the docker branch March 28, 2023 03:45
hyGuo00 added a commit to hyGuo00/ChatGPT-Next-Web that referenced this pull request Apr 11, 2023
Error: ' can be escaped with ', ‘, &ChatGPTNextWeb#39;, ’. react/no-unescaped-entities。
这个错误是由于React中的JSX语法不支持非转义的特殊字符,如 ' 等。解决这个错误的方法是将特殊字符转义为HTML实体,如 '、‘ 或 &ChatGPTNextWeb#39;。
‘ ---> '
yxl pushed a commit to yxl/ChatGPT-Next-Web that referenced this pull request May 4, 2023
feat: add docker deployment support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Will a Docker version be released?
5 participants