Skip to content

Commit

Permalink
feat: Add cargo build as part of Kurtosis build (#774)
Browse files Browse the repository at this point in the history
## Description:
<!-- Describe this change, how it works, and the motivation behind it.
-->

## Is this change user facing?
YES
<!-- If yes, please add the "user facing" label to the PR -->
<!-- If yes, don't forget to include docs changes where relevant -->

## References (if applicable):
<!-- Add relevant Github Issues, Discord threads, or other helpful
information. -->
  • Loading branch information
victorcolombo committed Jun 26, 2023
1 parent 782f045 commit c68fe0a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
1 change: 1 addition & 0 deletions .circleci/config.yml
Expand Up @@ -1252,6 +1252,7 @@ workflows:
- slack-secrets
requires:
- publish_kurtosis_api_typescript
- publish_kurtosis_sdk_rust
- publish_api_container_server_image
- publish_engine_server_image
- publish_files_artifacts_expander_image
Expand Down
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -165,6 +165,14 @@ mkdir ~/.nvm
nvm install 16.14.0
npm install -g yarn
```

#### Rust

On MacOS:
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

#### Go and Typescript protobuf compiler binaries

On MacOS:
Expand Down
61 changes: 60 additions & 1 deletion api/rust/README.md
Expand Up @@ -2,4 +2,63 @@

This is an SDK for [Kurtosis](https://github.com/kurtosis-tech/kurtosis), based on the protobufs available [here](https://github.com/kurtosis-tech/kurtosis/tree/main/api/protobuf);

More details can be found on the [docs](https://docs.kurtosis.com/).
## Example

Make sure that the engine is running:

```terminal
kurtosis engine start
```

Then you can run a Starlark script using Kurtosis+Rust:

```rust
use kurtosis_sdk::{engine_api::{engine_service_client::{EngineServiceClient}, CreateEnclaveArgs}, enclave_api::{api_container_service_client::ApiContainerServiceClient, RunStarlarkScriptArgs}};
use kurtosis_sdk::enclave_api::starlark_run_response_line::RunResponseLine::InstructionResult;

const STARLARK_SCRIPT : &str = "
def main(plan):
plan.print('Hello World!')
";

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// CREATE ENCLAVE
let mut engine = EngineServiceClient::connect("https://[::1]:9710").await?;
let create_enclave_response = engine.create_enclave(CreateEnclaveArgs{
enclave_name: "my-rust-test".to_string(),
api_container_log_level: "info".to_string(),
// Default
api_container_version_tag: "".to_string(),
is_partitioning_enabled: false,
}).await?.into_inner();

// CONNECT TO ENCLAVE
let enclave_port = create_enclave_response.enclave_info.expect("Enclave info must be present").api_container_host_machine_info.expect("Enclave host machine info must be present").grpc_port_on_host_machine;
let mut enclave = ApiContainerServiceClient::connect(format!("https://[::1]:{}", enclave_port)).await?;

// RUN STARLARK SCRIPT
let mut run_result = enclave.run_starlark_script(RunStarlarkScriptArgs{
serialized_script: STARLARK_SCRIPT.to_string(),
serialized_params: "{}".to_string(),
dry_run: Option::Some(false),
parallelism: Option::None,
main_function_name: "main".to_string(),
}).await?.into_inner();

// GET OUTPUT LINES
while let Some(next_message) = run_result.message().await? {
next_message.run_response_line.map(|line| match line {
InstructionResult(result) => {
println!("{}", result.serialized_instruction_result)
}
_ => (),
});
}
Ok(())
}

```

More details can be found on the [docs](https://docs.kurtosis.com/).

19 changes: 19 additions & 0 deletions api/rust/scripts/build.sh
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# 2021-07-08 WATERMARK, DO NOT REMOVE - This script was generated from the Kurtosis Bash script template

set -euo pipefail # Bash "strict mode"
script_dirpath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
lang_root_dirpath="$(dirname "${script_dirpath}")"



# ==================================================================================================
# Constants
# ==================================================================================================


# ==================================================================================================
# Main Logic
# ==================================================================================================
cd "${lang_root_dirpath}"
cargo build

0 comments on commit c68fe0a

Please sign in to comment.