Skip to content

Commit 277c425

Browse files
committed
feat: add cf
Signed-off-by: Ashing Zheng <axingfly@gmail.com>
1 parent 0defdfc commit 277c425

File tree

11 files changed

+434
-136
lines changed

11 files changed

+434
-136
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Deploy to Cloudflare Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
branches:
10+
- main
11+
- master
12+
13+
jobs:
14+
deploy:
15+
runs-on: ubuntu-latest
16+
name: Deploy to Cloudflare Pages
17+
18+
permissions:
19+
contents: read
20+
deployments: write
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Go
27+
uses: actions/setup-go@v5
28+
with:
29+
go-version: 'stable'
30+
31+
- name: Setup Node.js
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: '18'
35+
36+
- name: Cache Go modules
37+
uses: actions/cache@v4
38+
with:
39+
path: |
40+
~/.cache/go-build
41+
~/go/pkg/mod
42+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
43+
restore-keys: |
44+
${{ runner.os }}-go-
45+
46+
- name: Install Wrangler
47+
run: npm install -g wrangler
48+
49+
- name: Build project
50+
run: |
51+
chmod +x ./book/install-and-build.sh
52+
./book/install-and-build.sh build
53+
54+
- name: Deploy to Cloudflare Pages
55+
uses: cloudflare/pages-action@v1
56+
with:
57+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
58+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
59+
projectName: kubebuilder-zh-docs
60+
directory: book/book
61+
# Optional: Use a custom domain
62+
# wranglerVersion: '3'

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ src/docs
2828
/testdata/**/go.sum
2929
book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1/bin
3030
/testdata/**legacy**
31+
book/functions/litgo
32+
book/functions/markerdocs
3133

3234
## Skip testdata files that generate by tests using TestContext
3335
**/e2e-*/**

CLAUDE.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is the Chinese translation repository for the Kubebuilder documentation. It's built using mdBook and contains comprehensive documentation for the Kubebuilder project, including tutorials, reference materials, and migration guides.
8+
9+
## Architecture
10+
11+
- **mdBook Documentation**: Built using Rust's mdBook with custom preprocessors
12+
- **Custom Go Utilities**: Located in `book/utils/` for processing documentation
13+
- **Preprocessors**:
14+
- `litgo.sh` - Processes Go code examples using literate-go utility
15+
- `markerdocs.sh` - Generates marker documentation
16+
- **Content Structure**: Main content in `book/src/` with Chinese documentation
17+
- **Build Artifacts**: Generated site outputs to `book/` directory
18+
19+
## Essential Commands
20+
21+
### Building and Serving
22+
23+
```bash
24+
# Build the documentation (includes downloading dependencies)
25+
./book/install-and-build.sh build
26+
27+
# Serve locally for development (after mdBook is installed)
28+
cd book && mdbook serve
29+
# Then visit http://localhost:3000
30+
31+
# Deploy to Cloudflare (requires environment variables)
32+
./deploy-cloudflare.sh
33+
```
34+
35+
### Development
36+
37+
```bash
38+
# Build Go utilities (preprocessors)
39+
cd book/utils
40+
go build -o ../../bin/literate-go ./litgo
41+
go build -o ../../bin/marker-docs ./markerdocs
42+
43+
# Manual mdBook operations (after install-and-build.sh)
44+
cd book
45+
mdbook build # Build only
46+
mdbook clean # Clean build artifacts
47+
```
48+
49+
## Key Dependencies
50+
51+
- **Go 1.23+**: Required for building utilities and examples
52+
- **mdBook v0.4.40**: Rust-based documentation generator
53+
- **controller-gen v0.19.0**: Kubernetes code generation tool
54+
- **Node.js 18+**: For Cloudflare deployment via Wrangler
55+
56+
## Build Process
57+
58+
1. Downloads and installs mdBook binary for current platform
59+
2. Builds Go utilities in `book/utils/`
60+
3. Installs controller-gen tool
61+
4. Runs mdBook with custom preprocessors
62+
5. Outputs static site to `book/` directory
63+
64+
## Deployment
65+
66+
- **Cloudflare Pages**: Automated via GitHub Actions on push to main/master
67+
- **Environment Variables Required**:
68+
- `CLOUDFLARE_API_TOKEN`
69+
- `CLOUDFLARE_ACCOUNT_ID`
70+
- **Local Deploy**: Use `./deploy-cloudflare.sh` script
71+
72+
## File Structure
73+
74+
- `book/src/SUMMARY.md` - Table of contents for Chinese documentation
75+
- `book/book.toml` - mdBook configuration
76+
- `book/utils/` - Go utilities for documentation processing
77+
- `book/install-and-build.sh` - Main build script
78+
- `deploy-cloudflare.sh` - Cloudflare deployment script
79+
- `.github/workflows/` - CI/CD automation
80+
81+
## Important Notes
82+
83+
- This is a translation project - content follows the original Kubebuilder documentation structure
84+
- Custom preprocessors handle Go code examples and marker documentation
85+
- Build script handles cross-platform mdBook installation automatically
86+
- All scripts include proper error handling and platform detection

book/install-and-build.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if [[ -n "$(command -v gimme)" ]]; then
2828
eval "$(gimme $GO_VERSION)"
2929
fi
3030
echo go version
31-
GOBIN=$THIS_DIR/functions go install ./...
31+
(cd "$THIS_DIR/utils" && GOBIN=$THIS_DIR/functions go install ./...)
3232

3333
os=$(go env GOOS)
3434
arch=$(go env GOARCH)
@@ -67,15 +67,15 @@ esac
6767

6868
# grab mdbook
6969
# we hardcode linux/amd64 since rust uses a different naming scheme and it's a pain to tran
70-
# MDBOOK_VERSION="v0.4.40"
71-
# MDBOOK_BASENAME="mdBook-${MDBOOK_VERSION}-${arch}-${target}"
72-
# MDBOOK_URL="https://github.com/rust-lang/mdBook/releases/download/${MDBOOK_VERSION}/${MDBOOK_BASENAME}.${ext}"
70+
MDBOOK_VERSION="v0.4.40"
71+
MDBOOK_BASENAME="mdBook-${MDBOOK_VERSION}-${arch}-${target}"
72+
MDBOOK_URL="https://github.com/rust-lang/mdBook/releases/download/${MDBOOK_VERSION}/${MDBOOK_BASENAME}.${ext}"
7373

74-
# echo "downloading ${MDBOOK_BASENAME}.${ext} from ${MDBOOK_URL}"
75-
# set -x
76-
# curl -fL -o /tmp/mdbook.${ext} "${MDBOOK_URL}"
77-
# ${cmd} /tmp/mdbook.${ext}
78-
# chmod +x /tmp/mdbook
74+
echo "downloading ${MDBOOK_BASENAME}.${ext} from ${MDBOOK_URL}"
75+
set -x
76+
curl -fL -o /tmp/mdbook.${ext} "${MDBOOK_URL}"
77+
${cmd} /tmp/mdbook.${ext}
78+
chmod +x /tmp/mdbook
7979

8080
CONTROLLER_GEN_VERSION="v0.19.0"
8181

0 commit comments

Comments
 (0)