Skip to content

feat: add docker deploy support#50

Open
LuomingXu wants to merge 1 commit intosxjeru:mainfrom
LuomingXu:main
Open

feat: add docker deploy support#50
LuomingXu wants to merge 1 commit intosxjeru:mainfrom
LuomingXu:main

Conversation

@LuomingXu
Copy link

@LuomingXu LuomingXu commented Mar 4, 2026

nextjs

next-env.d.tsnext.config.ts有变动需要review一下

Docker部署

compose file service migrate-DB app
= 用来初始化数据库, 建表啊之类的(先启动, 看到DB里面有表了就可以删了) 服务端app(后启动)
  • 参考docker-compose.yml文件来进行docker的部署
  • 为什么用两个镜像. 因为同时打包的话太大了, 反正数据库也不是会频繁变结构的
IMAGE DISK USAGE CONTENT SIZE
cliproxyapi-monitor:latest 331MB 80.3MB
cliproxyapi-monitor-migrate:latest 580MB 96.6MB
  • 运行完migrate-DB, 会有类似log
检查迁移表... (驱动: pg)
执行数据库迁移...
✓ 迁移完成
  • app的log
▲ Next.js 16.1.6
- Local:         http://fa45b0e6e0ad:3000
- Network:       http://fa45b0e6e0ad:3000
✓ Starting...
✓ Ready in 426ms

Summary by Sourcery

使用 Docker 增加部署支持,为应用和数据库迁移提供容器镜像,并通过 GitHub Actions 自动化镜像发布。

新功能:

  • 提供应用和数据库迁移的 Docker 镜像以及用于运行它们的 docker-compose 配置。
  • 在 README 中记录 Docker 部署用法和容器行为。

增强项:

  • 配置 Next.js 输出独立的生产构建(standalone bundle),并在生产环境中禁用浏览器 source map,以减小容器镜像体积。

构建:

  • 为应用运行时和独立的迁移镜像新增 Dockerfile,并添加 .dockerignore 文件。

CI:

  • 新增 GitHub Actions 工作流,在打版本标签或手动触发时,构建并推送应用和迁移 Docker 镜像到 GitHub Container Registry。
  • 扩展 Dependabot 配置,以监控 GitHub Actions 工作流的更新。
Original summary in English

Summary by Sourcery

Add Docker-based deployment support with container images for the app and database migrations, and automate image publishing via GitHub Actions.

New Features:

  • Provide Docker images and a docker-compose setup for running the app and database migrations.
  • Document Docker deployment usage and container behavior in the README.

Enhancements:

  • Configure Next.js to output a standalone production bundle and disable production browser source maps to reduce container image size.

Build:

  • Add Dockerfiles for the app runtime and a separate migration image, along with a .dockerignore file.

CI:

  • Introduce a GitHub Actions workflow to build and push app and migration Docker images to GitHub Container Registry on version tags or manual dispatch.
  • Extend Dependabot configuration to monitor GitHub Actions workflows for updates.

@vercel
Copy link

vercel bot commented Mar 4, 2026

@LuomingXu is attempting to deploy a commit to the sxjeru's projects Team on Vercel.

A member of the Team first needs to authorize it.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在通过引入 Dockerfile 和 Docker Compose 配置来简化应用程序的部署流程。它将应用程序容器化,并提供了一个独立的数据库迁移容器,从而实现了更灵活和可扩展的部署策略。

Highlights

  • Docker 部署支持: 引入了对应用程序的 Docker 部署支持,包括用于主应用程序和数据库迁移的独立 Docker 镜像。
  • Next.js 配置更新: 修改了 Next.js 配置以支持 standalone 输出模式,并禁用了生产环境的源映射,以优化 Docker 镜像大小。
  • 部署文档: 更新了 README.md 文件,提供了详细的 Docker 部署指南和示例日志。
