docs(wasm-go): update README related to wasm-go (#2586)

Co-authored-by: 澄潭 <zty98751@alibaba-inc.com>
This commit is contained in:
xingpiaoliang
2025-07-16 10:27:40 +08:00
committed by GitHub
parent bdc3ecab71
commit ce271849de
13 changed files with 27 additions and 35 deletions

View File

@@ -32,4 +32,4 @@ RUN set -e; \
tar -C /usr/local/bin -xzf oras.tgz && rm oras.tgz; \
echo "done";
ENV PATH=$PATH:/usr/local/go/bin:/usr/local/tinygo/bin:/usr/local/bin
ENV PATH=$PATH:/usr/local/go/bin:/usr/local/bin

View File

@@ -52,7 +52,6 @@ builder:
--platform linux/amd64,linux/arm64 \
--build-arg BASE_IMAGE=docker.io/ubuntu \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg TINYGO_VERSION=$(TINYGO_VERSION) \
--build-arg ORAS_VERSION=$(ORAS_VERSION) \
--build-arg HIGRESS_VERSION=$(HIGRESS_VERSION) \
--build-arg USE_HIGRESS_TINYGO=$(USE_HIGRESS_TINYGO) \

View File

@@ -45,16 +45,15 @@ output wasm file: extensions/request-block/plugin.wasm
编译环境要求如下:
- Go 版本: >= 1.18 (需要支持范型特性)
- TinyGo 版本: >= 0.28.1
- Go 版本: >= 1.24 (需要支持 wasm 构建特性)
下面是本地多步骤构建 [request-block](extensions/request-block) 的例子。
### step1. 编译 wasm
```bash
tinygo build -o main.wasm -scheduler=none -target=wasi -gc=custom -tags='custommalloc nottinygc_finalizer' ./extensions/request-block/main.go
GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o ./extensions/request-block/main.wasm ./extensions/request-block
```
详细的编译说明,包括要使用更复杂的 Header 状态管理机制,请参考[ Go 开发插件的最佳实践](https://higress.io/docs/latest/user/wasm-go/#3-%E7%BC%96%E8%AF%91%E7%94%9F%E6%88%90-wasm-%E6%96%87%E4%BB%B6)。
@@ -70,8 +69,8 @@ COPY main.wasm plugin.wasm
```
```bash
docker build -t <your_registry_hub>/request-block:1.0.0 -f <your_dockerfile> .
docker push <your_registry_hub>/request-block:1.0.0
docker build -t <your_registry_hub>/request-block:2.0.0 -f <your_dockerfile> .
docker push <your_registry_hub>/request-block:2.0.0
```
## 创建 WasmPlugin 资源使插件生效
@@ -144,7 +143,7 @@ spec:
block_bodies:
- "foo"
- "bar"
url: oci://<your_registry_hub>/request-block:1.0.0
url: oci://<your_registry_hub>/request-block:2.0.0
```
所有规则会按上面配置的顺序一次执行匹配,当有一个规则匹配时,就停止匹配,并选择匹配的配置执行插件逻辑。

View File

@@ -41,16 +41,14 @@ You can also use `make build-push` to build and push the image at the same time.
You can also build wasm locally and copy it to a Docker image. This requires a local build environment:
Go version: >= 1.18
TinyGo version: >= 0.25.0
Go version: >= 1.24
The following is an example of building the plugin [request-block](extensions/request-block).
### step1. build wasm
```bash
tinygo build -o main.wasm -scheduler=none -target=wasi ./extensions/request-block/main.go
GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o ./extensions/request-block/main.wasm ./extensions/request-block
```
### step2. build and push docker image
@@ -63,8 +61,8 @@ COPY main.wasm plugin.wasm
```
```bash
docker build -t <your_registry_hub>/request-block:1.0.0 -f <your_dockerfile> .
docker push <your_registry_hub>/request-block:1.0.0
docker build -t <your_registry_hub>/request-block:2.0.0 -f <your_dockerfile> .
docker push <your_registry_hub>/request-block:2.0.0
```
## Apply WasmPlugin API
@@ -83,7 +81,7 @@ spec:
defaultConfig:
block_urls:
- "swagger.html"
url: oci://<your_registry_hub>/request-block:1.0.0
url: oci://<your_registry_hub>/request-block:2.0.0
```
When the resource is applied on the Kubernetes cluster with `kubectl apply -f <your-wasm-plugin-yaml>`,

View File

@@ -5,14 +5,13 @@ version: 1.0.0
build:
# The official builder image version
builder:
go: 1.19
tinygo: 0.28.1
go: 1.24.4
oras: 1.0.0
# The WASM plugin project directory
input: ./
# The output of the build products
output:
# Choose between 'files' and 'image'
# Choose between 'files' and 'image'
type: files
# Destination address: when type=files, specify the local directory path, e.g., './out' or
# type=image, specify the remote docker repository, e.g., 'docker.io/<your_username>/<your_image>'

View File

@@ -5,14 +5,13 @@ version: 1.0.0
build:
# The official builder image version
builder:
go: 1.19
tinygo: 0.28.1
go: 1.24.4
oras: 1.0.0
# The WASM plugin project directory
input: ./
# The output of the build products
output:
# Choose between 'files' and 'image'
# Choose between 'files' and 'image'
type: files
# Destination address: when type=files, specify the local directory path, e.g., './out' or
# type=image, specify the remote docker repository, e.g., 'docker.io/<your_username>/<your_image>'

View File

@@ -5,13 +5,13 @@
***Linux/macOS:***
```shell
DOCKER_BUILDKIT=1; docker build --build-arg PLUGIN_NAME=ai-proxy --build-arg EXTRA_TAGS=proxy_wasm_version_0_2_100 --build-arg BUILDER=higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/wasm-go-builder:go1.19-tinygo0.28.1-oras1.0.0 -t ai-proxy:0.0.1 --output ./out ../..
DOCKER_BUILDKIT=1; docker build --build-arg PLUGIN_NAME=ai-proxy --build-arg EXTRA_TAGS=proxy_wasm_version_0_2_100 --build-arg BUILDER=higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/wasm-go-builder:go1.24.0-oras1.0.0 -t ai-proxy:0.0.1 --output ./out ../..
```
***Windows:***
```powershell
$env:DOCKER_BUILDKIT=1; docker build --build-arg PLUGIN_NAME=ai-proxy --build-arg EXTRA_TAGS=proxy_wasm_version_0_2_100 --build-arg BUILDER=higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/wasm-go-builder:go1.19-tinygo0.28.1-oras1.0.0 -t ai-proxy:0.0.1 --output .\out ..\..
$env:DOCKER_BUILDKIT=1; docker build --build-arg PLUGIN_NAME=ai-proxy --build-arg EXTRA_TAGS=proxy_wasm_version_0_2_100 --build-arg BUILDER=higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/wasm-go-builder:go1.24.0-oras1.0.0 -t ai-proxy:0.0.1 --output .\out ..\..
```
## 本地运行

View File

@@ -5,14 +5,13 @@ version: 1.0.0
build:
# The official builder image version
builder:
go: 1.19
tinygo: 0.28.1
go: 1.24.4
oras: 1.0.0
# The WASM plugin project directory
input: ./
# The output of the build products
output:
# Choose between 'files' and 'image'
# Choose between 'files' and 'image'
type: files
# Destination address: when type=files, specify the local directory path, e.g., './out' or
# type=image, specify the remote docker repository, e.g., 'docker.io/<your_username>/<your_image>'

View File

@@ -1,10 +1,10 @@
.PHONY: reload
build:
tinygo build -o main.wasm -scheduler=none -target=wasi -gc=custom -tags='custommalloc nottinygc_finalizer' ./main.go
GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o ./main.wasm ./main.go
reload:
tinygo build -o main.wasm -scheduler=none -target=wasi -gc=custom -tags='custommalloc nottinygc_finalizer' ./main.go
GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o ./main.wasm ./main.go
./envoy -c envoy.yaml --concurrency 0 --log-level info --component-log-level wasm:debug
start:

View File

@@ -1,5 +1,5 @@
build:
go mod tidy
tinygo build -o main.wasm -scheduler=none -target=wasi -gc=custom -tags="custommalloc nottinygc_finalizer"
GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o ./main.wasm .
default: build

View File

@@ -5,14 +5,13 @@ version: 1.0.0
build:
# The official builder image version
builder:
go: 1.19
tinygo: 0.28.1
go: 1.24.4
oras: 1.0.0
# The WASM plugin project directory
input: ./
# The output of the build products
output:
# Choose between 'files' and 'image'
# Choose between 'files' and 'image'
type: files
# Destination address: when type=files, specify the local directory path, e.g., './out' or
# type=image, specify the remote docker repository, e.g., 'docker.io/<your_username>/<your_image>'

View File

@@ -68,7 +68,7 @@ response:
go mod tidy
# 编译
tinygo build -o main.wasm -scheduler=none -target=wasi -gc=custom -tags="custommalloc nottinygc_finalizer" ./main.go
GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o ./main.wasm ./main.go
```
## 访问日志配置

View File

@@ -1,4 +1,4 @@
.DEFAULT:
build:
tinygo build -o main.wasm -scheduler=none -target=wasi -gc=custom -tags='custommalloc nottinygc_finalizer' ./main.go
GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o ./main.wasm .
mv main.wasm ../../../../docker-compose-test/