-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(util) replicate runtimes workflow to sdks
- Loading branch information
Showing
8 changed files
with
237 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
SCRIPT_NAME=$(basename $0) | ||
NGX_WASM_DIR=${NGX_WASM_DIR:-"$( | ||
cd $(dirname $(dirname ${0})) | ||
pwd -P | ||
)"} | ||
if [[ ! -f "${NGX_WASM_DIR}/util/_lib.sh" ]]; then | ||
echo "Unable to source util/_lib.sh" >&2 | ||
exit 1 | ||
fi | ||
|
||
source $NGX_WASM_DIR/util/_lib.sh | ||
|
||
############################################################################### | ||
|
||
show_usage() { | ||
cat << EOF | ||
Usage: | ||
$SCRIPT_NAME -S <sdk> [options] | ||
EOF | ||
} | ||
|
||
show_help() { | ||
cat << EOF | ||
Download or build a proxy-wasm SDK. | ||
EOF | ||
show_usage | ||
cat << EOF | ||
Arguments: | ||
-S, --sdk <sdk> proxy-wasm SDK to build (e.g. 'go'). | ||
Options: | ||
--download Download a proxy-wasm SDK source code. | ||
This is the default. | ||
--build Build a proxy-wasm SDK and example filters. | ||
-V, --sdk-ver <ver> proxy-wasm SDK version to build (e.g. 'v0.2.1') | ||
-f, --force, --clean Force a clean download or build. | ||
-h, --help Print this message and exit. | ||
EOF | ||
} | ||
|
||
############################################################################### | ||
|
||
MODE="download" | ||
|
||
while [[ "$1" ]]; do | ||
case "$1" in | ||
-S|--sdk) | ||
shift | ||
PROXY_WASM_SDK="$1" | ||
;; | ||
-V|--sdk-ver) | ||
shift | ||
PROXY_WASM_SDK_VERSION="$1" | ||
;; | ||
--download) | ||
MODE="download" | ||
;; | ||
--build) | ||
MODE="build" | ||
;; | ||
--clean|--force|-f) | ||
CLEAN="clean" | ||
;; | ||
-h|--help) | ||
show_help | ||
exit 0 | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
if [[ -z "$PROXY_WASM_SDK" ]]; then | ||
show_usage | ||
fatal "Bad usage. Consult --help" | ||
fi | ||
|
||
if [[ -z "$PROXY_WASM_SDK_VERSION" ]]; then | ||
PROXY_WASM_SDK_VERSION="$(get_default_proxy_wasm_sdk_version "$PROXY_WASM_SDK")" | ||
fi | ||
|
||
BUILD_SCRIPT=$NGX_WASM_DIR/util/sdks/$PROXY_WASM_SDK.sh | ||
|
||
if "$BUILD_SCRIPT" "$MODE" "$PROXY_WASM_SDK_VERSION" "$CLEAN"; then | ||
exit 0 | ||
|
||
else | ||
notice "$MODE failed" | ||
exit 1 | ||
fi |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
SCRIPT_NAME=$(basename $0) | ||
NGX_WASM_DIR=${NGX_WASM_DIR:-"$( | ||
cd $(dirname $(dirname $(dirname ${0}))) | ||
pwd -P | ||
)"} | ||
if [[ ! -f "${NGX_WASM_DIR}/util/_lib.sh" ]]; then | ||
echo "Unable to source util/_lib.sh" >&2 | ||
exit 1 | ||
fi | ||
|
||
source $NGX_WASM_DIR/util/_lib.sh | ||
|
||
############################################################################### | ||
|
||
download_go_sdk() { | ||
local version="$1" | ||
local clean="$2" | ||
|
||
if [[ "$clean" = "clean" ]]; then | ||
rm -rfv "$DIR_PROXY_WASM_GO_SDK" | ||
fi | ||
|
||
if [[ -d "$DIR_PROXY_WASM_GO_SDK" ]]; then | ||
notice "updating the proxy-wasm-go-sdk repository..." | ||
pushd $DIR_PROXY_WASM_GO_SDK | ||
git fetch | ||
git reset --hard $version | ||
popd | ||
else | ||
notice "cloning proxy-wasm-go-sdk repository, version ${version}..." | ||
git clone \ | ||
-c advice.detachedHead=false --depth 1 \ | ||
--branch $version \ | ||
https://github.com/tetratelabs/proxy-wasm-go-sdk.git \ | ||
$DIR_PROXY_WASM_GO_SDK | ||
fi | ||
} | ||
|
||
build_go_sdk() { | ||
local version="$1" | ||
local clean="$2" | ||
|
||
if [[ ! -x "$(command -v tinygo)" ]]; then | ||
fatal "missing 'tinygo', is TinyGo installed?" | ||
fi | ||
|
||
local hasher=sha1sum | ||
if [[ ! -x "$(command -v $hasher)" ]]; then | ||
hasher=shasum | ||
fi | ||
|
||
local hash_src=$(find $DIR_PROXY_WASM_GO_SDK -type f \( -name '*.go' -or -name '*.mod' \) -exec $hasher {} \; \ | ||
| $hasher | awk '{ print $1 }') | ||
|
||
if [[ -d "$DIR_PATCHED_PROXY_WASM_GO_SDK" \ | ||
&& -f "$DIR_PATCHED_PROXY_WASM_GO_SDK/.hash" \ | ||
&& $(cat "$DIR_PATCHED_PROXY_WASM_GO_SDK/.hash") == $(echo $hash_src) ]]; | ||
then | ||
exit | ||
fi | ||
|
||
rm -rf $DIR_PATCHED_PROXY_WASM_GO_SDK | ||
cp -R $DIR_PROXY_WASM_GO_SDK $DIR_PATCHED_PROXY_WASM_GO_SDK | ||
echo $hash_src > "$DIR_PATCHED_PROXY_WASM_GO_SDK/.hash" | ||
|
||
pushd $DIR_PATCHED_PROXY_WASM_GO_SDK | ||
set +e | ||
patch --forward --ignore-whitespace examples/http_auth_random/main.go <<'EOF' | ||
@@ -21,7 +21,7 @@ import ( | ||
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" | ||
) | ||
-const clusterName = "httpbin" | ||
+const clusterName = "httpbin:2000" | ||
func main() { | ||
proxywasm.SetVMContext(&vmContext{}) | ||
EOF | ||
patch --forward --ignore-whitespace examples/dispatch_call_on_tick/main.go <<'EOF' | ||
@@ -88,7 +88,7 @@ func (ctx *pluginContext) OnTick() { | ||
} else { | ||
headers = append(headers, [2]string{":path", "/fail"}) | ||
} | ||
- if _, err := proxywasm.DispatchHttpCall("web_service", headers, nil, nil, 5000, ctx.callBack); err != nil { | ||
+ if _, err := proxywasm.DispatchHttpCall("web_service:81", headers, nil, nil, 5000, ctx.callBack); err != nil { | ||
proxywasm.LogCriticalf("dispatch httpcall failed: %v", err) | ||
} | ||
} | ||
EOF | ||
set -e | ||
|
||
notice "compiling Go examples..." | ||
|
||
make build.examples || exit 0 | ||
|
||
cd examples | ||
|
||
find . -name "*.wasm" | while read f; do | ||
# flatten module names, for example: | ||
# "./shared_queue/sender/main.wasm" to "go_shared_queue_sender.wasm" | ||
name=$(echo "$f" | sed 's,./\(.*\)/main.wasm,go_\1.wasm,;s,/,_,g') | ||
cp -av "$f" "$DIR_TESTS_LIB_WASM/$name" | ||
done | ||
popd | ||
} | ||
|
||
############################################################################### | ||
|
||
mode="$1" | ||
version="$2" | ||
clean="$3" | ||
|
||
if [ "$mode" = "download" ]; then | ||
download_go_sdk "$version" "$clean" | ||
else | ||
build_go_sdk "$version" "$clean" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters