Compare commits

...

37 Commits

Author SHA1 Message Date
Charile Zhou
24265ac20d perf(ci): 并行构建前后端 Docker 镜像
Some checks are pending
Deploy / Build and Push Web Image (push) Blocked by required conditions
Deploy / Build and Push API Image (push) Blocked by required conditions
Deploy / Deploy to Knative (push) Blocked by required conditions
Deploy / Generate Image Tag (push) Successful in 1s
优化流程:
- 拆分为 4 个独立 job:generate-tag、build-web、build-api、deploy
- build-web 和 build-api 并行执行,缩短构建时间
- deploy job 等待两个构建 job 都完成后再执行

预期提升:
- 构建时间从 串行(web + api) 缩短到 max(web, api)
- 大约节省 40-50% 的构建时间
2026-01-23 00:44:55 +08:00
Charile Zhou
294241a7fd perf(docker): 添加阿里云 Alpine 镜像源加速 apk 包下载
Some checks failed
Deploy / Deploy to Knative (push) Has been cancelled
Deploy / Build and Push Images (push) Has been cancelled
- 配置 mirrors.aliyun.com 替代官方源
- 加速 python3、make、g++ 等构建工具的下载
- 显著提升构建速度
2026-01-23 00:40:55 +08:00
Charile Zhou
839e321fb7 fix(docker): 重新添加构建工具以支持离线环境
问题:
- 构建环境无法访问 GitHub (connect ETIMEDOUT)
- bcrypt 无法下载预编译二进制,尝试从源代码编译
- 缺少 python3/make/g++ 导致编译失败

原因:
- 即使是 amd64 架构,在无法访问 GitHub 的离线环境下
- bcrypt 等 native modules 也需要构建工具作为 fallback

解决:
- 重新安装 python3、make、g++ 用于编译 native modules
- 仅在 base 阶段安装,最终 runner 镜像不包含这些工具
2026-01-23 00:40:18 +08:00
Charile Zhou
e08759b869 revert: 移除 Alpine 镜像源和构建工具配置
Some checks failed
Deploy / Build and Push Images (push) Failing after 5m8s
Deploy / Deploy to Knative (push) Has been skipped
- 移除阿里云 Alpine 镜像源配置
- 移除 python3/make/g++ 构建工具安装
- 原��:仅构建 amd64 架构,bcrypt 可直接使用预编译二进制
- 简化 Dockerfile,减少镜像构建时间和体积
2026-01-23 00:33:42 +08:00
Charile Zhou
ad41866e88 revert: 移除多架构镜像构建配置
Some checks failed
Deploy / Deploy to Knative (push) Has been cancelled
Deploy / Build and Push Images (push) Has been cancelled
- 移除 platforms: linux/amd64,linux/arm64 配置
- 恢复为单架构构建(默认 linux/amd64)
- 原因:ARM64 构建时 apk ���发脚本在 QEMU 模拟环境下执行失败
2026-01-23 00:31:20 +08:00
Charile Zhou
f26cd1a739 perf(docker): 配置阿里云 Alpine 镜像源加速构建
Some checks failed
Deploy / Build and Push Images (push) Failing after 1m53s
Deploy / Deploy to Knative (push) Has been skipped
- 使用阿里云 mirrors.aliyun.com 替代官方 dl-cdn.alpinelinux.org
- 显著加速 apk 包下载速度(python3, make, g++ 等)
- 对国内网络环境友好
2026-01-23 00:24:20 +08:00
Charile Zhou
9b24ef50d7 fix(docker): 安装构建工具支持 native modules 编译
Some checks failed
Deploy / Deploy to Knative (push) Has been cancelled
Deploy / Build and Push Images (push) Has been cancelled
问题:
- ARM64 架构编译时,bcrypt 无法从 GitHub 下载预编译二进制
- Alpine 镜像中缺少 Python 和编译工具,导致从源代码编译失败

解决方案:
- 在 base 阶段安装 python3、make、g++
- 这些工具在 deps/builder 阶段用于编译 native modules
- 最终 runner 镜像中不包含这些工具(已编译的二进制从中间镜像复制)

