Skip to content

Commit

Permalink
feat: initial new enclave manager (#1603)
Browse files Browse the repository at this point in the history
## Description:
This PR contains the beginnings of the new enclave manager ui.
Specifically it adds a new project in `enclave-manager/web`. Notable
inclusions:
* Continuing to use Chakra as a component libary, the
KurtosisThemeProvider injects components themed based on the mocks.
* The enclave manager sdk cllient is refactored into authenticated
(remote) and local versions, and provided to react components with
`useKurtosisClient` by the `KurtosisClientProvider`. This provider
blocks loading the application (with a spinner) until it's configured
the client to use.
* react router is used to compose the application.
* react-table is used to create a (reusable) table for showing the
enclaves list.

### Demo (WIP)


https://github.com/kurtosis-tech/kurtosis/assets/4419574/c026a1d9-313d-4e73-944a-2814399e039a

## Is this change user facing?
NO (this is not yet part of the build/deploy process)

## References (if applicable):
This PR is rebased on top of
#1595 which should be
merged first.

---------

Co-authored-by: Anders Schwartz <anders.schwartz@kurtosistech.com>
Co-authored-by: Anders Schwartz <adschwartz@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 31, 2023
1 parent aeb4128 commit 9944658
Show file tree
Hide file tree
Showing 87 changed files with 15,292 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Expand Up @@ -1151,6 +1151,9 @@ workflows:
},
{
"pattern": "https://twitter.com/.*"
},
{
"pattern": "http://localhost:3000"
}
]
}
Expand Down
4 changes: 4 additions & 0 deletions enclave-manager/web/.env
@@ -0,0 +1,4 @@
REACT_APP_KURTOSIS_DEFAULT_HOST=localhost
REACT_APP_KURTOSIS_DEFAULT_PORT=8081

REACT_APP_KURTOSIS_CLOUD_URL=https://cloud.kurtosis.com:9770
3 changes: 3 additions & 0 deletions enclave-manager/web/.prettierignore
@@ -0,0 +1,3 @@
# Ignore artifacts:
build
coverage
4 changes: 4 additions & 0 deletions enclave-manager/web/.prettierrc
@@ -0,0 +1,4 @@
{
"printWidth": 120,
"plugins": ["prettier-plugin-organize-imports"]
}
53 changes: 53 additions & 0 deletions enclave-manager/web/README.md
@@ -0,0 +1,53 @@
# Enclave Manager UI (EMUI)

This codebase produces the enclave manager UI (ie `kurtosis web`). The `src` directory contains:

- `components` - components used in the application. This includes theme definitions and application context definitions
- `client/enclaveManager` - libraries for interacting with the local `kurtosis` backend - used to instantiate a `KurtosisClientContext` and interacted with using `useKurtosisClient`
- `client/packageIndexer` - libraries for interacting with the package indexer - used to instantiate a `KurtosisPackageIndexerClientContext` and interacted with using `useKurtosisPackageIndexerClient`
- `emui` - the composition of the above to produce the Enclave Manager UI using react router

## Available Scripts

In the project directory, you can run:

### `yarn cleanInstall`

Removes `node_modules` and runs `yarn install`.

### `yarn clean`

Removes the build output if present.

