verifying-taubyte-functions
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVerifying Taubyte Functions
验证Taubyte函数
When to use
适用场景
- "Does this Go function compile to WASM?"
- "Smoke-test the function before pushing"
- "Check whether the deployed function actually responds"
- Need to hit a URL from the browser
*.localtau - Avoiding root-owned artifacts left behind by
tau build
- "这个Go函数能否编译为WASM?"
- "推送前对函数进行冒烟测试"
- "检查已部署的函数是否能正常响应"
- 需要从浏览器访问格式的URL
*.localtau - 避免留下root权限的产物
tau build
Two distinct things
两类不同的验证场景
| Goal | Use this section |
|---|---|
| Compile WASM locally to confirm the source builds | "Local Go WASM verify (Docker)" below |
| Hit a function running on Dream | "Runtime verification (Dream gateway)" below |
tau buildgo.sumlib/main.go| 目标 | 参考章节 |
|---|---|
| 本地编译WASM以确认源码可构建 | 下方的「本地Go WASM验证(Docker)」 |
| 访问运行在Dream上的函数 | 下方的「运行时验证(Dream网关)」 |
tau buildgo.sumlib/main.goLocal Go WASM verify (Docker)
本地Go WASM验证(Docker)
Run from the function root (the directory containing and the source files):
go.mod.gobash
cd <project>/code/functions/<fn>
mkdir -p out
docker run --rm \
-e CODE=/src \
-e GOPROXY=https://proxy.golang.org,direct \
-e GOSUMDB=sum.golang.org \
-v "$(pwd)/out:/out" \
--mount type=bind,src="$(pwd)",dst=/src_ro,ro \
--mount type=tmpfs,dst=/src \
taubyte/go-wasi:latest /bin/bash -lc '
set -euo pipefail
rsync -a --delete /src_ro/ /src/ 2>/dev/null || cp -a /src_ro/. /src/
cd /src
export CODE=/src
# go-wasi:latest: go/tinygo live under /usr/local/* but are often missing from PATH in non-login shells (same class of env Dream uses when running build.sh).
export PATH="/usr/local/go/bin:/usr/local/tinygo/bin:${PATH}"
source /utils/wasm.sh
ls -la /out
'Why this shape:
- makes your real source read-only inside the container.
--mount type=bind,...,ro - provides a writable scratch copy at
--mount type=tmpfs,dst=/src./src - The script s the read-only source into the tmpfs, builds there, and writes only into the host-mapped
rsyncdirectory.out/ - Result: no root-owned files appear in your real source tree.
从函数根目录(包含和源码文件的目录)执行:
go.mod.gobash
cd <project>/code/functions/<fn>
mkdir -p out
docker run --rm \
-e CODE=/src \
-e GOPROXY=https://proxy.golang.org,direct \
-e GOSUMDB=sum.golang.org \
-v "$(pwd)/out:/out" \
--mount type=bind,src="$(pwd)",dst=/src_ro,ro \
--mount type=tmpfs,dst=/src \
taubyte/go-wasi:latest /bin/bash -lc '
set -euo pipefail
rsync -a --delete /src_ro/ /src/ 2>/dev/null || cp -a /src_ro/. /src/
cd /src
export CODE=/src
# go-wasi:latest: go/tinygo live under /usr/local/* but are often missing from PATH in non-login shells (same class of env Dream uses when running build.sh).
export PATH="/usr/local/go/bin:/usr/local/tinygo/bin:${PATH}"
source /utils/wasm.sh
ls -la /out
'脚本设计思路:
- 将本地真实源码以只读方式挂载到容器内。
--mount type=bind,...,ro - 在
--mount type=tmpfs,dst=/src路径提供可写的临时副本。/src - 脚本将只读源码同步到tmpfs中,在tmpfs中执行构建,仅将产物写入宿主机映射的目录。
out/ - 结果:本地源码树中不会出现root权限的文件。
Naive bind-mount (avoid)
简易绑定挂载(不推荐)
Running (or similar) with read-write and no tmpfs scratch layer can drop root-owned , , moved sources, or zips into git. Never commit that junk — use the tmpfs pattern above; must be clean before (field-reported footgun).
taubyte/go-wasi$(pwd):/srclib/main.gogit statustau push直接以读写方式将挂载到容器(不使用tmpfs临时层),会在git目录中留下root权限的、、移动的源码或压缩包。绝对不要提交这些垃圾文件——请使用上述tmpfs方案;执行前必须保证显示干净(这是用户反馈的常见陷阱)。
$(pwd):/srctaubyte/go-wasilib/main.gotau pushgit statusNotes
注意事项
- The function's declares the build image (e.g.
.taubyte/config.yamlortaubyte/go-wasi:latest). Use the same image in the local recipe as the cloud will use.taubyte/go-wasi:v2 - Don't use in non-TTY environments — it fails with
-it. The recipe above already omitscannot attach stdin to a TTY-enabled container.-it - The recipe is intended only when the user explicitly asks for local build verification. Default Taubyte workflow is "push to GitHub → cloud builds".
- +
taubyte/go-wasi:latest: the image installsPATHandgoundertinygoand/usr/local/go/bin. Non-login shells (this Docker block, Dream/monkey running/usr/local/tinygo/bin) often start with a minimal.taubyte/build.sh, soPATHcan fail with/utils/wasm.shunless you exportgo: command not found(shown in the recipe above) or put the samePATHat the top ofexportbefore.taubyte/build.sh— see configuring-taubyte-build-runtime.. /utils/wasm.sh
- 函数的文件声明了构建镜像(如
.taubyte/config.yaml或taubyte/go-wasi:latest)。本地脚本使用的镜像必须与云端使用的一致。taubyte/go-wasi:v2 - 在非TTY环境中不要使用参数——会报错
-it。上述脚本已省略cannot attach stdin to a TTY-enabled container。-it - 该脚本仅适用于用户明确需要本地构建验证的场景。Taubyte的默认工作流是「推送到GitHub → 云端构建」。
- +
taubyte/go-wasi:latest:该镜像将PATH和go安装在tinygo和/usr/local/go/bin路径下。非登录shell(如本Docker块、Dream/monkey运行/usr/local/tinygo/bin时)通常使用最小化.taubyte/build.sh,因此如果不导出PATH(如上述脚本所示)或在PATH顶部添加同样的.taubyte/build.sh命令再执行export,. /utils/wasm.sh可能会报错**/utils/wasm.sh**——详情请参考configuring-taubyte-build-runtime。go: command not found
Output expectation
预期输出
After the run, on the host should contain at least the WASM artifact and any expected build outputs. If is empty, the build failed; re-read the container's stdout for compile errors.
out/out/执行完成后,宿主机的目录应至少包含WASM产物和其他预期构建输出。如果为空,说明构建失败;请重新查看容器的标准输出以排查编译错误。
out/out/Runtime verification (Dream gateway)
运行时验证(Dream网关)
To curl a function running on Dream, you need (1) the gateway port and (2) the function's domain FQDN.
bash
undefined要curl访问运行在Dream上的函数,你需要(1)网关端口和(2)函数的域名FQDN。
bash
undefined1. Discover gateway port
1. 发现网关端口
dream status gateway
often prints a blank line before @ http://...
; awk '/@ http/{print $3}' can return empty — prefer:
dream status gateway@ http://...dream status gateway
常在@ http://...
前输出空行;使用awk '/@ http/{print $3}'可能返回空值——推荐使用:
dream status gateway@ http://...GW=$(dream status gateway default | grep -Eo 'http://[0-9.]+:[0-9]+' | head -n1)
GW=$(dream status gateway default | grep -Eo 'http://[0-9.]+:[0-9]+' | head -n1)
2. Read the function's FQDN from its domain YAML
2. 从域名YAML文件中读取函数的FQDN
FQDN=$(awk '/^fqdn:/{print $2; exit}' config/domains/<domain>.yaml)
FQDN=$(awk '/^fqdn:/{print $2; exit}' config/domains/<domain>.yaml)
3. Curl with Host header
3. 携带Host头执行curl请求
curl -i -H "Host: $FQDN" "$GW/<path>"
Concrete example for a `ping_pong`-templated function on `/ping`:
```bash
curl -i -H "Host: <random>.default.localtau" "http://127.0.0.1:<gateway_port>/ping"curl -i -H "Host: $FQDN" "$GW/<path>"
针对`ping_pong`模板函数访问`/ping`路径的具体示例:
```bash
curl -i -H "Host: <random>.default.localtau" "http://127.0.0.1:<gateway_port>/ping"Expected: HTTP 200 and body "PONG"
预期结果:HTTP 200状态码,响应体为"PONG"
undefinedundefinedHosts file for *.localtau
(browser convenience)
*.localtau*.localtau
的Hosts文件配置(浏览器便捷访问)
*.localtauBrowsers don't let you set a header trivially. To hit directly, map the generated FQDN to localhost:
Host:http://<fqdn>/<path>bash
sudo sh -c 'echo "127.0.0.1 <random>.default.localtau" >> /etc/hosts'浏览器无法轻松设置头。要直接访问,需将生成的FQDN映射到localhost:
Host:http://<fqdn>/<path>bash
sudo sh -c 'echo "127.0.0.1 <random>.default.localtau" >> /etc/hosts'or edit /etc/hosts manually:
或手动编辑/etc/hosts文件:
127.0.0.1 <random>.default.localtau
127.0.0.1 <random>.default.localtau
After the mapping, browsing to `http://<random>.default.localtau:<gateway_port>/<path>` works directly.
Re-run for each new generated FQDN you want to open in a browser. To find the FQDN:
```bash
awk '/^fqdn:/{print $2; exit}' config/domains/<domain>.yaml
完成映射后,即可直接在浏览器中访问`http://<random>.default.localtau:<gateway_port>/<path>`。
如需在浏览器中打开新生成的FQDN,请重复上述操作。查找FQDN的命令:
```bash
awk '/^fqdn:/{print $2; exit}' config/domains/<domain>.yamlWorkflow checklists
工作流检查清单
Pre-push local smoke
推送前本地冒烟测试
Smoke check progress:
- [ ] cd into function root (has go.mod)
- [ ] Run Docker WASM build recipe (above)
- [ ] Confirm out/ contains expected artifacts
- [ ] Inspect container stdout for errors
- [ ] If green, proceed to push冒烟测试进度:
- [ ] 进入函数根目录(包含go.mod)
- [ ] 执行Docker WASM构建脚本(上述内容)
- [ ] 确认out/目录包含预期产物
- [ ] 检查容器标准输出是否有错误
- [ ] 若一切正常,继续执行推送Post-deploy runtime check
部署后运行时检查
Runtime check progress:
- [ ] dream status gateway <universe> -> note port (use grep -Eo 'http://[0-9.]+:[0-9]+' if awk returns empty)
- [ ] Read FQDN from config/domains/<domain>.yaml
- [ ] curl -i -H "Host: <fqdn>" http://127.0.0.1:<port>/<path>
- [ ] Expect HTTP 200 + expected body
- [ ] If non-200, see diagnosing-dream-builds for build/log inspection运行时检查进度:
- [ ] 执行dream status gateway <universe> -> 记录端口(若awk返回空值,使用grep -Eo 'http://[0-9.]+:[0-9]+'命令)
- [ ] 从config/domains/<domain>.yaml中读取FQDN
- [ ] 执行curl -i -H "Host: <fqdn>" http://127.0.0.1:<port>/<path>
- [ ] 预期结果:HTTP 200状态码 + 预期响应体
- [ ] 若状态码非200,请参考diagnosing-dream-builds技能检查构建/日志Gotchas
注意事项
- Don't run casually. It works, but it can leave root-owned artifacts (
tau build,lib/,main.go) in the function tree. Never commit those — they break Dream/go-wasi builds (mixed packages, import cycles). Prefer the Docker recipe above; delete +artifact.zipif they appear, and addgit rm --cachedpatterns for them..gitignore - Wrong header = 404. Dream's gateway routes by
Host:; without the right header you'll seeHost:even with a healthy function. Re-read the FQDN from the domain YAML.404 - Some gateways require to include the port. If you see
Hostwhile the gateway is reachable, retry withno substrate match found.-H "Host: <fqdn>:<gateway_port>" - Stale gateway port across sessions. is the canonical source; ports change between Dream runs.
dream status gateway - Generated FQDNs only resolve via hosts mapping. They aren't real DNS; the browser must be told .
127.0.0.1 - Remote vs Dream: this skill is Dream-focused. For remote clouds, hit the FQDN directly over the public DNS the cloud configured.
- 不要随意运行。它虽然能工作,但会在函数目录中留下root权限的产物(如
tau build、lib/、main.go)。绝对不要提交这些文件——它们会破坏Dream/go-wasi的构建(如包冲突、导入循环)。优先使用上述Docker脚本;若已出现此类文件,请删除并执行artifact.zip,同时在git rm --cached中添加对应的忽略规则。.gitignore - 错误的头会导致404。Dream网关通过
Host:头路由请求;即使函数正常运行,若无正确的头信息也会返回Host:。请重新从域名YAML文件中确认FQDN。404 - 部分网关要求头包含端口。若网关可访问但返回
Host,请尝试使用no substrate match found重新请求。-H "Host: <fqdn>:<gateway_port>" - 会话间网关端口可能变化。是获取端口的权威方式;Dream重启后端口可能改变。
dream status gateway - 生成的FQDN仅能通过Hosts映射解析。它们不是真实的DNS域名;必须告知浏览器将其指向。
127.0.0.1 - 远程云与Dream的区别:本技能针对Dream环境。对于远程云平台,可直接通过云配置的公共DNS访问FQDN。
Related skills
相关技能
- — gateway port discovery
inspecting-dream-status - — push and inject before runtime checks
triggering-dream-builds - — when a runtime check fails
diagnosing-dream-builds - — the matching
building-taubyte-websites-header pattern for sitesHost:
- —— 网关端口发现
inspecting-dream-status - —— 推送并注入代码后再执行运行时检查
triggering-dream-builds - —— 运行时检查失败时的排查
diagnosing-dream-builds - —— 网站对应的
building-taubyte-websites头匹配规则Host: