mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 12:47:28 +08:00
docs(wasm-go): update README related to wasm-go (#2586)
Co-authored-by: 澄潭 <zty98751@alibaba-inc.com>
This commit is contained in:
@@ -32,4 +32,4 @@ RUN set -e; \
|
|||||||
tar -C /usr/local/bin -xzf oras.tgz && rm oras.tgz; \
|
tar -C /usr/local/bin -xzf oras.tgz && rm oras.tgz; \
|
||||||
echo "done";
|
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
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ builder:
|
|||||||
--platform linux/amd64,linux/arm64 \
|
--platform linux/amd64,linux/arm64 \
|
||||||
--build-arg BASE_IMAGE=docker.io/ubuntu \
|
--build-arg BASE_IMAGE=docker.io/ubuntu \
|
||||||
--build-arg GO_VERSION=$(GO_VERSION) \
|
--build-arg GO_VERSION=$(GO_VERSION) \
|
||||||
--build-arg TINYGO_VERSION=$(TINYGO_VERSION) \
|
|
||||||
--build-arg ORAS_VERSION=$(ORAS_VERSION) \
|
--build-arg ORAS_VERSION=$(ORAS_VERSION) \
|
||||||
--build-arg HIGRESS_VERSION=$(HIGRESS_VERSION) \
|
--build-arg HIGRESS_VERSION=$(HIGRESS_VERSION) \
|
||||||
--build-arg USE_HIGRESS_TINYGO=$(USE_HIGRESS_TINYGO) \
|
--build-arg USE_HIGRESS_TINYGO=$(USE_HIGRESS_TINYGO) \
|
||||||
|
|||||||
@@ -45,16 +45,15 @@ output wasm file: extensions/request-block/plugin.wasm
|
|||||||
|
|
||||||
编译环境要求如下:
|
编译环境要求如下:
|
||||||
|
|
||||||
- Go 版本: >= 1.18 (需要支持范型特性)
|
- Go 版本: >= 1.24 (需要支持 wasm 构建特性)
|
||||||
|
|
||||||
- TinyGo 版本: >= 0.28.1
|
|
||||||
|
|
||||||
下面是本地多步骤构建 [request-block](extensions/request-block) 的例子。
|
下面是本地多步骤构建 [request-block](extensions/request-block) 的例子。
|
||||||
|
|
||||||
### step1. 编译 wasm
|
### step1. 编译 wasm
|
||||||
|
|
||||||
```bash
|
```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)。
|
详细的编译说明,包括要使用更复杂的 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
|
```bash
|
||||||
docker build -t <your_registry_hub>/request-block:1.0.0 -f <your_dockerfile> .
|
docker build -t <your_registry_hub>/request-block:2.0.0 -f <your_dockerfile> .
|
||||||
docker push <your_registry_hub>/request-block:1.0.0
|
docker push <your_registry_hub>/request-block:2.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
## 创建 WasmPlugin 资源使插件生效
|
## 创建 WasmPlugin 资源使插件生效
|
||||||
@@ -144,7 +143,7 @@ spec:
|
|||||||
block_bodies:
|
block_bodies:
|
||||||
- "foo"
|
- "foo"
|
||||||
- "bar"
|
- "bar"
|
||||||
url: oci://<your_registry_hub>/request-block:1.0.0
|
url: oci://<your_registry_hub>/request-block:2.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
所有规则会按上面配置的顺序一次执行匹配,当有一个规则匹配时,就停止匹配,并选择匹配的配置执行插件逻辑。
|
所有规则会按上面配置的顺序一次执行匹配,当有一个规则匹配时,就停止匹配,并选择匹配的配置执行插件逻辑。
|
||||||
|
|||||||
@@ -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:
|
You can also build wasm locally and copy it to a Docker image. This requires a local build environment:
|
||||||
|
|
||||||
Go version: >= 1.18
|
Go version: >= 1.24
|
||||||
|
|
||||||
TinyGo version: >= 0.25.0
|
|
||||||
|
|
||||||
The following is an example of building the plugin [request-block](extensions/request-block).
|
The following is an example of building the plugin [request-block](extensions/request-block).
|
||||||
|
|
||||||
### step1. build wasm
|
### step1. build wasm
|
||||||
|
|
||||||
```bash
|
```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
|
### step2. build and push docker image
|
||||||
@@ -63,8 +61,8 @@ COPY main.wasm plugin.wasm
|
|||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker build -t <your_registry_hub>/request-block:1.0.0 -f <your_dockerfile> .
|
docker build -t <your_registry_hub>/request-block:2.0.0 -f <your_dockerfile> .
|
||||||
docker push <your_registry_hub>/request-block:1.0.0
|
docker push <your_registry_hub>/request-block:2.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
## Apply WasmPlugin API
|
## Apply WasmPlugin API
|
||||||
@@ -83,7 +81,7 @@ spec:
|
|||||||
defaultConfig:
|
defaultConfig:
|
||||||
block_urls:
|
block_urls:
|
||||||
- "swagger.html"
|
- "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>`,
|
When the resource is applied on the Kubernetes cluster with `kubectl apply -f <your-wasm-plugin-yaml>`,
|
||||||
|
|||||||
@@ -5,14 +5,13 @@ version: 1.0.0
|
|||||||
build:
|
build:
|
||||||
# The official builder image version
|
# The official builder image version
|
||||||
builder:
|
builder:
|
||||||
go: 1.19
|
go: 1.24.4
|
||||||
tinygo: 0.28.1
|
|
||||||
oras: 1.0.0
|
oras: 1.0.0
|
||||||
# The WASM plugin project directory
|
# The WASM plugin project directory
|
||||||
input: ./
|
input: ./
|
||||||
# The output of the build products
|
# The output of the build products
|
||||||
output:
|
output:
|
||||||
# Choose between 'files' and 'image'
|
# Choose between 'files' and 'image'
|
||||||
type: files
|
type: files
|
||||||
# Destination address: when type=files, specify the local directory path, e.g., './out' or
|
# 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>'
|
# type=image, specify the remote docker repository, e.g., 'docker.io/<your_username>/<your_image>'
|
||||||
|
|||||||
@@ -5,14 +5,13 @@ version: 1.0.0
|
|||||||
build:
|
build:
|
||||||
# The official builder image version
|
# The official builder image version
|
||||||
builder:
|
builder:
|
||||||
go: 1.19
|
go: 1.24.4
|
||||||
tinygo: 0.28.1
|
|
||||||
oras: 1.0.0
|
oras: 1.0.0
|
||||||
# The WASM plugin project directory
|
# The WASM plugin project directory
|
||||||
input: ./
|
input: ./
|
||||||
# The output of the build products
|
# The output of the build products
|
||||||
output:
|
output:
|
||||||
# Choose between 'files' and 'image'
|
# Choose between 'files' and 'image'
|
||||||
type: files
|
type: files
|
||||||
# Destination address: when type=files, specify the local directory path, e.g., './out' or
|
# 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>'
|
# type=image, specify the remote docker repository, e.g., 'docker.io/<your_username>/<your_image>'
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
***Linux/macOS:***
|
***Linux/macOS:***
|
||||||
|
|
||||||
```shell
|
```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:***
|
***Windows:***
|
||||||
|
|
||||||
```powershell
|
```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 ..\..
|
||||||
```
|
```
|
||||||
|
|
||||||
## 本地运行
|
## 本地运行
|
||||||
|
|||||||
@@ -5,14 +5,13 @@ version: 1.0.0
|
|||||||
build:
|
build:
|
||||||
# The official builder image version
|
# The official builder image version
|
||||||
builder:
|
builder:
|
||||||
go: 1.19
|
go: 1.24.4
|
||||||
tinygo: 0.28.1
|
|
||||||
oras: 1.0.0
|
oras: 1.0.0
|
||||||
# The WASM plugin project directory
|
# The WASM plugin project directory
|
||||||
input: ./
|
input: ./
|
||||||
# The output of the build products
|
# The output of the build products
|
||||||
output:
|
output:
|
||||||
# Choose between 'files' and 'image'
|
# Choose between 'files' and 'image'
|
||||||
type: files
|
type: files
|
||||||
# Destination address: when type=files, specify the local directory path, e.g., './out' or
|
# 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>'
|
# type=image, specify the remote docker repository, e.g., 'docker.io/<your_username>/<your_image>'
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
.PHONY: reload
|
.PHONY: reload
|
||||||
|
|
||||||
build:
|
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:
|
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
|
./envoy -c envoy.yaml --concurrency 0 --log-level info --component-log-level wasm:debug
|
||||||
|
|
||||||
start:
|
start:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
build:
|
build:
|
||||||
go mod tidy
|
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
|
default: build
|
||||||
@@ -5,14 +5,13 @@ version: 1.0.0
|
|||||||
build:
|
build:
|
||||||
# The official builder image version
|
# The official builder image version
|
||||||
builder:
|
builder:
|
||||||
go: 1.19
|
go: 1.24.4
|
||||||
tinygo: 0.28.1
|
|
||||||
oras: 1.0.0
|
oras: 1.0.0
|
||||||
# The WASM plugin project directory
|
# The WASM plugin project directory
|
||||||
input: ./
|
input: ./
|
||||||
# The output of the build products
|
# The output of the build products
|
||||||
output:
|
output:
|
||||||
# Choose between 'files' and 'image'
|
# Choose between 'files' and 'image'
|
||||||
type: files
|
type: files
|
||||||
# Destination address: when type=files, specify the local directory path, e.g., './out' or
|
# 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>'
|
# type=image, specify the remote docker repository, e.g., 'docker.io/<your_username>/<your_image>'
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ response:
|
|||||||
go mod tidy
|
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
|
||||||
```
|
```
|
||||||
|
|
||||||
## 访问日志配置
|
## 访问日志配置
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.DEFAULT:
|
.DEFAULT:
|
||||||
build:
|
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/
|
mv main.wasm ../../../../docker-compose-test/
|
||||||
Reference in New Issue
Block a user