### `yarn start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `yarn build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `yarn eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
62 changes: 62 additions & 0 deletions enclave-manager/web/package.json
@@ -0,0 +1,62 @@
{
"name": "frontend",
"version": "0.2.0",
"private": true,
"dependencies": {
"@chakra-ui/icons": "^2.1.1",
"@chakra-ui/react": "^2.8.1",
"@connectrpc/connect": "^0.13.0",
"@connectrpc/connect-web": "^0.13.0",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@tanstack/react-table": "^8.10.7",
"enclave-manager-sdk": "file:../api/typescript",
"framer-motion": "^10.16.4",
"luxon": "^3.4.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.47.0",
"react-icons": "^4.11.0",
"react-markdown": "^9.0.0",
"react-router-dom": "^6.17.0",
"react-scripts": "5.0.1",
"true-myth": "^7.1.0"
},
"devDependencies": {
"@types/luxon": "^3.3.3",
"@types/node": "^16.7.13",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"prettier": "3.0.3",
"prettier-plugin-organize-imports": "^3.2.3",
"typescript": "^4.4.2"
},
"scripts": {
"clean": "rm -rf build",
"cleanInstall": "rm -rf node_modules; yarn install",
"start": "react-scripts start",
"build": "react-scripts build",
"prettier": "prettier . --check",
"prettier:fix": "prettier . --write",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file added enclave-manager/web/public/favicon.ico
Binary file not shown.
Binary file not shown.
34 changes: 34 additions & 0 deletions enclave-manager/web/public/index.html
@@ -0,0 +1,34 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="The Kurtosis Enclave Manager Web UI." />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Kurtosis Enclave Manager</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file added enclave-manager/web/public/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions enclave-manager/web/scripts/build.sh
@@ -0,0 +1,17 @@
#!/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}")"


# ==================================================================================================
# Main Logic
# ==================================================================================================
cd "${lang_root_dirpath}"
yarn install --frozen-lockfile
# There are no unit tests currently
# CGO_ENABLED=0 yarn test
yarn clean
yarn build
10 changes: 10 additions & 0 deletions enclave-manager/web/src/client/constants.ts
@@ -0,0 +1,10 @@
import { isDefined } from "../utils";

export const KURTOSIS_DEFAULT_HOST = process.env.REACT_APP_KURTOSIS_DEFAULT_HOST || "localhost";
export const KURTOSIS_DEFAULT_PORT = isDefined(process.env.REACT_APP_KURTOSIS_DEFAULT_PORT)
? parseInt(process.env.REACT_APP_KURTOSIS_DEFAULT_PORT)
: 8081;
export const KURTOSIS_DEFAULT_URL =
process.env.REACT_APP_KURTOSIS_DEFAULT_URL || `http://${KURTOSIS_DEFAULT_HOST}:${KURTOSIS_DEFAULT_PORT}`;

export const KURTOSIS_CLOUD_URL = process.env.REACT_APP_KURTOSIS_CLOUD_URL || "https://cloud.kurtosis.com:9770";
@@ -0,0 +1,26 @@
import { createPromiseClient } from "@connectrpc/connect";
import { createConnectTransport } from "@connectrpc/connect-web";
import { KurtosisEnclaveManagerServer } from "enclave-manager-sdk/build/kurtosis_enclave_manager_api_connect";
import { KURTOSIS_DEFAULT_PORT } from "../constants";
import { KurtosisClient } from "./KurtosisClient";

function constructGatewayURL(host: string): string {
return `https://cloud.kurtosis.com/gateway/ips/${host}/ports/${KURTOSIS_DEFAULT_PORT}`;
}

export class AuthenticatedKurtosisClient extends KurtosisClient {
private token: string;

constructor(host: string, token: string) {
super(
createPromiseClient(KurtosisEnclaveManagerServer, createConnectTransport({ baseUrl: constructGatewayURL(host) })),
);
this.token = token;
}

getHeaderOptions(): { headers?: Headers } {
const headers = new Headers();
headers.set("Authorization", `Bearer ${this.token}`);
return { headers: headers };
}
}
120 changes: 120 additions & 0 deletions enclave-manager/web/src/client/enclaveManager/KurtosisClient.ts
@@ -0,0 +1,120 @@
import { PromiseClient } from "@connectrpc/connect";
import { RunStarlarkPackageArgs } from "enclave-manager-sdk/build/api_container_service_pb";
import {
CreateEnclaveArgs,
DestroyEnclaveArgs,
EnclaveAPIContainerInfo,
EnclaveInfo,
EnclaveMode,
} from "enclave-manager-sdk/build/engine_service_pb";
import { KurtosisEnclaveManagerServer } from "enclave-manager-sdk/build/kurtosis_enclave_manager_api_connect";
import {
GetListFilesArtifactNamesAndUuidsRequest,
GetServicesRequest,
GetStarlarkRunRequest,
RunStarlarkPackageRequest,
} from "enclave-manager-sdk/build/kurtosis_enclave_manager_api_pb";
import { assertDefined, asyncResult } from "../../utils";
import { RemoveFunctions } from "../../utils/types";

export abstract class KurtosisClient {
protected client: PromiseClient<typeof KurtosisEnclaveManagerServer>;

constructor(client: PromiseClient<typeof KurtosisEnclaveManagerServer>) {
this.client = client;
}

abstract getHeaderOptions(): { headers?: Headers };

async checkHealth() {
return asyncResult(this.client.check({}, this.getHeaderOptions()));
}

async getEnclaves() {
return asyncResult(this.client.getEnclaves({}, this.getHeaderOptions()), "KurtosisClient could not getEnclaves");
}

async destroy(enclaveUUID: string) {
return asyncResult(
this.client.destroyEnclave(new DestroyEnclaveArgs({ enclaveIdentifier: enclaveUUID }), this.getHeaderOptions()),
`KurtosisClient could not destroy enclave ${enclaveUUID}`,
);
}

async getServices(enclave: RemoveFunctions<EnclaveInfo>) {
return await asyncResult(() => {
const apicInfo = enclave.apiContainerInfo;
assertDefined(apicInfo, `Cannot getServices because the passed enclave '${enclave.name}' does not have apicInfo`);
const request = new GetServicesRequest({
apicIpAddress: apicInfo.bridgeIpAddress,
apicPort: apicInfo.grpcPortInsideEnclave,
});
return this.client.getServices(request, this.getHeaderOptions());
}, "KurtosisClient could not getServices");
}

async getStarlarkRun(enclave: RemoveFunctions<EnclaveInfo>) {
return await asyncResult(() => {
const apicInfo = enclave.apiContainerInfo;
assertDefined(
apicInfo,
`Cannot getStarlarkRun because the passed enclave '${enclave.name}' does not have apicInfo`,
);
const request = new GetStarlarkRunRequest({
apicIpAddress: apicInfo.bridgeIpAddress,
apicPort: apicInfo.grpcPortInsideEnclave,
});
return this.client.getStarlarkRun(request, this.getHeaderOptions());
}, "KurtosisClient could not getStarlarkRun");
}

async listFilesArtifactNamesAndUuids(enclave: RemoveFunctions<EnclaveInfo>) {
return await asyncResult(() => {
const apicInfo = enclave.apiContainerInfo;
assertDefined(
apicInfo,
`Cannot listFilesArtifactNamesAndUuids because the passed enclave '${enclave.name}' does not have apicInfo`,
);
const request = new GetListFilesArtifactNamesAndUuidsRequest({
apicIpAddress: apicInfo.bridgeIpAddress,
apicPort: apicInfo.grpcPortInsideEnclave,
});
return this.client.listFilesArtifactNamesAndUuids(request, this.getHeaderOptions());
}, "KurtosisClient could not listFilesArtifactNamesAndUuids");
}

async createEnclave(
enclaveName: string,
apiContainerLogLevel: string,
productionMode?: boolean,
apiContainerVersionTag?: string,
) {
return asyncResult(() => {
const request = new CreateEnclaveArgs({
enclaveName,
apiContainerLogLevel,
mode: productionMode ? EnclaveMode.PRODUCTION : EnclaveMode.TEST,
apiContainerVersionTag: apiContainerVersionTag || "",
});
return this.client.createEnclave(request, this.getHeaderOptions());
});
}

async runStarlarkPackage(
apicInfo: RemoveFunctions<EnclaveAPIContainerInfo>,
packageId: string,
args: Record<string, any>,
) {
// Not currently using asyncResult as the return type here is an asyncIterable
const request = new RunStarlarkPackageRequest({
apicIpAddress: apicInfo.bridgeIpAddress,
apicPort: apicInfo.grpcPortInsideEnclave,
RunStarlarkPackageArgs: new RunStarlarkPackageArgs({
dryRun: false,
packageId: packageId,
serializedParams: JSON.stringify(args),
}),
});
return this.client.runStarlarkPackage(request, this.getHeaderOptions());
}
}

0 comments on commit 9944658

Please sign in to comment.