mirror of
https://github.com/alibaba/higress.git
synced 2026-05-29 07:07:37 +08:00
add devcontainer for wasm-go plugin developing (#749)
Co-authored-by: Xunzhuo <bitliu@tencent.com>
This commit is contained in:
23
plugins/wasm-go/.devcontainer/Dockerfile
Normal file
23
plugins/wasm-go/.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
FROM higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/gateway:1.3.1
|
||||||
|
|
||||||
|
FROM ubuntu:20.04
|
||||||
|
|
||||||
|
RUN apt -y update \
|
||||||
|
&& apt install -y --no-install-recommends python3-pip net-tools vim wget make curl git 2>&1 \
|
||||||
|
&& apt install -y --reinstall ca-certificates \
|
||||||
|
&& apt-get autoremove -y && apt-get clean \
|
||||||
|
&& rm -rf /tmp/* /var/tmp/* \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
ENV PATH=/opt/tinygo/bin:/opt/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||||
|
|
||||||
|
RUN wget --no-check-certificate https://github.com/tinygo-org/tinygo/releases/download/v0.29.0/tinygo0.29.0.linux-amd64.tar.gz \
|
||||||
|
&& tar -zvxf tinygo0.29.0.linux-amd64.tar.gz -C /opt \
|
||||||
|
&& rm tinygo0.29.0.linux-amd64.tar.gz
|
||||||
|
|
||||||
|
RUN wget --no-check-certificate https://go.dev/dl/go1.19.linux-amd64.tar.gz \
|
||||||
|
&& tar -zvxf go1.19.linux-amd64.tar.gz -C /opt \
|
||||||
|
&& rm go1.19.linux-amd64.tar.gz \
|
||||||
|
&& go install -v golang.org/x/tools/gopls@latest
|
||||||
|
|
||||||
|
COPY --from=0 /usr/local/bin/envoy /usr/local/bin/envoy
|
||||||
21
plugins/wasm-go/.devcontainer/devcontainer.json
Normal file
21
plugins/wasm-go/.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "Wasm Go Dev",
|
||||||
|
// "dockerFile": "Dockerfile",
|
||||||
|
"image": "liuxr25/wasm-go:tinygo-0.29.0",
|
||||||
|
"runArgs": [
|
||||||
|
"--user=root"
|
||||||
|
],
|
||||||
|
"customizations": {
|
||||||
|
"vscode": {
|
||||||
|
"settings": {
|
||||||
|
"terminal.integrated.shell.linux": "/bin/bash",
|
||||||
|
"python.pythonPath": "/usr/bin/python3"
|
||||||
|
},
|
||||||
|
"extensions": [
|
||||||
|
"ms-python.python",
|
||||||
|
"golang.go"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
76
plugins/wasm-go/.devcontainer/gen_config.py
Normal file
76
plugins/wasm-go/.devcontainer/gen_config.py
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
plugin_name = sys.argv[1]
|
||||||
|
|
||||||
|
with open("extensions/"+plugin_name+"/config.json", "r") as f:
|
||||||
|
plugin_config = json.load(f)
|
||||||
|
|
||||||
|
config = f'''static_resources:
|
||||||
|
listeners:
|
||||||
|
- address:
|
||||||
|
socket_address:
|
||||||
|
address: 0.0.0.0
|
||||||
|
port_value: 8080
|
||||||
|
filter_chains:
|
||||||
|
- filters:
|
||||||
|
- name: envoy.filters.network.http_connection_manager
|
||||||
|
typed_config:
|
||||||
|
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
|
||||||
|
codec_type: AUTO
|
||||||
|
stat_prefix: ingress_http
|
||||||
|
route_config:
|
||||||
|
name: test
|
||||||
|
virtual_hosts:
|
||||||
|
- name: direct_response_service
|
||||||
|
domains:
|
||||||
|
- "*"
|
||||||
|
routes:
|
||||||
|
- match:
|
||||||
|
prefix: "/"
|
||||||
|
direct_response:
|
||||||
|
status: 200
|
||||||
|
body:
|
||||||
|
inline_string: "hello world\\n"
|
||||||
|
# - match:
|
||||||
|
# prefix: "/"
|
||||||
|
# route:
|
||||||
|
# cluster: service-backend
|
||||||
|
http_filters:
|
||||||
|
- name: {plugin_name}
|
||||||
|
typed_config:
|
||||||
|
"@type": type.googleapis.com/udpa.type.v1.TypedStruct
|
||||||
|
type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
|
||||||
|
value:
|
||||||
|
config:
|
||||||
|
name: wasmdemo
|
||||||
|
vm_config:
|
||||||
|
runtime: envoy.wasm.runtime.v8
|
||||||
|
code:
|
||||||
|
local:
|
||||||
|
filename: ./extensions/{plugin_name}/main.wasm
|
||||||
|
configuration:
|
||||||
|
"@type": "type.googleapis.com/google.protobuf.StringValue"
|
||||||
|
value: '{json.dumps(plugin_config)}'
|
||||||
|
- name: envoy.filters.http.router
|
||||||
|
typed_config:
|
||||||
|
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
|
||||||
|
# clusters:
|
||||||
|
# - name: service-backend
|
||||||
|
# connect_timeout: 600s
|
||||||
|
# type: STATIC
|
||||||
|
# lb_policy: ROUND_ROBIN
|
||||||
|
# load_assignment:
|
||||||
|
# cluster_name: service-backend
|
||||||
|
# endpoints:
|
||||||
|
# - lb_endpoints:
|
||||||
|
# - endpoint:
|
||||||
|
# address:
|
||||||
|
# socket_address:
|
||||||
|
# address: 127.0.0.1
|
||||||
|
# port_value: 8000
|
||||||
|
'''
|
||||||
|
|
||||||
|
with open("extensions/"+plugin_name+"/config.yaml", "w") as f:
|
||||||
|
f.write(config)
|
||||||
@@ -60,3 +60,16 @@ builder:
|
|||||||
.
|
.
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "image: ${BUILDER}"
|
@echo "image: ${BUILDER}"
|
||||||
|
|
||||||
|
local-build:
|
||||||
|
tinygo build -scheduler=none -target=wasi -gc=custom -tags='custommalloc nottinygc_finalizer' \
|
||||||
|
-o extensions/${PLUGIN_NAME}/main.wasm \
|
||||||
|
extensions/${PLUGIN_NAME}/main.go
|
||||||
|
@echo ""
|
||||||
|
@echo "wasm: extensions/${PLUGIN_NAME}/main.wasm"
|
||||||
|
|
||||||
|
local-run:
|
||||||
|
python3 .devcontainer/gen_config.py ${PLUGIN_NAME}
|
||||||
|
envoy -c extensions/${PLUGIN_NAME}/config.yaml --concurrency 0 --log-level info --component-log-level wasm:debug
|
||||||
|
|
||||||
|
local-all: local-build local-run
|
||||||
Reference in New Issue
Block a user