支持的架构:linux/amd64 和 linux/arm64
2026-01-23 00:19:33 +08:00
Charile Zhou
5ce21e2008 fix(docker): 修复 prod-deps 阶段 Prisma Client 生成失败
Some checks failed
Deploy / Build and Push Images (push) Failing after 14m59s
Deploy / Deploy to Knative (push) Has been skipped
问题:
- prod-deps 阶段使用 --prod 安装时不包含 devDependencies
- pnpm db:generate 依赖 dotenv-cli 和 prisma(都是 devDependencies)
- 导致 "sh: dotenv: not found" 错误

解决方案:
- 先安装所有依赖(包括 devDependencies)
- 生成 Prisma Client
- 使用 pnpm prune --prod 删除 devDependencies
- 保持最终镜像体积最小化
2026-01-22 23:57:56 +08:00
Charile Zhou
0d6d6117ea feat(ci): 添加多架构镜像构建支持
- 支持 linux/amd64 和 linux/arm64 架构
- 同时构建 Web 和 API 镜像的多架构版本
- Harbor 镜像仓库将存储 multi-platform manifest
2026-01-22 23:54:33 +08:00
Charile Zhou
f6670372a1 chore: 配置 Verdaccio npm 镜像源
- 添加 registry 配置指向内部 Verdaccio 镜像
- 保留原有的 peer dependencies 配置
- 统一开发和构建环境的包管理源
2026-01-22 23:49:09 +08:00
Charile Zhou
4e8b660213 refactor(docker): 简化镜像源配置,统一在 base stage 设置
Some checks failed
Deploy / Build and Push Images (push) Failing after 2m39s
Deploy / Deploy to Knative (push) Has been skipped
- 移除无用的 npm config set(项目使用 pnpm)
- 在 base stage 统一设置 pnpm config,deps 和 prod-deps 自动继承
- 减少重复配置,代码更简洁
2026-01-22 23:42:53 +08:00
Charile Zhou
fd5efabd76 feat(docker): 使用内部 Verdaccio npm 镜像源
- 所有 npm registry 从 npmmirror.com 改为 verdaccio.tegical.world
- 包括 Corepack、npm 和 pnpm 的镜像源配置
- 完全隔离外网依赖,提升构建速度和稳定性
2026-01-22 23:40:53 +08:00
Charile Zhou
02f48c2955 fix(docker): 配置 Corepack 使用 npmmirror 下载 pnpm
Some checks failed
Deploy / Build and Push Images (push) Failing after 4m40s
Deploy / Deploy to Knative (push) Has been skipped
- 添加 ENV COREPACK_NPM_REGISTRY 环境变量
- 解决 Corepack 仍然尝试从 registry.npmjs.org 下载 pnpm 的问题
- npm config 只影响 npm,Corepack 需要单独配置
2026-01-22 23:28:15 +08:00
Charile Zhou
76c03f95f1 feat(web): 添加 public 目录
Some checks failed
Deploy / Build and Push Images (push) Failing after 4m7s
Deploy / Deploy to Knative (push) Has been skipped
- 创建 apps/web/public 目录用于存放静态资源
- 添加 .gitkeep 确保空目录被 Git 追踪
- 兼容 Dockerfile 中的 COPY public 指令
2026-01-22 23:08:15 +08:00
Charile Zhou
9a1285b4cc fix(docker): 配置 npm 镜像源解决网络访问问题
Some checks failed
Deploy / Build and Push Images (push) Failing after 3m6s
Deploy / Deploy to Knative (push) Has been skipped
- 配置 npm registry 为 https://registry.npmmirror.com
- 解决 Corepack 下载 pnpm 超时问题
- 配置 pnpm registry 加速依赖安装
- 应用于所有 stage (deps, prod-deps)
2026-01-22 23:00:37 +08:00
Charile Zhou
0201b5336e feat(docker): 使用 Harbor 内部代理拉取 Node 镜像
Some checks failed
Deploy / Build and Push Images (push) Failing after 1m51s
Deploy / Deploy to Knative (push) Has been skipped
- Node 镜像改为 harbor.tegical.world/docker.io/node:24.11.1-alpine
- 通过内部 Harbor 代理访问 Docker Hub,避免网络问题
- 提升镜像拉取速度和稳定性
2026-01-22 22:53:34 +08:00
Charile Zhou
b6b0c229ef revert: 移除 Docker Buildx driver 配置
- 恢复使用默认的 docker-container driver
- 支持更完整的 BuildKit 特性
2026-01-22 22:50:42 +08:00
Charile Zhou
a83de0cc0d ci: 配置 Docker Buildx 使用 docker driver
Some checks failed
Deploy / Build and Push Images (push) Failing after 1m8s
Deploy / Deploy to Knative (push) Has been skipped
- 添加 driver: docker 配置
- 使用 Docker 原生构建器而非 docker-container
- 更简单轻量,适合标准构建场景
2026-01-22 22:47:20 +08:00
Charile Zhou
31ca44dbc3 refactor(docker): runner stage 复用 base 而非重新 FROM
Some checks failed
Deploy / Build and Push Images (push) Failing after 1m29s
Deploy / Deploy to Knative (push) Has been skipped
- 将 runner stage 从 'FROM node:20-alpine' 改为 'FROM base'
- 统一版本管理,只需修改 base stage 一处
- 避免 base 和 runner 使用不同 Node 版本的风险
2026-01-22 22:41:05 +08:00
Charile Zhou
771920afbc fix(docker): 对齐 Node 版本并简化 pnpm 配置
Some checks failed
Deploy / Deploy to Knative (push) Has been cancelled
Deploy / Build and Push Images (push) Has been cancelled
- Node 版本从 20 升级到 24.11.1,与 .nvmrc 保持一致
- 移除 corepack prepare pnpm@9,由 package.json 的 packageManager 字段管理
- Corepack 会自动读取 packageManager: "pnpm@9.15.2" 并使用
2026-01-22 22:39:48 +08:00
Charile Zhou
0a87cf8939 fix(docker): 移除 syntax 指令避免访问 Docker Hub
Some checks failed
Deploy / Deploy to Knative (push) Has been cancelled
Deploy / Build and Push Images (push) Has been cancelled
- 移除 Dockerfile 第一行的 syntax=docker/dockerfile:1
- 该指令会导致 BuildKit 尝试从 Docker Hub 拉取镜像
- 修复无法访问 Docker Hub 导致的构建失败问题
- 对于标准 Dockerfile 特性,此指令非必需
2026-01-22 22:38:15 +08:00
Charile Zhou
097658606b refactor(ci): 直接使用 vars.IMAGE_REGISTRY 不通过 env 套一层
Some checks failed
Deploy / Build and Push Images (push) Failing after 1m39s
Deploy / Deploy to Knative (push) Has been skipped
- 移除不必要的 env.REGISTRY 定义
- 所有引用直接使用 ${{ vars.IMAGE_REGISTRY }}
- 减少间接引用,代码更简洁直观
2026-01-22 22:35:09 +08:00
Charile Zhou
e394358946 fix(ci): 使用 vars 而非 secrets 访问 IMAGE_REGISTRY
Some checks failed
Deploy / Deploy to Knative (push) Has been cancelled
Deploy / Build and Push Images (push) Has been cancelled
- IMAGE_REGISTRY 配置为 repository variable 而非 secret
- 使用 ${{ vars.IMAGE_REGISTRY }} 替代 ${{ secrets.IMAGE_REGISTRY }}
2026-01-22 22:33:43 +08:00
Charile Zhou
7889037b0e feat(ci): 集成 Harbor 镜像仓库
Some checks failed
Deploy / Build and Push Images (push) Failing after 1m1s
Deploy / Deploy to Knative (push) Has been skipped
- 使用 secrets.IMAGE_REGISTRY 配置仓库地址
- 使用 Harbor Robot 账号进行镜像推送认证
- Knative Service 添加 harbor-registry-secret 拉取认证
- 支持动态替换镜像仓库地址和标签占位符
2026-01-22 22:31:21 +08:00
Charile Zhou
45e3542558 Revert "perf(ci): 使用 Kubernetes 内部 Service 加速镜像推送"
Some checks failed
Deploy / Build and Push Images (push) Failing after 1m1s
Deploy / Deploy to Knative (push) Has been skipped
This reverts commit af159b6b4f.
2026-01-22 22:12:05 +08:00
Charile Zhou
af159b6b4f perf(ci): 使用 Kubernetes 内部 Service 加速镜像推送
Some checks failed
Deploy / Build and Push Images (push) Failing after 45s
Deploy / Deploy to Knative (push) Has been skipped
- 使用 gitea-http.infra.svc.cluster.local:3000 替代外部域名
- 避免流量经过外部网络,提升推送速度
- 配置 BuildKit 支持 HTTP insecure registry
- 同一集群内部通信,延迟更低
2026-01-22 22:07:22 +08:00
Charile Zhou
6323f6b361 fix(ci): 修复 Docker 登录认证变量
- 使用 github.actor 替代 gitea.actor
- 使用 secrets.GITHUB_TOKEN 替代 secrets.GITEA_TOKEN
- Gitea Actions 为兼容 GitHub Actions 使用相同的上下文命名
2026-01-22 22:04:40 +08:00
Charile Zhou
1a921c725e ci: 使用 Gitea 内置认证变量替代手动配置的 Secrets
Some checks failed
Deploy / Build and Push Images (push) Failing after 59s
Deploy / Deploy to Knative (push) Has been skipped
- 工作流配置改用 gitea.actor 和 GITEA_TOKEN
- 更新部署文档,移除镜像仓库凭证配置说明
- 添加手动部署的 docker login 步骤
2026-01-22 21:56:34 +08:00
48aaea7773 Merge pull request 'test/ci-workflow' (#7) from test/ci-workflow into main
Some checks failed
Deploy / Build and Push Images (push) Failing after 1m41s
Deploy / Deploy to Knative (push) Has been skipped
Reviewed-on: #7
Reviewed-by: gitea_admin <gitea@local.domain>
2026-01-22 10:36:57 +00:00
charilezhou
a632d48590 ci: 移除 pnpm 缓存配置
All checks were successful
CI / Build Check (pull_request) Successful in 2m10s
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 18:22:07 +08:00
charilezhou
e98c726796 fix(ci): 使用 .nvmrc 和 packageManager 配置版本
All checks were successful
CI / Build Check (pull_request) Successful in 2m21s
- Node.js 版本从 .nvmrc 读取
- pnpm 版本从 package.json 的 packageManager 字段读取
- 移除硬编码的版本号

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 18:19:41 +08:00
charilezhou
c5e08b5632 ci: 使用 registry 缓存替代 gha 缓存
Some checks failed
CI / Build Check (pull_request) Failing after 1m28s
Docker 构建缓存改为存储在镜像仓库中,兼容 Gitea Actions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 18:17:13 +08:00
charilezhou
a82144a676 ci: 移除容器配置,改为 Runner 级别配置
Some checks failed
CI / Build Check (pull_request) Failing after 4m51s
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 18:08:57 +08:00
charilezhou
a211da4468 ci: 添加 pnpm 依赖包缓存配置
Some checks failed
CI / Build Check (pull_request) Failing after 33s
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 18:02:26 +08:00
charilezhou
9c93e324dd fix(ci): 添加容器镜像配置解决 Node.js 缺失问题
Some checks failed
CI / Build Check (pull_request) Failing after 25s
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 18:00:41 +08:00
charilezhou
fbe88764e5 ci: 移除手动触发配置
Some checks failed
CI / Build Check (pull_request) Failing after 1m18s
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 17:50:46 +08:00
charilezhou
42501148b9 ci: 添加手动触发支持
Some checks failed
CI / Build Check (pull_request) Failing after 4m43s
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 17:45:45 +08:00
9 changed files with 99 additions and 53 deletions

View File

@@ -5,10 +5,6 @@ on:
branches: branches:
- main - main
env:
PNPM_VERSION: 9
NODE_VERSION: 20
jobs: jobs:
build: build:
name: Build Check name: Build Check
@@ -19,14 +15,11 @@ jobs:
- name: Setup pnpm - name: Setup pnpm
uses: pnpm/action-setup@v4 uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- name: Setup Node.js - name: Setup Node.js
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: ${{ env.NODE_VERSION }} node-version-file: '.nvmrc'
cache: pnpm
- name: Install dependencies - name: Install dependencies
run: pnpm install --frozen-lockfile run: pnpm install --frozen-lockfile

View File

@@ -6,17 +6,24 @@ on:
- main - main
env: env:
PNPM_VERSION: 9
NODE_VERSION: 20
REGISTRY: gitea.tegical.world
IMAGE_PREFIX: tegical/seclusion IMAGE_PREFIX: tegical/seclusion
jobs: jobs:
build-and-push: generate-tag:
name: Build and Push Images name: Generate Image Tag
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
image_tag: ${{ steps.meta.outputs.tag }} image_tag: ${{ steps.meta.outputs.tag }}
steps:
- name: Generate image tag
id: meta
run: |
echo "tag=$(date +%Y%m%d%H%M%S)-${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
build-web:
name: Build and Push Web Image
runs-on: ubuntu-latest
needs: generate-tag
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -24,17 +31,12 @@ jobs:
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Generate image tag - name: Login to Harbor Registry
id: meta
run: |
echo "tag=$(date +%Y%m%d%H%M%S)-${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
- name: Login to Gitea Container Registry
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ${{ env.REGISTRY }} registry: ${{ vars.IMAGE_REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }} username: ${{ secrets.IMAGE_REGISTRY_ROBOT_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }} password: ${{ secrets.IMAGE_REGISTRY_ROBOT_PASSWORD }}
- name: Build and push Web image - name: Build and push Web image
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
@@ -43,10 +45,28 @@ jobs:
file: ./apps/web/Dockerfile file: ./apps/web/Dockerfile
push: true push: true
tags: | tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}-web:${{ steps.meta.outputs.tag }} ${{ vars.IMAGE_REGISTRY }}/${{ env.IMAGE_PREFIX }}-web:${{ needs.generate-tag.outputs.image_tag }}
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}-web:latest ${{ vars.IMAGE_REGISTRY }}/${{ env.IMAGE_PREFIX }}-web:latest
cache-from: type=gha cache-from: type=registry,ref=${{ vars.IMAGE_REGISTRY }}/${{ env.IMAGE_PREFIX }}-web:buildcache
cache-to: type=gha,mode=max cache-to: type=registry,ref=${{ vars.IMAGE_REGISTRY }}/${{ env.IMAGE_PREFIX }}-web:buildcache,mode=max
build-api:
name: Build and Push API Image
runs-on: ubuntu-latest
needs: generate-tag
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Harbor Registry
uses: docker/login-action@v3
with:
registry: ${{ vars.IMAGE_REGISTRY }}
username: ${{ secrets.IMAGE_REGISTRY_ROBOT_USERNAME }}
password: ${{ secrets.IMAGE_REGISTRY_ROBOT_PASSWORD }}
- name: Build and push API image - name: Build and push API image
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
@@ -55,15 +75,15 @@ jobs:
file: ./apps/api/Dockerfile file: ./apps/api/Dockerfile
push: true push: true
tags: | tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}-api:${{ steps.meta.outputs.tag }} ${{ vars.IMAGE_REGISTRY }}/${{ env.IMAGE_PREFIX }}-api:${{ needs.generate-tag.outputs.image_tag }}
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}-api:latest ${{ vars.IMAGE_REGISTRY }}/${{ env.IMAGE_PREFIX }}-api:latest
cache-from: type=gha cache-from: type=registry,ref=${{ vars.IMAGE_REGISTRY }}/${{ env.IMAGE_PREFIX }}-api:buildcache
cache-to: type=gha,mode=max cache-to: type=registry,ref=${{ vars.IMAGE_REGISTRY }}/${{ env.IMAGE_PREFIX }}-api:buildcache,mode=max
deploy: deploy:
name: Deploy to Knative name: Deploy to Knative
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: build-and-push needs: [generate-tag, build-web, build-api]
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -79,8 +99,10 @@ jobs:
- name: Update image tags in manifests - name: Update image tags in manifests
run: | run: |
IMAGE_TAG=${{ needs.build-and-push.outputs.image_tag }} IMAGE_TAG=${{ needs.generate-tag.outputs.image_tag }}
IMAGE_REGISTRY=${{ vars.IMAGE_REGISTRY }}
sed -i "s|IMAGE_TAG_PLACEHOLDER|${IMAGE_TAG}|g" deploy/k8s/*.yaml sed -i "s|IMAGE_TAG_PLACEHOLDER|${IMAGE_TAG}|g" deploy/k8s/*.yaml
sed -i "s|IMAGE_REGISTRY_PLACEHOLDER|${IMAGE_REGISTRY}|g" deploy/k8s/*.yaml
- name: Deploy to Knative - name: Deploy to Knative
run: | run: |

2
.npmrc
View File

@@ -1,2 +1,4 @@
registry=https://verdaccio.tegical.world
auto-install-peers=true auto-install-peers=true
strict-peer-dependencies=false strict-peer-dependencies=false

View File

@@ -1,10 +1,18 @@
# syntax=docker/dockerfile:1
# ============================================ # ============================================
# Base stage: Install dependencies # Base stage: Install dependencies
# ============================================ # ============================================
FROM node:20-alpine AS base FROM harbor.tegical.world/docker.io/node:24.11.1-alpine AS base
RUN corepack enable && corepack prepare pnpm@9 --activate # 配置阿里云 Alpine 镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 配置镜像源
ENV COREPACK_NPM_REGISTRY=https://verdaccio.tegical.world
RUN corepack enable
RUN pnpm config set registry https://verdaccio.tegical.world
# 安装构建工具 (bcrypt 等 native modules 在无法下载预编译二进制时需要从源代码编译)
RUN apk add --no-cache python3 make g++
WORKDIR /app WORKDIR /app
# ============================================ # ============================================
@@ -50,16 +58,22 @@ COPY apps/api/prisma ./apps/api/prisma/
COPY packages/shared/package.json ./packages/shared/ COPY packages/shared/package.json ./packages/shared/
COPY packages/eslint-config/package.json ./packages/eslint-config/ COPY packages/eslint-config/package.json ./packages/eslint-config/
COPY packages/typescript-config/package.json ./packages/typescript-config/ COPY packages/typescript-config/package.json ./packages/typescript-config/
RUN pnpm install --frozen-lockfile --prod
# Generate Prisma Client for production # Install all dependencies first (including devDependencies for Prisma generation)
RUN pnpm install --frozen-lockfile
# Generate Prisma Client
WORKDIR /app/apps/api WORKDIR /app/apps/api
RUN pnpm db:generate RUN pnpm db:generate
# Remove devDependencies to reduce image size
WORKDIR /app
RUN pnpm prune --prod
# ============================================ # ============================================
# Runner stage: Production image # Runner stage: Production image
# ============================================ # ============================================
FROM node:20-alpine AS runner FROM base AS runner
WORKDIR /app WORKDIR /app
ENV NODE_ENV=production ENV NODE_ENV=production

View File

@@ -1,10 +1,18 @@
# syntax=docker/dockerfile:1
# ============================================ # ============================================
# Base stage: Install dependencies # Base stage: Install dependencies
# ============================================ # ============================================
FROM node:20-alpine AS base FROM harbor.tegical.world/docker.io/node:24.11.1-alpine AS base
RUN corepack enable && corepack prepare pnpm@9 --activate # 配置阿里云 Alpine 镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 配置镜像源
ENV COREPACK_NPM_REGISTRY=https://verdaccio.tegical.world
RUN corepack enable
RUN pnpm config set registry https://verdaccio.tegical.world
# 安装构建工具 (native modules 在无法下载预编译二进制时需要从源代码编译)
RUN apk add --no-cache python3 make g++
WORKDIR /app WORKDIR /app
# ============================================ # ============================================
@@ -39,7 +47,7 @@ RUN pnpm build
# ============================================ # ============================================
# Runner stage: Production image # Runner stage: Production image
# ============================================ # ============================================
FROM node:20-alpine AS runner FROM base AS runner
WORKDIR /app WORKDIR /app
ENV NODE_ENV=production ENV NODE_ENV=production

0
apps/web/public/.gitkeep Normal file
View File

View File

@@ -33,10 +33,10 @@ deploy/k8s/
| Secret 名称 | 说明 | 生成方式 | | Secret 名称 | 说明 | 生成方式 |
|------------|------|---------| |------------|------|---------|
| `REGISTRY_USERNAME` | Gitea 容器镜像仓库用户名 | - |
| `REGISTRY_PASSWORD` | Gitea 容器镜像仓库密码 | Token 或密码 |
| `KUBECONFIG` | Base64 编码的 kubeconfig | `cat ~/.kube/config \| base64` | | `KUBECONFIG` | Base64 编码的 kubeconfig | `cat ~/.kube/config \| base64` |
**注意**:容器镜像推送使用 Gitea Actions 内置的认证变量(`${{ github.actor }}``${{ secrets.GITHUB_TOKEN }}`),无需手动配置镜像仓库凭证。
## 配置修改 ## 配置修改
### 1. ConfigMap (`deploy/k8s/configmap.yaml`) ### 1. ConfigMap (`deploy/k8s/configmap.yaml`)
@@ -111,26 +111,29 @@ resources:
### 手动部署 ### 手动部署
```bash ```bash
# 1. 构建镜像 # 1. 登录 Gitea 容器镜像仓库
docker login gitea.tegical.world
# 2. 构建镜像
docker build -f apps/web/Dockerfile -t gitea.tegical.world/tegical/seclusion-web:latest . docker build -f apps/web/Dockerfile -t gitea.tegical.world/tegical/seclusion-web:latest .
docker build -f apps/api/Dockerfile -t gitea.tegical.world/tegical/seclusion-api:latest . docker build -f apps/api/Dockerfile -t gitea.tegical.world/tegical/seclusion-api:latest .
# 2. 推送镜像 # 3. 推送镜像
docker push gitea.tegical.world/tegical/seclusion-web:latest docker push gitea.tegical.world/tegical/seclusion-web:latest
docker push gitea.tegical.world/tegical/seclusion-api:latest docker push gitea.tegical.world/tegical/seclusion-api:latest
# 3. 部署到 Knative # 4. 部署到 Knative
kubectl apply -f deploy/k8s/namespace.yaml kubectl apply -f deploy/k8s/namespace.yaml
kubectl apply -f deploy/k8s/configmap.yaml kubectl apply -f deploy/k8s/configmap.yaml
kubectl apply -f deploy/k8s/secret.yaml kubectl apply -f deploy/k8s/secret.yaml
kubectl apply -f deploy/k8s/web-ksvc.yaml kubectl apply -f deploy/k8s/web-ksvc.yaml
kubectl apply -f deploy/k8s/api-ksvc.yaml kubectl apply -f deploy/k8s/api-ksvc.yaml
# 4. 等待服务就绪 # 5. 等待服务就绪
kubectl wait --for=condition=Ready ksvc/seclusion-web -n seclusion --timeout=300s kubectl wait --for=condition=Ready ksvc/seclusion-web -n seclusion --timeout=300s
kubectl wait --for=condition=Ready ksvc/seclusion-api -n seclusion --timeout=300s kubectl wait --for=condition=Ready ksvc/seclusion-api -n seclusion --timeout=300s
# 5. 查看服务 URL # 6. 查看服务 URL
kubectl get ksvc -n seclusion kubectl get ksvc -n seclusion
``` ```

View File

@@ -16,10 +16,12 @@ spec:
# 每个实例的并发请求数 # 每个实例的并发请求数
autoscaling.knative.dev/target: "100" autoscaling.knative.dev/target: "100"
spec: spec:
imagePullSecrets:
- name: harbor-registry-secret
containerConcurrency: 0 containerConcurrency: 0
containers: containers:
- name: api - name: api
image: gitea.tegical.world/tegical/seclusion-api:IMAGE_TAG_PLACEHOLDER image: IMAGE_REGISTRY_PLACEHOLDER/tegical/seclusion-api:IMAGE_TAG_PLACEHOLDER
ports: ports:
- containerPort: 4000 - containerPort: 4000
envFrom: envFrom:

View File

@@ -16,10 +16,12 @@ spec:
# 每个实例的并发请求数 # 每个实例的并发请求数
autoscaling.knative.dev/target: "100" autoscaling.knative.dev/target: "100"
spec: spec:
imagePullSecrets:
- name: harbor-registry-secret
containerConcurrency: 0 containerConcurrency: 0
containers: containers:
- name: web - name: web
image: gitea.tegical.world/tegical/seclusion-web:IMAGE_TAG_PLACEHOLDER image: IMAGE_REGISTRY_PLACEHOLDER/tegical/seclusion-web:IMAGE_TAG_PLACEHOLDER
ports: ports:
- containerPort: 3000 - containerPort: 3000
envFrom: envFrom: