From e946d9b97c813717dd375d8c3dcd0b275b1ca078 Mon Sep 17 00:00:00 2001 From: Haoyuan Ma Date: Tue, 15 Aug 2023 22:13:39 +0800 Subject: [PATCH] add README, improve code comments, fix spell error Signed-off-by: flyinghorse0510 --- configs/.wordlist.txt | 2 + scripts/README.md | 107 ++++++++++++++++++++++++++++ scripts/configs/vHive.go | 2 + scripts/setup.go | 1 + scripts/utils/system.go | 3 +- scripts/utils/vhive_repo_context.go | 11 +++ 6 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 scripts/README.md diff --git a/configs/.wordlist.txt b/configs/.wordlist.txt index b9d836c29..20d7c57c4 100644 --- a/configs/.wordlist.txt +++ b/configs/.wordlist.txt @@ -314,6 +314,8 @@ NEURALWALKER neuroevolution NewServer Nicopoulos +Nvidia +nvidia nmi NoC NOC diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 000000000..fe80e519c --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,107 @@ +# vHive Setup Scripts +- [vHive Setup Scripts](#vhive-setup-scripts) + - [1. Get Setup Tool](#1-get-setup-tool) + - [1.1 Download the Binary Executable Directly](#11-download-the-binary-executable-directly) + - [1.2 Build from Source](#12-build-from-source) + - [2. Config the Setup Tool](#2-config-the-setup-tool) + - [3. Use of Setup Tool](#3-use-of-setup-tool) + - [3.1 General Usage](#31-general-usage) + - [3.2 Specify Config Files](#32-specify-config-files) + - [3.3 Use with Local vHive Repo](#33-use-with-local-vhive-repo) + - [3.4 Use with Remote vHive Repo (Standalone Use)](#34-use-with-remote-vhive-repo-standalone-use) + - [3.5 Migrate from Legacy Shell Scripts](#35-migrate-from-legacy-shell-scripts) + - [4. Logs](#4-logs) + - [5. Supported Platform](#5-supported-platform) +## 1. Get Setup Tool +There are basically two ways to get the setup tool + +### 1.1 Download the Binary Executable Directly +Check [vHive GitHub Repo](https://github.com/vhive-serverless/vHive/releases) for more details and choose the appropriate version to download. + +### 1.2 Build from Source +**Building from source requires Go (version 1.19 at least) installed on your system.** +```bash +git clone --depth 1 https://github.com/vhive-serverless/vHive +cd vHive +pushd scripts && go build -o setup_tool && popd +``` +Compiled executable file will be in the `scripts` directory. + +## 2. Config the Setup Tool +**Normally, just skip this section and use the default config files** which are located in the `configs/setup` directory inside the [vHive repo](https://github.com/vhive-serverless/vHive). + +- `configs/setup/knative.json`: knative related configs (all the path in the config file should be relative path inside the vHive repo) +- `configs/setup/kube.json`: Kubernetes related configs +- `configs/setup/system.json`: system related configs +- `configs/setup/vhive.json`: vHive related configs + +You can modify the config files on your demand and then place all of them in one directory for the later use. + +## 3. Use of Setup Tool +### 3.1 General Usage +```bash +./setup_tool [options] [parameters] +``` +use the `-h` or `--help` option to look for the help +### 3.2 Specify Config Files +By default, the setup_tool will use the config files in `configs/setup` directory inside the vHive repo. + +To change the path of config files, use the `--setup-configs-dir` option to specify it. +```bash +./setup_tool --setup-configs-dir ... +``` + +### 3.3 Use with Local vHive Repo +By default, the setup_tool will check the current directory to ensure it is a vHive repo and then use it during the setup process. + +To use other vHive repos locally, provide the `--vhive-repo-dir` option to specify it. +```bash +./setup_tool --vhive-repo-dir ... +``` + +If the current directory or the provided path is not a valid vHive repo, the setup_tool will [automatically clone the remote vHive repo and use it](#34-use-with-remote-vhive-repo). + +### 3.4 Use with Remote vHive Repo (Standalone Use) +When the setup_tool is directly downloaded or targeted for standalone use, the setup_tool will automatically clone the remote vHive repo to the temporary directory and then use it during the setup process. + +To change the URL and branch of the [default remote vHive repo](https://github.com/vhive-serverless/vHive), use `--vhive-repo-url` and `--vhive-repo-branch` options to specify them. +```bash +./setup_tool --vhive-repo-url --vhive-repo-branch ... +``` + +Besides, when the current directory is a vHive repo or the `--vhive-repo-dir` option is valid, **the local repo will be prioritized for use**. **To force the setup_tool to clone and use the remote vHive repo**, provide `--force-remote` option to the setup_tool. +```bash +./setup_tool --force-remote ... +``` + + +### 3.5 Migrate from Legacy Shell Scripts +Just type the name of the original shell script and append corresponding parameters behind. For example: +```bash +# Legacy ==> +scripts/cloudlab/setup_node.sh stock-only +# ==> Current +./setup_tool [options] setup_node stock-only + +# Legacy ==> +scripts/create_devmapper.sh +# ==> Current +./setup_tool [options] create_devmapper + +# Legacy ==> +scripts/gpu/setup_nvidia_gpu.sh +# ==> Current +./setup_tool [options] setup_nvidia_gpu +``` + +**NOTICE**: Shell scripts in `scripts/stargz`, `scripts/self-hosted-kind`, and `scripts/github_runner` **are not supported to be invoked in this way at present**. + + +## 4. Logs +The log files will be named as `_common.log` and `_error.log`. All log files will be stored in the directory where the setup_tool is executed. + +- `_common.log`: all output originally writes to `stdout` will be redirected to this log file. +- `_error.log`: all output originally writes to `stderr` will be redirected to this log file. + +## 5. Supported Platform +At present, only `Ubuntu 20.04 (amd64)` is officially tested. Other versions of `Ubuntu` may also work, but not guaranteed. \ No newline at end of file diff --git a/scripts/configs/vHive.go b/scripts/configs/vHive.go index c8391447f..ac30afb21 100644 --- a/scripts/configs/vHive.go +++ b/scripts/configs/vHive.go @@ -29,6 +29,7 @@ type VHiveConfigStruct struct { VHiveRepoBranch string VHiveRepoUrl string VHiveSetupConfigPath string + ForceRemote bool } var VHive = VHiveConfigStruct{ @@ -36,4 +37,5 @@ var VHive = VHiveConfigStruct{ VHiveRepoBranch: "main", VHiveRepoUrl: "https://github.com/vhive-serverless/vHive.git", VHiveSetupConfigPath: "", + ForceRemote: false, } diff --git a/scripts/setup.go b/scripts/setup.go index 113025142..4bebe164c 100644 --- a/scripts/setup.go +++ b/scripts/setup.go @@ -51,6 +51,7 @@ func main() { setupFlags.StringVar(&configs.VHive.VHiveRepoPath, "vhive-repo-dir", configs.VHive.VHiveRepoPath, "vHive repo path (left blank to use online repo automatically)") setupFlags.StringVar(&configs.VHive.VHiveRepoBranch, "vhive-repo-branch", configs.VHive.VHiveRepoBranch, "vHive repo branch (valid only when using online repo)") setupFlags.StringVar(&configs.VHive.VHiveRepoUrl, "vhive-repo-url", configs.VHive.VHiveRepoUrl, "vHive repo url (valid only when using online repo)") + setupFlags.BoolVar(&configs.VHive.ForceRemote, "force-remote", configs.VHive.ForceRemote, "Force scripts to use the online repo") setupFlags.BoolVar(&help, "help", false, "Show help") setupFlags.BoolVar(&help, "h", false, "Show help") diff --git a/scripts/utils/system.go b/scripts/utils/system.go index c8f07c1a2..2a8e09f82 100644 --- a/scripts/utils/system.go +++ b/scripts/utils/system.go @@ -169,6 +169,7 @@ func CleanUpTmpDir() error { return err } +// Copy file(directory) to the specific destination func CopyToDir(source string, target string, privileged bool) error { var err error @@ -176,7 +177,7 @@ func CopyToDir(source string, target string, privileged bool) error { if privileged { privilegedCmd = "sudo" } - + // Copy recursively _, err = ExecShellCmd("%s cp -R %s %s", privilegedCmd, source, target) return err diff --git a/scripts/utils/vhive_repo_context.go b/scripts/utils/vhive_repo_context.go index bdd136024..562d7a3e9 100644 --- a/scripts/utils/vhive_repo_context.go +++ b/scripts/utils/vhive_repo_context.go @@ -31,6 +31,16 @@ import ( // Check whether vHive repo exists, if not, clone it to the temporary directory func CheckVHiveRepo() error { + + if configs.VHive.ForceRemote { + WaitPrintf("Force to use the online repo! Automatically cloning the vHive repo") + vHiveRepoPath, err := CloneRepoToTmpDir(configs.VHive.VHiveRepoBranch, configs.VHive.VHiveRepoUrl) + if CheckErrorWithTagAndMsg(err, "Failed to clone the vHive repo!\n") { + configs.VHive.VHiveRepoPath = vHiveRepoPath + } + return err + } + if _, err := os.Stat(configs.VHive.VHiveRepoPath); err != nil { // vHive Repo not specified or not exist WaitPrintf("vHive repo not detected! Automatically cloning the vHive repo") @@ -41,6 +51,7 @@ func CheckVHiveRepo() error { } return err } + return nil }