diff --git a/cloudbuild.yaml b/cloudbuild.yaml index b2a9fcddc7d..5b4c8025550 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -81,7 +81,7 @@ steps: waitFor: ['run_tests_tsan'] timeout: 60m entrypoint: 'bash' - args: ['./scripts/run_examples', '-s', 'base'] + args: ['./scripts/run_examples', '-s', 'base', '-c', 'rust cpp nodejs'] - name: 'gcr.io/oak-ci/oak:latest' id: run_examples_cpp @@ -90,24 +90,6 @@ steps: entrypoint: 'bash' args: ['./scripts/run_examples', '-s', 'base', '-a', 'cpp'] - # TODO(#1145): Integrate examples with multiple clients into our - # run_examples script, instead of listing them individually. - - name: 'gcr.io/oak-ci/oak:latest' - id: run_example_hello_world_nodejs - waitFor: ['run_examples_cpp'] - timeout: 15m - entrypoint: 'bash' - args: - [ - './scripts/run_example', - '-s', - 'base', - '-e', - 'hello_world', - '-c', - 'nodejs', - ] - - name: 'gcr.io/oak-ci/oak:latest' id: build_experimental waitFor: ['run_tests'] @@ -118,7 +100,7 @@ steps: # Run clang-tidy after the examples finish running, since they share the same `output_base`. - name: 'gcr.io/oak-ci/oak:latest' id: run_clang_tidy - waitFor: ['run_example_hello_world_nodejs'] + waitFor: ['run_examples_cpp'] timeout: 30m entrypoint: 'bash' args: ['./scripts/run_clang_tidy'] diff --git a/scripts/run_example b/scripts/run_example index d980e143882..942403c179b 100755 --- a/scripts/run_example +++ b/scripts/run_example @@ -6,13 +6,13 @@ source "${SCRIPTS_DIR}/common" server="base" application_language="rust" -client_language="cpp" +client_languages="cpp" buildargs="" serverargs="" while getopts "s:a:c:de:vh" opt; do case "${opt}" in h) - echo -e "Usage: ${0} [-h] [-s base|logless|none] [-a rust|cpp] [-c rust|cpp|nodejs] [-d] [-v] -e EXAMPLE [-- CLIENT_ARGS] + echo -e "Usage: ${0} [-h] [-s base|logless|none] [-a rust|cpp] [-c [rust|cpp|nodejs]...] [-d] [-v] -e EXAMPLE [-- CLIENT_ARGS] Build and run the given example Oak Application and client. @@ -26,7 +26,8 @@ Options: -a Example application variant: - rust (used by default) - cpp - -c Example client variant: + -c Example client variants. Multiple clients can be specified by space + seperating them. Eg -c \"rust cpp nodejs\". - rust - cpp (used by default) - nodejs @@ -37,7 +38,7 @@ Options after -- will be passed to the example client program." a) application_language="${OPTARG}";; c) - client_language="${OPTARG}";; + client_languages="${OPTARG}";; s) case "${OPTARG}" in base|logless|none) @@ -97,28 +98,40 @@ fi readonly CLIENT_ARGS=("${@-}") # Choose client args provided after '--'. -# Run the application client. -case "${client_language}" in - rust) - cargo run --release --target=x86_64-unknown-linux-musl --manifest-path="${SCRIPTS_DIR}/../examples/${EXAMPLE}/client/rust/Cargo.toml" -- \ - --root-tls-certificate="${SCRIPTS_DIR}/../examples/certs/local/ca.pem" \ - "${CLIENT_ARGS[@]-}" - ;; - cpp) - "./bazel-client-bin/examples/${EXAMPLE}/client/client" "${TLS_ARGS[@]}" "${ADDITIONAL_ARGS[@]-}" "${CLIENT_ARGS[@]-}" - ;; - nodejs) - nodejs_client="./examples/${EXAMPLE}/client/nodejs" - if [[ -d "${nodejs_client}" ]]; then - npm start --prefix "./examples/${EXAMPLE}/client/nodejs" - else - echo "The ${EXAMPLE} example does not contain a ${client_language} client." - exit 1 - fi - ;; - *) - echo "Invalid example client variant: ${client_language}" - exit 1;; -esac +# Run the application clients. +for client_language in $client_languages +do + case "${client_language}" in + rust) + rust_client_manifest="${SCRIPTS_DIR}/../examples/${EXAMPLE}/client/rust/Cargo.toml" + if [[ -d "${rust_client_manifest}" ]]; then + cargo run --release --target=x86_64-unknown-linux-musl --manifest-path="${rust_client_manifest}" -- \ + --root-tls-certificate="${SCRIPTS_DIR}/../examples/certs/local/ca.pem" \ + "${CLIENT_ARGS[@]-}" + else + echo "The ${EXAMPLE} example does not contain a ${client_language} client. Skipping this client." + fi + ;; + cpp) + cpp_client="./bazel-client-bin/examples/${EXAMPLE}/client/client" + if [[ -d "${cpp_client}" ]]; then + "${cpp_client}" "${TLS_ARGS[@]}" "${ADDITIONAL_ARGS[@]-}" "${CLIENT_ARGS[@]-}" + else + echo "The ${EXAMPLE} example does not contain a ${client_language} client. Skipping this client." + fi + ;; + nodejs) + nodejs_client="./examples/${EXAMPLE}/client/nodejs" + if [[ -d "${nodejs_client}" ]]; then + npm start --prefix "${nodejs_client}" + else + echo "The ${EXAMPLE} example does not contain a ${client_language} client. Skipping this client." + fi + ;; + *) + echo "Invalid example client variant: ${client_language}" + exit 1;; + esac +done kill_bg_pids diff --git a/scripts/run_examples b/scripts/run_examples index f6b44f4f922..e9244717f1b 100755 --- a/scripts/run_examples +++ b/scripts/run_examples @@ -6,7 +6,8 @@ source "${SCRIPTS_DIR}/common" server="base" application_language="rust" -while getopts "s:a:h" opt; do +client_languages="cpp" +while getopts "s:a:c:h" opt; do case "${opt}" in h) echo -e "Usage: ${0} [-s base|logless] [-a rust|cpp] @@ -16,10 +17,17 @@ while getopts "s:a:h" opt; do -a Example application variant: - rust (default) - cpp + -c Example client variants. Multiple clients can be specified by space + seperating them. Eg -c \"rust cpp nodejs\". + - rust + - cpp (used by default) + - nodejs -h Print Help (this message) and exit" exit 0;; a) application_language="${OPTARG}";; + c) + client_languages="${OPTARG}";; s) case "${OPTARG}" in base|logless) @@ -38,12 +46,12 @@ done examples="$(find examples -mindepth 2 -maxdepth 4 -type d -regex '.*/module.*/'"${application_language}"'$' | cut -d'/' -f2 | uniq)" for example in ${examples}; do if [[ "${example}" == 'aggregator' ]]; then - "${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -e aggregator -- --bucket=test --data=1:10,2:20,3:30 + "${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -c "${client_languages}" -e aggregator -- --bucket=test --data=1:10,2:20,3:30 elif [[ "${example}" == 'chat' ]]; then - "${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -e chat -- --test + "${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -c "${client_languages}" -e chat -- --test elif [[ "${example}" == 'trusted_information_retrieval' ]]; then - "${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -c rust -e trusted_information_retrieval -- --latitude 0.0 --longitude 0.0 + "${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -c "${client_languages}" -e trusted_information_retrieval -- --latitude 0.0 --longitude 0.0 else - "${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -e "${example}" + "${SCRIPTS_DIR}/run_example" -s "${server}" -a "${application_language}" -c "${client_languages}" -e "${example}" fi done