Changelog
  • .dockerignore
    • 添加了 .dockerignore 文件,以在 Docker 构建过程中排除不必要的文件和目录。
  • .github/dependabot.yml
    • 更新了 Dependabot 配置,以包含对 GitHub Actions 依赖项的每周更新。
  • .gitignore
    • 更新了 .gitignore 文件,添加了 .serenaCLAUDE.md 以忽略这些文件。
  • Dockerfile
    • 添加了主应用程序的 Dockerfile,采用多阶段构建以优化镜像大小,并配置了生产环境。
  • Dockerfile.migrate
    • 添加了数据库迁移服务的 Dockerfile,用于初始化和执行数据库迁移。
  • README.md
    • 更新了 README.md 文件,新增了 Docker 部署部分,详细说明了如何使用 Docker Compose 部署应用程序。
  • docker-compose.yml
    • 添加了 docker-compose.yml 文件,定义了 migrate-DBapp 两个服务,用于协调 Docker 容器的部署。
  • next-env.d.ts
    • 更新了 Next.js 环境声明文件中的类型导入路径。
  • next.config.ts
    • 修改了 Next.js 配置文件,将 output 设置为 standalone 并将 productionBrowserSourceMaps 设置为 false
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/docker-release.yml
Activity
  • 此拉取请求尚未有任何人工活动。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了两个问题,并给出了一些高层次的反馈:

  • 新增的 .dockerignore 文件目前是空的;建议添加一些常见的排除项(node_modules、.next、.git、本地日志等),以减小 Docker 构建上下文的体积,从而加快镜像构建速度。
  • 在 docker-release.yml 中,镜像在有版本标签(vX.Y.Z)时仍然只被打上 :latest 标签;建议同时使用版本号为镜像打标签(例如 ghcr.io/...:v1.2.3),以便在回滚和调试时更方便。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- 新增的 .dockerignore 文件目前是空的;建议添加一些常见的排除项(node_modules、.next、.git、本地日志等),以减小 Docker 构建上下文的体积,从而加快镜像构建速度。
- 在 docker-release.yml 中,镜像在有版本标签(vX.Y.Z)时仍然只被打上 :latest 标签;建议同时使用版本号为镜像打标签(例如 ghcr.io/...:v1.2.3),以便在回滚和调试时更方便。

## Individual Comments

### Comment 1
<location path=".github/workflows/docker-release.yml" line_range="18" />
<code_context>
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v6
+
+      - name: Detect migration-related changes
</code_context>
<issue_to_address>
**issue (bug_risk):** `actions/checkout``v6` 版本目前还不存在,会导致工作流执行失败。

当前可用的最新主版本是 `actions/checkout@v4`,因此使用 `@v6` 会在无法解析该 Action 时导致工作流无效。除非你是有意针对未来的主版本,否则请将其更新为 `actions/checkout@v4`(或固定到具体的提交 SHA),并在两个 job 中都进行相应修改。
</issue_to_address>

### Comment 2
<location path="docker-compose.yml" line_range="10-12" />
<code_context>
+      DATABASE_URL: ${DATABASE_URL}
+      DATABASE_DRIVER: ${DATABASE_DRIVER:-pg}
+      # 针对neon/Supabase
+      POSTGRES_URL: # 池化连接(适合短连接、高并发函数)
+      POSTGRES_URL_NON_POOLING: # 直连连接(更适合迁移、长事务、某些管理操作)
+    restart: "no"
+    profiles:
</code_context>
<issue_to_address>
**suggestion (bug_risk):** 直接给 `POSTGRES_URL*` 赋值会把这些变量设置为空字符串,而不是从宿主环境中继承。

以这种写法,Compose 会将 `POSTGRES_URL``POSTGRES_URL_NON_POOLING` 显式设为两个空字符串,从而覆盖宿主环境中已有的值。如果这些变量是可选的,要么显式地透传它们(例如 `POSTGRES_URL: ${POSTGRES_URL:-}`),要么完全从 `environment` 中删掉,并依赖文档说明,只在实际提供时才设置。

