Skip to content

Commit 856900f

Browse files
committed
ci: fix deploy workflow and add Docker support
- replace pnpm with bun (oven-sh/setup-bun@v2) in build-pages and docker jobs - fix cache/artifact paths from .vitepress/* to docs/.vitepress/* - update cache keys from pnpm-lock.yaml to bun.lock - fix build commands from pnpm build to bun run docs:build - add Dockerfile (multi-stage: bun builder + nginx:alpine runner) - add .dockerignore to exclude src, test, node_modules from image
1 parent 28d35e3 commit 856900f

3 files changed

Lines changed: 76 additions & 26 deletions

File tree

.dockerignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 依赖与构建产物
2+
node_modules
3+
dist
4+
docs/.vitepress/dist
5+
docs/.vitepress/cache
6+
7+
# 源码(CLI,不进镜像)
8+
src
9+
test
10+
.github
11+
12+
# 配置与工具文件
13+
.claude
14+
.env*
15+
*.local
16+
biome.json
17+
tsconfig.json
18+
tsconfig*.json
19+
vercel.json
20+
21+
# 系统文件
22+
.DS_Store
23+
*.log
24+
25+
# README(可选保留,这里排除节省镜像体积)
26+
README*.md
27+
LICENSE

.github/workflows/deploy.yml

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,28 @@ jobs:
3333
with:
3434
fetch-depth: 0
3535

36-
- uses: pnpm/action-setup@v4
36+
- uses: oven-sh/setup-bun@v2
3737
with:
38-
version: 9
39-
40-
- uses: actions/setup-node@v4
41-
with:
42-
node-version: 22
43-
cache: pnpm
38+
bun-version: latest
4439

4540
- uses: actions/cache@v4
4641
with:
47-
path: .vitepress/cache
48-
key: vitepress-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('**/*.md', '.vitepress/config.mts') }}
42+
path: docs/.vitepress/cache
43+
key: vitepress-${{ runner.os }}-${{ hashFiles('bun.lock') }}-${{ hashFiles('docs/**/*.md', 'docs/.vitepress/config.mts') }}
4944
restore-keys: |
50-
vitepress-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-
45+
vitepress-${{ runner.os }}-${{ hashFiles('bun.lock') }}-
5146
vitepress-${{ runner.os }}-
5247
53-
- run: pnpm install --frozen-lockfile
48+
- run: bun install --frozen-lockfile
5449

5550
- name: Build (GitHub Pages)
56-
run: pnpm build
51+
run: bun run docs:build
5752
env:
5853
VITEPRESS_BASE: ${{ vars.VITEPRESS_BASE || format('/{0}/', github.event.repository.name) }}
5954

6055
- uses: actions/upload-pages-artifact@v3
6156
with:
62-
path: .vitepress/dist
57+
path: docs/.vitepress/dist
6358

6459
# ──────────────────────────────────────────────────────────────────────────
6560
# 2. 部署到 GitHub Pages
@@ -78,7 +73,7 @@ jobs:
7873
# 3. 构建并推送 Docker 镜像
7974
#
8075
# Docker 始终以 VITEPRESS_BASE=/ 构建,因为 nginx 从根路径服务。
81-
# 借助 pnpm + VitePress + Docker 层三重缓存,二次构建极快。
76+
# 借助 bun + VitePress + Docker 层三重缓存,二次构建极快。
8277
# ──────────────────────────────────────────────────────────────────────────
8378
docker:
8479
runs-on: ubuntu-latest
@@ -90,28 +85,23 @@ jobs:
9085
with:
9186
fetch-depth: 0
9287

93-
- uses: pnpm/action-setup@v4
94-
with:
95-
version: 9
96-
97-
- uses: actions/setup-node@v4
88+
- uses: oven-sh/setup-bun@v2
9889
with:
99-
node-version: 22
100-
cache: pnpm
90+
bun-version: latest
10191

10292
# 复用与 build-pages 相同的 VitePress 缓存 key
10393
- uses: actions/cache@v4
10494
with:
105-
path: .vitepress/cache
106-
key: vitepress-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('**/*.md', '.vitepress/config.mts') }}
95+
path: docs/.vitepress/cache
96+
key: vitepress-${{ runner.os }}-${{ hashFiles('bun.lock') }}-${{ hashFiles('docs/**/*.md', 'docs/.vitepress/config.mts') }}
10797
restore-keys: |
108-
vitepress-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-
98+
vitepress-${{ runner.os }}-${{ hashFiles('bun.lock') }}-
10999
vitepress-${{ runner.os }}-
110100
111-
- run: pnpm install --frozen-lockfile
101+
- run: bun install --frozen-lockfile
112102

113103
- name: Build (Docker, base=/)
114-
run: pnpm build
104+
run: bun run docs:build
115105
env:
116106
VITEPRESS_BASE: /
117107

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# ── Stage 1: Build ──────────────────────────────────────────────────────────
2+
FROM oven/bun:1 AS builder
3+
4+
WORKDIR /app
5+
6+
COPY package.json bun.lock* ./
7+
RUN bun install --frozen-lockfile
8+
9+
COPY docs/ docs/
10+
11+
ARG VITEPRESS_BASE=/
12+
ENV VITEPRESS_BASE=${VITEPRESS_BASE}
13+
14+
RUN bun run docs:build
15+
16+
# ── Stage 2: Serve ───────────────────────────────────────────────────────────
17+
FROM nginx:alpine AS runner
18+
19+
COPY --from=builder /app/docs/.vitepress/dist /usr/share/nginx/html
20+
21+
# SPA / cleanUrls: try file, then .html, then 404
22+
RUN printf 'server {\n\
23+
listen 80;\n\
24+
root /usr/share/nginx/html;\n\
25+
index index.html;\n\
26+
location / {\n\
27+
try_files $uri $uri.html $uri/ /404.html;\n\
28+
}\n\
29+
}\n' > /etc/nginx/conf.d/default.conf
30+
31+
EXPOSE 80
32+
33+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)