From f67b5545664a0e5bb77ceb1b8c5b22fca4e4f4cb Mon Sep 17 00:00:00 2001 From: Razieh Behjati Date: Wed, 10 Jun 2020 14:00:12 +0100 Subject: [PATCH] Move top-level Cargo.toml to oak/server * Moves top-level `Cargo.toml` and `Cargo.lock` to `oak/server` * Updates the scripts and the README files accordingly * Removes `--target-dir` flags in `scripts/build_example` --- BUILD | 2 +- examples/aggregator/README.md | 15 +++++++++------ examples/aggregator/scripts/run_backend | 2 +- examples/aggregator/scripts/run_server | 4 ++-- examples/aggregator/server/BUILD | 2 +- examples/authentication/README.md | 4 ++-- examples/hello_world/gcp/BUILD | 1 - examples/hello_world/gcp/config.json | 3 +-- oak/server/BUILD | 2 +- Cargo.lock => oak/server/Cargo.lock | 0 Cargo.toml => oak/server/Cargo.toml | 13 ++++++------- oak/server/rust/oak_loader/src/main.rs | 2 +- runner/src/main.rs | 6 +++--- scripts/build_example | 4 ++-- scripts/build_gh_pages | 2 +- scripts/check_docs | 6 ++---- scripts/common | 2 +- scripts/deploy_example_gcp | 5 +++-- scripts/run_server | 2 +- 19 files changed, 38 insertions(+), 39 deletions(-) rename Cargo.lock => oak/server/Cargo.lock (100%) rename Cargo.toml => oak/server/Cargo.toml (52%) diff --git a/BUILD b/BUILD index dada619bea1..6c4c66bc13a 100644 --- a/BUILD +++ b/BUILD @@ -32,4 +32,4 @@ exports_files(srcs = glob(["target/x86_64-unknown-linux-musl/release/*oak_loader exports_files(srcs = glob(["examples/target/wasm32-unknown-unknown/release/*.wasm"])) # These files are necessary for the backend server in the Aggregator example application. -exports_files(srcs = glob(["target/release/aggregator_*"])) +exports_files(srcs = glob(["examples/target/x86_64-unknown-linux-musl/release/aggregator_*"])) diff --git a/examples/aggregator/README.md b/examples/aggregator/README.md index b5b3ef40e4a..9cc105973ee 100644 --- a/examples/aggregator/README.md +++ b/examples/aggregator/README.md @@ -16,7 +16,9 @@ Build and run the Backend with the following command: ```bash export RUST_LOG=info -cargo run --release --package=aggregator_backend +cargo run --release --manifest-path=examples/aggregator/backend/Cargo.toml -- \ + --grpc-tls-private-key="" \ + --grpc-tls-certificate="" ``` Backend code is in the `backend` directory. @@ -36,11 +38,12 @@ Build and run the Aggregator with the following command: ```bash ./scripts/build_example -e aggregator -./scripts/build_server -s rust -./bazel-clang-bin/oak/server/loader/oak_runner \ +./scripts/build_server -s base +cargo run --release --target=x86_64-unknown-linux-musl --manifest-path=oak/server/rust/oak_loader/Cargo.toml -- \ --application=./bazel-client-bin/examples/aggregator/config/config.bin \ - --private_key=./examples/certs/local/local.key \ - --cert_chain=./examples/certs/local/local.pem + --grpc-tls-private-key=./examples/certs/local/local.key \ + --grpc-tls-certificate=./examples/certs/local/local.pem \ + --root-tls-certificate=./examples/certs/local/ca.pem ``` Aggregator code is in `common` and `module` directories (where `common` defines @@ -104,6 +107,6 @@ Deployment requires Docker images to be uploaded to the the following command: ```bash -./scripts/build_example -e aggregator -i rust +./scripts/build_example -e aggregator -i base ./examples/aggregator/scripts/docker_push ``` diff --git a/examples/aggregator/scripts/run_backend b/examples/aggregator/scripts/run_backend index a08e216ff76..e5f86737e89 100755 --- a/examples/aggregator/scripts/run_backend +++ b/examples/aggregator/scripts/run_backend @@ -5,6 +5,6 @@ readonly SCRIPTS_DIR="$(dirname "$(readlink -f "$0")")" # shellcheck source=scripts/common source "${GLOBAL_SCRIPTS_DIR}/common" -exec cargo run --release --package=aggregator_backend \ +exec cargo run --release --manifest-path=examples/aggregator/backend/Cargo.toml -- \ --grpc-tls-private-key="${GLOBAL_SCRIPTS_DIR}/../examples/certs/local/local.key" \ --grpc-tls-certificate="${GLOBAL_SCRIPTS_DIR}/../examples/certs/local/local.pem" diff --git a/examples/aggregator/scripts/run_server b/examples/aggregator/scripts/run_server index 9d61706f1c1..39947554b48 100755 --- a/examples/aggregator/scripts/run_server +++ b/examples/aggregator/scripts/run_server @@ -5,11 +5,11 @@ readonly SCRIPTS_DIR="$(dirname "$(readlink -f "$0")")" # shellcheck source=scripts/common source "${GLOBAL_SCRIPTS_DIR}/common" -"${GLOBAL_SCRIPTS_DIR}/build_server" -s rust +"${GLOBAL_SCRIPTS_DIR}/build_server" -s base "${GLOBAL_SCRIPTS_DIR}/build_example" -e aggregator readonly APPLICATION="${PWD}/bazel-client-bin/examples/aggregator/config/config.bin" -exec cargo run --release --target=x86_64-unknown-linux-musl --package=oak_loader -- \ +exec cargo run --release --target=x86_64-unknown-linux-musl --manifest-path=oak/server/rust/oak_loader/Cargo.toml -- \ --application="${APPLICATION}" \ --grpc-tls-private-key="${GLOBAL_SCRIPTS_DIR}/../examples/certs/local/local.key" \ --grpc-tls-certificate="${GLOBAL_SCRIPTS_DIR}/../examples/certs/local/local.pem" \ diff --git a/examples/aggregator/server/BUILD b/examples/aggregator/server/BUILD index db307eb835f..f06c73421d0 100644 --- a/examples/aggregator/server/BUILD +++ b/examples/aggregator/server/BUILD @@ -36,7 +36,7 @@ container_image( "./aggregator_backend", ], files = [ - "//:target/release/aggregator_backend", + "//:examples/target/x86_64-unknown-linux-musl/release/aggregator_backend", ], ports = [ "8888/tcp", # Backend gRPC port. diff --git a/examples/authentication/README.md b/examples/authentication/README.md index d6e552a48e1..a756ec60b31 100644 --- a/examples/authentication/README.md +++ b/examples/authentication/README.md @@ -21,7 +21,7 @@ The Oak server can be run with the OpenID Connect authentication service enabled using the --oidc-client flag: ```bash -cargo run --package=oak_loader -- \ +cargo run --manifest-path=oak/server/rust/oak_loader/Cargo.toml -- \ --application= \ --grpc-tls-private-key= \ --grpc-tls-certificate= \ @@ -55,7 +55,7 @@ While the Oak server is running with the OpenID Connect authentication service enabled, the client can be executed using: ```bash -cargo run --package=auth_client +cargo run --manifest-path=examples/authentication/client/Cargo.toml ``` The client will log the returned identity token as an informational log message. diff --git a/examples/hello_world/gcp/BUILD b/examples/hello_world/gcp/BUILD index 846e5208a07..c37c760cbd8 100644 --- a/examples/hello_world/gcp/BUILD +++ b/examples/hello_world/gcp/BUILD @@ -26,7 +26,6 @@ assemble_packer( name = "assemble-oak-gcp-hello-world", config = ":config.json", files = { - "//oak/server/loader:oak_runner": "oak_runner", "//examples/hello_world/config:config.bin": "config.bin", }, ) diff --git a/examples/hello_world/gcp/config.json b/examples/hello_world/gcp/config.json index 28099db3eae..9edf7e8161f 100644 --- a/examples/hello_world/gcp/config.json +++ b/examples/hello_world/gcp/config.json @@ -31,8 +31,7 @@ "type": "shell", "inline": [ "sudo mkdir /opt/oak", - "sudo cp /tmp/deployment/* /opt/oak/", - "sudo chmod +x /opt/oak/oak_runner" + "sudo cp /tmp/deployment/* /opt/oak/" ] } ] diff --git a/oak/server/BUILD b/oak/server/BUILD index cc8403528d6..1081c83899e 100644 --- a/oak/server/BUILD +++ b/oak/server/BUILD @@ -28,7 +28,7 @@ container_image( name = "oak_docker", base = "@cc_image//image", files = [ - "//:target/x86_64-unknown-linux-musl/release/oak_loader", + "target/x86_64-unknown-linux-musl/release/oak_loader", ], ports = [ "8080/tcp", # Oak Application gRPC port. diff --git a/Cargo.lock b/oak/server/Cargo.lock similarity index 100% rename from Cargo.lock rename to oak/server/Cargo.lock diff --git a/Cargo.toml b/oak/server/Cargo.toml similarity index 52% rename from Cargo.toml rename to oak/server/Cargo.toml index 32e3081a1d7..1c22d0b1d4a 100644 --- a/Cargo.toml +++ b/oak/server/Cargo.toml @@ -1,6 +1,5 @@ [workspace] -members = ["oak/server/rust/oak_loader", "oak/server/rust/oak_runtime"] -exclude = ["third_party/expect", "third_party/roughenough"] +members = ["rust/oak_loader", "rust/oak_runtime"] # Patch dependencies on oak crates so that they refer to the versions within this same repository. # @@ -9,9 +8,9 @@ exclude = ["third_party/expect", "third_party/roughenough"] # > explicit about the dependency relationships between the crates. [patch.crates-io] # Oak. -oak_abi = { path = "oak_abi" } -oak_loader = { path = "oak/server/rust/oak_loader" } -oak_runtime = { path = "oak/server/rust/oak_runtime" } -oak_utils = { path = "oak_utils" } +oak_abi = { path = "../../oak_abi" } +oak_loader = { path = "rust/oak_loader" } +oak_runtime = { path = "rust/oak_runtime" } +oak_utils = { path = "../../oak_utils" } # Third party. -roughenough = { path = "third_party/roughenough" } +roughenough = { path = "../../third_party/roughenough" } diff --git a/oak/server/rust/oak_loader/src/main.rs b/oak/server/rust/oak_loader/src/main.rs index 345d5e0fcf1..a64a6020c4d 100644 --- a/oak/server/rust/oak_loader/src/main.rs +++ b/oak/server/rust/oak_loader/src/main.rs @@ -19,7 +19,7 @@ //! Invoke with: //! //! ```shell -//! cargo run --package=oak_loader -- \ +//! cargo run --manifest-path=oak/server/rust/oak_loader/Cargo.toml -- \ //! --application= \ //! --grpc-tls-private-key= \ //! --grpc-tls-certificate= \ diff --git a/runner/src/main.rs b/runner/src/main.rs index b143609755b..b5d7cd41738 100644 --- a/runner/src/main.rs +++ b/runner/src/main.rs @@ -20,7 +20,7 @@ //! To invoke, run the following command from the root of the repository: //! //! ``` -//! cargo run --package=runner +//! cargo run --manifest-path=runner/Cargo.toml //! ``` use colored::*; @@ -210,7 +210,7 @@ fn build_server(opt: &BuildServer) -> Step { "build", "--release", "--target=x86_64-unknown-linux-musl", - "--package=oak_loader", + "--manifest-path=oak/server/rust/oak_loader/Cargo.toml", ], ), }, @@ -307,7 +307,7 @@ fn run_example_server(application_file: &str) -> Cmd { "run", "--release", "--target=x86_64-unknown-linux-musl", - "--package=oak_loader", + "--manifest-path=oak/server/rust/oak_loader/Cargo.toml", "--", "--grpc-tls-private-key=./examples/certs/local/local.key", "--grpc-tls-certificate=./examples/certs/local/local.pem", diff --git a/scripts/build_example b/scripts/build_example index 8b62ff8894b..4eaa0ebad0e 100755 --- a/scripts/build_example +++ b/scripts/build_example @@ -56,13 +56,13 @@ case "${application_language}" in for module in examples/"${EXAMPLE}"/module*/rust/Cargo.toml; do # Use a separate target dir for Wasm build artifacts. The precise name is not relevant, but it # should end with `target` so that it gets automatically ignored by our `.gitignore`. - cargo build --release --target-dir=examples/target --target=wasm32-unknown-unknown --manifest-path="${module}" + cargo build --release --target=wasm32-unknown-unknown --manifest-path="${module}" done # Serialize application configuration for Rust module. if [[ "${EXAMPLE}" == "hello_world" ]]; then # `hello_world` example has an optional additional `translator` module. - cargo build --release --target-dir=examples/target --target=wasm32-unknown-unknown --manifest-path="examples/translator/module/rust/Cargo.toml" + cargo build --release --target=wasm32-unknown-unknown --manifest-path="examples/translator/module/rust/Cargo.toml" elif [[ "${EXAMPLE}" == "aggregator" ]]; then # `aggregator` example has an additional Backend Docker image cargo build --release --target=x86_64-unknown-linux-musl --manifest-path="examples/aggregator/backend/Cargo.toml" diff --git a/scripts/build_gh_pages b/scripts/build_gh_pages index 79834f55ca0..89cc5480755 100755 --- a/scripts/build_gh_pages +++ b/scripts/build_gh_pages @@ -33,7 +33,7 @@ fi readonly TARGET_ABS_PATH="$(realpath "${TARGET_DIR}")" # All the dirs that we want to generate docs for. -declare -ar SOURCE_PATHS=("." "oak_abi" "oak_utils" "sdk" "runner") +declare -ar SOURCE_PATHS=("oak/server" "oak_abi" "oak_utils" "sdk" "runner") declare -ar TARGET_SUBDIRS=("oak" "oak_abi" "oak_utils" "sdk" "runner") # Titles used in the top-level index.html files. diff --git a/scripts/check_docs b/scripts/check_docs index e697191aaf1..6c97e571d2a 100755 --- a/scripts/check_docs +++ b/scripts/check_docs @@ -6,10 +6,8 @@ readonly SCRIPTS_DIR="$(dirname "$0")" # shellcheck source=scripts/common source "$SCRIPTS_DIR/common" -# All the dirs that we generate docs for -declare -ar PATHS=("." "oak_abi" "oak_utils") - -for path in "${PATHS[@]}"; do +# We will not generate docs for all the workspaces, but we check the docs for all workspaces regardless. +for path in "${ALL_CRATES[@]}"; do ( cd "$path" DOCS_OUT="$(cargo doc --document-private-items --no-deps 2>&1)" diff --git a/scripts/common b/scripts/common index 73550442abb..999afc93355 100644 --- a/scripts/common +++ b/scripts/common @@ -17,7 +17,7 @@ readonly SERVER_DOCKER_IMAGE_NAME='gcr.io/oak-ci/oak-server' readonly CACHE_DIR='bazel-cache' # List all workspaces. -declare -ar ALL_CRATES=("oak_utils" "oak_abi" "." "sdk" "examples" "runner" "experimental") +declare -ar ALL_CRATES=("oak_utils" "oak_abi" "oak/server" "sdk" "examples" "runner" "experimental") # To set up remote cache write credentials: # - navigate to https://pantheon.corp.google.com/iam-admin/serviceaccounts?project=oak-ci diff --git a/scripts/deploy_example_gcp b/scripts/deploy_example_gcp index 43be101e86d..c2fe3282671 100755 --- a/scripts/deploy_example_gcp +++ b/scripts/deploy_example_gcp @@ -20,7 +20,9 @@ source "$SCRIPTS_DIR/gcp_common" # - Service Account User # Create a minimal Ubuntu linux image on the GCP project. -# The image will be named oak-gcp-hello-world. +# The image will be named oak-gcp-hello-world. +# The script fails if an image with the same name exists. +# Use `gcloud compute images delete oak-gcp-hello-world` to remove the old image. bazel run "${bazel_build_flags[@]}" "//examples/hello_world/gcp:deploy-${IMAGE_NAME}" # Authenticate as the service account @@ -37,7 +39,6 @@ gcloud beta compute instances create "${INSTANCE_NAME}" \ --boot-disk-size=16GB \ --boot-disk-type=pd-standard \ --boot-disk-device-name="${DISK_NAME}" \ - --metadata=startup-script='/opt/oak/oak_runner --application=/opt/oak/config.bin' # Create a firewall rule to allow access to the hello world VM on port 8080 gcloud compute firewall-rules create "${FIREWALL_RULE}" \ diff --git a/scripts/run_server b/scripts/run_server index 6e49ae8f64d..91d8640e926 100755 --- a/scripts/run_server +++ b/scripts/run_server @@ -93,6 +93,6 @@ fi # Launching the server requires a `--application=/config.bin` flag. # `exec` is necessary for the `run_example` script to be able to get a PID of a background server. -exec cargo run "${cargo_build_flags[@]}" --package=oak_loader -- \ +exec cargo run "${cargo_build_flags[@]}" --manifest-path=oak/server/rust/oak_loader/Cargo.toml -- \ --application="${APPLICATION_FILE}" \ "${additional_args[@]}"