```suggestion
      # 针对neon/Supabase
      POSTGRES_URL: ${POSTGRES_URL:-} # 池化连接(适合短连接、高并发函数)
      POSTGRES_URL_NON_POOLING: ${POSTGRES_URL_NON_POOLING:-} # 直连连接(更适合迁移、长事务、某些管理操作)
```
</issue_to_address>

Sourcery 对开源项目是免费的——如果你觉得这些评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据这些反馈改进后续的评审。
Original comment in English

Hey - I've found 2 issues, and left some high level feedback:

  • The newly added .dockerignore file appears empty; consider adding common exclusions (node_modules, .next, .git, local logs, etc.) to reduce the Docker build context size and speed up image builds.
  • In docker-release.yml, images are only tagged as :latest even for version tags (vX.Y.Z); consider also tagging images with the version (e.g., ghcr.io/...:v1.2.3) to make rollbacks and debugging easier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The newly added .dockerignore file appears empty; consider adding common exclusions (node_modules, .next, .git, local logs, etc.) to reduce the Docker build context size and speed up image builds.
- In docker-release.yml, images are only tagged as :latest even for version tags (vX.Y.Z); consider also tagging images with the version (e.g., ghcr.io/...:v1.2.3) to make rollbacks and debugging easier.

## Individual Comments

### Comment 1
<location path=".github/workflows/docker-release.yml" line_range="18" />
<code_context>
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v6
+
+      - name: Detect migration-related changes
</code_context>
<issue_to_address>
**issue (bug_risk):** The `actions/checkout` version `v6` does not exist yet and will cause workflow failures.

The latest available major is `actions/checkout@v4`, so `@v6` will cause the workflow to be invalid when the action can’t be resolved. Unless you’re intentionally targeting a future major, please update this to `actions/checkout@v4` (or pin to a specific commit SHA) in both jobs.
</issue_to_address>

### Comment 2
<location path="docker-compose.yml" line_range="10-12" />
<code_context>
+      DATABASE_URL: ${DATABASE_URL}
+      DATABASE_DRIVER: ${DATABASE_DRIVER:-pg}
+      # 针对neon/Supabase
+      POSTGRES_URL: # 池化连接(适合短连接、高并发函数)
+      POSTGRES_URL_NON_POOLING: # 直连连接(更适合迁移、长事务、某些管理操作)
+    restart: "no"
+    profiles:
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Bare `POSTGRES_URL*` assignments will set these vars to empty strings rather than inheriting from the host environment.

In this form, Compose sets `POSTGRES_URL` and `POSTGRES_URL_NON_POOLING` to empty strings, overriding any existing host values. If they’re meant to be optional, either pass them through explicitly (e.g. `POSTGRES_URL: ${POSTGRES_URL:-}`) or omit them from `environment` and rely on documentation so they’re only set when provided.

```suggestion
      # 针对neon/Supabase
      POSTGRES_URL: ${POSTGRES_URL:-} # 池化连接(适合短连接、高并发函数)
      POSTGRES_URL_NON_POOLING: ${POSTGRES_URL_NON_POOLING:-} # 直连连接(更适合迁移、长事务、某些管理操作)
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +10 to +12
# 针对neon/Supabase
POSTGRES_URL: # 池化连接(适合短连接、高并发函数)
POSTGRES_URL_NON_POOLING: # 直连连接(更适合迁移、长事务、某些管理操作)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): 直接给 POSTGRES_URL* 赋值会把这些变量设置为空字符串,而不是从宿主环境中继承。

以这种写法,Compose 会将 POSTGRES_URLPOSTGRES_URL_NON_POOLING 显式设为两个空字符串,从而覆盖宿主环境中已有的值。如果这些变量是可选的,要么显式地透传它们(例如 POSTGRES_URL: ${POSTGRES_URL:-}),要么完全从 environment 中删掉,并依赖文档说明,只在实际提供时才设置。

Suggested change
# 针对neon/Supabase
POSTGRES_URL: # 池化连接(适合短连接、高并发函数)
POSTGRES_URL_NON_POOLING: # 直连连接(更适合迁移、长事务、某些管理操作)
# 针对neon/Supabase
POSTGRES_URL: ${POSTGRES_URL:-} # 池化连接(适合短连接、高并发函数)
POSTGRES_URL_NON_POOLING: ${POSTGRES_URL_NON_POOLING:-} # 直连连接(更适合迁移、长事务、某些管理操作)
Original comment in English

suggestion (bug_risk): Bare POSTGRES_URL* assignments will set these vars to empty strings rather than inheriting from the host environment.

In this form, Compose sets POSTGRES_URL and POSTGRES_URL_NON_POOLING to empty strings, overriding any existing host values. If they’re meant to be optional, either pass them through explicitly (e.g. POSTGRES_URL: ${POSTGRES_URL:-}) or omit them from environment and rely on documentation so they’re only set when provided.

Suggested change
# 针对neon/Supabase
POSTGRES_URL: # 池化连接(适合短连接、高并发函数)
POSTGRES_URL_NON_POOLING: # 直连连接(更适合迁移、长事务、某些管理操作)
# 针对neon/Supabase
POSTGRES_URL: ${POSTGRES_URL:-} # 池化连接(适合短连接、高并发函数)
POSTGRES_URL_NON_POOLING: ${POSTGRES_URL_NON_POOLING:-} # 直连连接(更适合迁移、长事务、某些管理操作)

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces Docker deployment support, which is a great improvement for the project. While the use of multi-stage builds and non-root users in the Dockerfile, along with a clear docker-compose.yml and Next.js configurations, align with best practices for secure and optimized containerization, a critical security vulnerability was identified. The migration script catches errors but still exits with a success code (0), which can mask deployment failures and lead to an unstable application state. Additionally, there are some areas in the Dockerfile that could be improved to enhance build reliability and maintainability.

@@ -0,0 +1,38 @@
FROM node:24-alpine AS base

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

您好,node:24-alpine 这个基础镜像似乎不存在。Node.js 24 尚未发布,目前最新的稳定版本是 22,LTS 版本是 20。使用一个不存在的镜像会导致 Docker 构建失败。建议使用一个存在的、稳定的版本,例如最新的 Node.js 22 (node:22-alpine) 或者当前的 LTS 版本 (node:20-alpine),以确保构建的稳定性和可预测性。

FROM node:22-alpine AS base

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,22 @@
FROM node:24-alpine

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

您好,与主 Dockerfile 一样,这里使用的 node:24-alpine 基础镜像似乎不存在,这将导致构建失败。建议更换为存在的镜像版本,例如 node:22-alpine 或 LTS 版本 node:20-alpine,以保证构建能够成功。

FROM node:22-alpine

Comment on lines +7 to +20
ARG DRIZZLE_ORM_VERSION=0.45.1
ARG PG_VERSION=8.19.0
ARG NEON_VERSION=1.0.2
ARG WS_VERSION=8.19.0

COPY scripts ./scripts
COPY drizzle ./drizzle

# Keep migration image dependencies minimal and separate from app image.
RUN npm install --omit=dev --no-package-lock \
drizzle-orm@${DRIZZLE_ORM_VERSION} \
pg@${PG_VERSION} \
@neondatabase/serverless@${NEON_VERSION} \
ws@${WS_VERSION}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

您好,在 Dockerfile.migrate 中硬编码依赖版本(L7-10 和 L16-20)虽然可以精确控制镜像中的包,但长期来看可能会引入维护问题。当项目根目录的 package.json 中这些依赖更新时,此文件需要手动同步更新,否则可能导致迁移脚本在本地和 CI/CD 环境中行为不一致。此外,这里使用了 npm,而主应用使用的是 pnpm,统一包管理器会更好。

为了在保持镜像体积小的同时提高可维护性,可以考虑创建一个专门用于迁移的 package.json 文件,并使用 pnpm 来管理其依赖。如果不想引入新的 package.json,另一种折衷方案是在 CI 流程中从 pnpm-lock.yaml 文件动态提取版本号,并作为构建参数(--build-arg)传入 Dockerfile.migrate

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个确实

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.

1 participant