#!/bin/sh set -eu . "$(dirname "$0")/common.sh" xburner_init MODE="${1:-all}" SERVER_LOG="${ROOT_DIR}/.zig-cache/sample-server.log" PORT_FILE="" WORKFLOW_SAMPLE_WASM="" WORKFLOW_SAMPLE_WASM_PRESERVE=0 usage() { printf 'usage: %s [simple|workflow|grpc|all]\n' "$0" >&2 exit 2 } case "${MODE}" in simple) SERVER_KIND="python" SERVER_SCRIPT="${ROOT_DIR}/hacks/simple_fixture_server.py" SERVER_ARGS="" ;; workflow) SERVER_KIND="python" SERVER_SCRIPT="${ROOT_DIR}/hacks/workflow_fixture_server.py" SERVER_ARGS="" ;; grpc) SERVER_KIND="grpc" SERVER_SCRIPT="${ROOT_DIR}/hacks/grpc_fixture_server.go" SERVER_ARGS="" ;; all) SERVER_KIND="python" SERVER_SCRIPT="${ROOT_DIR}/hacks/sample_http_server.py" SERVER_ARGS="--mode both" ;; *) usage ;; esac if [ ! -f "${ROOT_DIR}/third_party/wamr/core/iwasm/include/wasm_export.h" ]; then printf >&2 'missing third_party dependencies; run `sh scripts/init.sh`\n' exit 1 fi mkdir -p "${ROOT_DIR}/.zig-cache" xburner_build_if_needed if [ "${MODE}" = "workflow" ] || [ "${MODE}" = "all" ]; then xburner_build_workflow_sample_if_needed fi if [ "${MODE}" = "grpc" ]; then WORKFLOW_SAMPLE_WASM="${ROOT_DIR}/samples/workflow-grpc-echo.wasm" if git -C "${ROOT_DIR}" ls-files --error-unmatch "${WORKFLOW_SAMPLE_WASM}" >/dev/null 2>&1; then WORKFLOW_SAMPLE_WASM_PRESERVE=1 fi sh "${ROOT_DIR}/scripts/build_workflow_sample_wasm.sh" \ "${ROOT_DIR}/samples/workflow-grpc-echo.c" \ "${WORKFLOW_SAMPLE_WASM}" fi if [ "${SERVER_KIND}" = "grpc" ]; then PORT_FILE=$(mktemp "${ROOT_DIR}/.zig-cache/grpc-sample-port.XXXXXX") xburner_start_grpc_fixture_server "${SERVER_LOG}" "${PORT_FILE}" else if [ -n "${SERVER_ARGS}" ]; then "${PYTHON_BIN}" "${SERVER_SCRIPT}" ${SERVER_ARGS} >"${SERVER_LOG}" 2>&1 & else "${PYTHON_BIN}" "${SERVER_SCRIPT}" >"${SERVER_LOG}" 2>&1 & fi SERVER_PID=$! fi cleanup() { xburner_stop_background_pid "${SERVER_PID:-}" if [ -n "${PORT_FILE}" ]; then rm -f "${PORT_FILE}" fi if [ "${WORKFLOW_SAMPLE_WASM_PRESERVE}" != "1" ]; then rm -f "${WORKFLOW_SAMPLE_WASM}" fi } trap cleanup EXIT INT TERM if [ "${SERVER_KIND}" = "grpc" ]; then xburner_wait_for_grpc_fixture_server "${SERVER_LOG}" "${PORT_FILE}" GRPC_FIXTURE_PORT=$(cat "${PORT_FILE}") export GRPC_FIXTURE_PORT else sleep 1 fi if [ "${MODE}" = "simple" ] || [ "${MODE}" = "all" ]; then "${XBURNER_BIN}" validate "${ROOT_DIR}/samples/simple-healthcheck.toml" "${XBURNER_BIN}" run "${ROOT_DIR}/samples/simple-healthcheck.toml" fi if [ "${MODE}" = "workflow" ] || [ "${MODE}" = "all" ]; then ( cd "${ROOT_DIR}/samples" "${XBURNER_BIN}" validate workflow-health.toml "${XBURNER_BIN}" run workflow-health.toml ) fi if [ "${MODE}" = "grpc" ]; then "${XBURNER_BIN}" validate "${ROOT_DIR}/samples/simple-grpc-echo.toml" "${XBURNER_BIN}" run "${ROOT_DIR}/samples/simple-grpc-echo.toml" ( cd "${ROOT_DIR}/samples" "${XBURNER_BIN}" validate workflow-grpc-echo.toml "${XBURNER_BIN}" run workflow-grpc-echo.toml ) fi