Skip to content

Commit

Permalink
ci: lint Chinese doc (#641)
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander authored Jul 15, 2024
1 parent ac75cf0 commit 6109acd
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 24 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ jobs:
check:
timeout-minutes: 10
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./site
steps:
- uses: actions/checkout@v4

Expand All @@ -33,7 +30,15 @@ jobs:
./site/tmp
key: ${{ runner.os }}-${{ hashFiles('./Makefile') }}

- name: lint cjk
run: |
if ! make lint-cjk; then
echo "Please run 'make fix-cjk', edit the detected files and commit changes."
exit 1
fi
- name: build
working-directory: ./site
run: |
set -euo pipefail
make build
Expand Down
25 changes: 22 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dev-tools:
build-dev-tools:
# before running this task, please run `make build-dev-tools-local` and check if the image work locally
docker buildx build --platform=linux/amd64,linux/arm64 \
--network=host --build-arg GOPROXY=${GOPROXY} -t ${DEV_TOOLS_IMAGE} --push -f tools/Dockerfile.dev ./tools
--network=host --build-arg GOPROXY=${GOPROXY} -t ${REAL_DEV_TOOLS_IMAGE} --push -f tools/Dockerfile.dev ./tools

.PHONY: build-dev-tools-local
build-dev-tools-local:
Expand Down Expand Up @@ -159,16 +159,35 @@ lint-editorconfig: $(LOCALBIN)
test -x $(LOCALBIN)/editorconfig-checker || GOBIN=$(LOCALBIN) go install github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.2
$(LOCALBIN)/editorconfig-checker

.PHONY: lint-cjk
lint-cjk: dev-tools
docker run --rm -v $(PWD):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} \
${DEV_TOOLS_IMAGE} \
autocorrect --lint ./site/content/zh-hans

.PHONY: fix-cjk
fix-cjk: dev-tools
docker run --rm -v $(PWD):/go/src/${PROJECT_NAME} -w /go/src/${PROJECT_NAME} \
${DEV_TOOLS_IMAGE} \
autocorrect --fix ./site/content/zh-hans

# we don't add this to the umbrella `lint` task because it requires the website to be generated first
.PHONY: lint-website
lint-website: $(LOCALBIN)
test -x $(LOCALBIN)/htmltest || GOBIN=$(LOCALBIN) go install github.com/wjdp/htmltest@v0.17.0
$(LOCALBIN)/htmltest --conf ./.htmltest.yml ./public | grep -E '(target does not exist|Non-OK status: 404)' \
&& exit 1 || true

.PHONY: lint-remain
lint-remain:
grep '>>>>>>' $(shell git ls-files .) | grep -v 'Makefile:' && exit 1 || true
go run tools/cmd/linter/main.go

.PHONY: lint
lint: lint-go lint-proto lint-license lint-spell lint-editorconfig lint-remain
lint: lint-go lint-proto lint-license lint-spell lint-editorconfig lint-cjk lint-remain

.PHONY: fmt
fmt: fmt-go fmt-proto
fmt: fmt-go fmt-proto fix-spell fix-cjk

.PHONY: verify-example
verify-example:
Expand Down
3 changes: 2 additions & 1 deletion common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ BUILD_IMAGE ?= $(DOCKER_MIRROR)docker.io/library/golang:1.21-bullseye
# We don't use istio/proxyv2 because it is not designed to be run separately (need to work around permission issue).
PROXY_IMAGE ?= $(DOCKER_MIRROR)docker.io/envoyproxy/envoy:contrib-v1.29.5
# We may need to use timestamp if we need to update the image in one PR
DEV_TOOLS_IMAGE ?= $(DOCKER_MIRROR)ghcr.io/mosn/htnn-dev-tools:2024-03-05
REAL_DEV_TOOLS_IMAGE ?= ghcr.io/mosn/htnn-dev-tools:2024-07-12
DEV_TOOLS_IMAGE ?= $(DOCKER_MIRROR)$(REAL_DEV_TOOLS_IMAGE)

ISTIO_VERSION = 1.21.3
GATEWAY_API_VERSION = 1.0.0
Expand Down
6 changes: 0 additions & 6 deletions site/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,3 @@ clean:
publish:
# FIXME: change baseURL to real link
docker run --rm -v $(PWD):/src --name docsy htnn-docsy -- hugo --minify --gc --baseURL https://mosn.io/

.PHONY: lint-website
lint-website: $(LOCALBIN)
test -x $(LOCALBIN)/htmltest || GOBIN=$(LOCALBIN) go install github.com/wjdp/htmltest@v0.17.0
$(LOCALBIN)/htmltest --conf ./.htmltest.yml ./public | grep -E '(target does not exist|Non-OK status: 404)' \
&& exit 1 || true
2 changes: 1 addition & 1 deletion site/content/zh-hans/docs/concept/filterpolicy.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ status:
pet: cat
```

对于 VirtualService 里的其他路由,“pet” 对应的配置都是 goldfish。只有 “to-httpbin” 这条路由的配置是 cat。
对于 VirtualService 里的其他路由,“pet”对应的配置都是 goldfish。只有“to-httpbin”这条路由的配置是 cat。

我们也可以在 [LDS](https://www.envoyproxy.io/docs/envoy/latest/configuration/listeners/lds.html) 级别上配置策略。简单来说,你可以理解成端口级别上的配置。要想配置 LDS 级别的策略,需要在启动控制面时设置环境变量 `HTNN_ENABLE_LDS_PLUGIN_VIA_ECDS` 为 true。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ HTNN 的插件分成两种:Go 插件和 Native 插件。Native 插件在运行
### 插件顺序

我们为每个插件定义了固定顺序。
顺序由两部分组合而成:顺序组(Order Group) 和 操作(Operation)。插件的顺序首先通过其组进行比较。
顺序由两部分组合而成:顺序组(Order Group)和 操作(Operation)。插件的顺序首先通过其组进行比较。
然后,同组内插件的顺序由操作决定。
对于操作相同的插件,它们按字母顺序排序。
以下是顺序组(从第一个到最后一个排序):
Expand Down
2 changes: 1 addition & 1 deletion site/content/zh-hans/docs/reference/expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: 表达式
---

HTNN 许多地方使用了 CEL(Common Expression Language) 作为运行时动态执行的表达式。关于 CEL 的语法,请参考[官方文档](https://github.com/google/cel-spec)。为了让 CEL 可以在网络代理的上下文中大显身手,HTNN 提供了一套 CEL 拓展库以供表达式访问相关的信息。本文档将描述该 CEL 拓展库。
HTNN 许多地方使用了 CEL(Common Expression Language)作为运行时动态执行的表达式。关于 CEL 的语法,请参考[官方文档](https://github.com/google/cel-spec)。为了让 CEL 可以在网络代理的上下文中大显身手,HTNN 提供了一套 CEL 拓展库以供表达式访问相关的信息。本文档将描述该 CEL 拓展库。

## request

Expand Down
2 changes: 1 addition & 1 deletion site/content/zh-hans/docs/reference/plugins/ext_auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ title: Ext Auth

| 名称 | 类型 | 必选 | 校验规则 | 说明 |
|---------------------|--------------------------------------------|------|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| url | string || must be valid URI | 外部服务的 uri,如 `http://ext_auth/prefix` uri 的路径将作为鉴权请求路径的前缀。 |
| url | string || must be valid URI | 外部服务的 uri,如 `http://ext_auth/prefix`。uri 的路径将作为鉴权请求路径的前缀。 |
| timeout | [Duration](../../type#duration) || > 0s | 超时时长。例如,`10s` 表示超时时间为 10 秒。默认值为 0.2s。 |
| authorizationRequest | AuthorizationRequest || | |
| authorizationResponse | AuthorizationResponse || | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ title: Limit Count Redis

每个规则的统计是独立的。当任一规则的额度用完后,就会触发限流操作。因限流产生的拒绝的响应中会包含 header `x-envoy-ratelimited: true`。如果配置了 `enableLimitQuotaHeaders``true` 且访问 Redis 成功,所有响应中都会包括下面三个头:

* `x-ratelimit-limit`:表示当前应用的限流规则。格式为“当前剩余额度最少的规则, (规则额度;w=时间窗口){1个或多个规则}”,例如 `2, 2;w=60`
* `x-ratelimit-limit`:表示当前应用的限流规则。格式为“当前剩余额度最少的规则(规则额度;w=时间窗口){1 个或多个规则}”,例如 `2, 2;w=60`
* `x-ratelimit-remaining`:表示当前剩余额度最少的规则的剩余额度,最小值为 `0`
* `x-ratelimit-reset`:表示当前剩余额度最少的规则什么时候重置,单位为秒,例如 `59`。注意由于网络延迟等原因,该值并非绝对精准。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
port: 8080
```
通过应用下述配置,`http://localhost:10000/` 的请求速率被限制为每秒 1 个请求:
通过应用下述配置,`http://localhost:10000/` 的请求速率被限制为每秒 1 个请求

```yaml
apiVersion: htnn.mosn.io/v1
Expand Down Expand Up @@ -69,7 +69,7 @@ spec:
denominator: HUNDRED
```

我们可以进行测试:
我们可以进行测试

```
$ while true; do curl -I http://localhost:10000/ 2>/dev/null | head -1 ;done
Expand Down
2 changes: 1 addition & 1 deletion site/content/zh-hans/docs/reference/plugins/oidc.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ title: OIDC
|---------------------------|---------------------------------------------|------|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| clientId | string || | 客户端 ID |
| clientSecret | string || | 客户端 secret |
| issuer | string || must be valid URI | OIDC Provider 的 URI,如 https://accounts.google.com” |
| issuer | string || must be valid URI | OIDC Provider 的 URI,如“https://accounts.google.com” |
| redirectUrl | string || must be valid URI | OIDC 认证过程中重定向用户的 URL。该 URL 需要满足两个条件:1. 事先已经在 OIDC Provider 中注册。2. 该 URL 和用户访问的 URL 使用同样的 OIDC 插件配置。 |
| scopes | string[] || | 该参数可以要求 OIDC Provider 返回经过身份验证的用户的更多信息。具体可以参考 https://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims 和所用的 Provider 自身的文档。 |
| idTokenHeader | string || | OIDC Provider 返回的 ID Token 将通过该 header 传给上游。默认为 `X-ID-Token`|
Expand Down
4 changes: 2 additions & 2 deletions site/content/zh-hans/docs/reference/registries/nacos.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: Nacos

`nacos` registry 对接 [Nacos](https://nacos.io/) 服务发现,将服务信息转换成 `ServiceEntry`。该 registry 支持的是 V1 API,但根据 Nacos OpenAPI 文档,亦可用于对接 Nacos 2.x。

> Nacos 2.X 版本兼容 Nacos1.X 版本的OpenAPI, 请参考文档Nacos1.X OpenAPI使用
> Nacos 2.X 版本兼容 Nacos1.X 版本的 OpenAPI, 请参考文档 Nacos1.X OpenAPI 使用
>
> https://nacos.io/zh-cn/docs/v2/guide/user/open-api.html
Expand All @@ -25,7 +25,7 @@ Nacos 1.x 没有提供订阅当前服务列表的接口,所以只能通过轮

注意:由于心跳间隔、网络延迟等原因,服务的变化可能需要几十秒之后才会引起 `ServiceEntry` 改变。尤其是因为 https://github.com/nacos-group/nacos-sdk-go/issues/139,服务中最后一个示例的移除不会导致 `ServiceEntry` 改变。另外,为了避免因为轮询失败或 Nacos 暂时不可用导致 `ServiceEntry` 被错误删除,只有在 registry 配置变化时,才会清除生成的 `ServiceEntry`

注意:因为 [nacos-sdk-go](https://github.com/nacos-group/nacos-sdk-go/) 会向文件系统写入日志和缓存,而默认情况下 HTNN 的控制面是以只读模式挂载的,所以会导致无法对接 Nacos 。解决方法是在部署 HTNN 时往 `/log``/cache` 挂载可写的目录。以通过 helm 安装 HTNN 为例,可以通过以下方式挂载可写的目录:
注意:因为 [nacos-sdk-go](https://github.com/nacos-group/nacos-sdk-go/) 会向文件系统写入日志和缓存,而默认情况下 HTNN 的控制面是以只读模式挂载的,所以会导致无法对接 Nacos。解决方法是在部署 HTNN 时往 `/log``/cache` 挂载可写的目录。以通过 helm 安装 HTNN 为例,可以通过以下方式挂载可写的目录:

```shell
helm install htnn-controller htnn/htnn-controller ... -f custom-values.yaml
Expand Down
10 changes: 9 additions & 1 deletion tools/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM --platform=$TARGETPLATFORM golang:1.21-bullseye
FROM --platform=$TARGETPLATFORM m.daocloud.io/docker.io/library/golang:1.21-bullseye

# If this image is changed, tell @spacewander to push it.
# TODO: Maybe we can push this image automatically by tag?
Expand Down Expand Up @@ -68,3 +68,11 @@ RUN VER=24.4 && \

# clang-format
RUN pip install clang-format==17.0.6

# autocorrect
RUN VER=2.11.1 && \
ARCH=$(dpkg --print-architecture) && \
wget --progress=dot:giga https://github.com/huacnlee/autocorrect/releases/download/v${VER}/autocorrect-linux-${ARCH}.tar.gz -O autocorrect.tar.gz && \
tar -zxvpf autocorrect.tar.gz && \
mv autocorrect /usr/bin && \
autocorrect --version

0 comments on commit 6109acd

Please sign in to comment.