Skip to content

Commit 222ce4f

Browse files
authored
Merge pull request #185 from morningtzh/for1.0.1
[release/1.0] Prepare release for v1.0.1
2 parents 88c3b4d + 60b4e6a commit 222ce4f

38 files changed

+2540
-350
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
steps:
3030
- uses: actions/checkout@v3
3131
- run: rustup toolchain install nightly --component rustfmt
32+
- run: rustup show
3233
- name: Install Protoc
3334
uses: arduino/setup-protoc@v1.1.2
3435
with:

Makefile

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ INSTALL_DIR := /var/lib/kuasar
99
BIN_DIR := /usr/local/bin
1010
SYSTEMD_SERVICE_DIR := /usr/lib/systemd/system
1111
SYSTEMD_CONF_DIR := /etc/sysconfig
12+
ENABLE_YOUKI ?= false
13+
RUNC_FEATURES =
14+
VMM_TASK_FEATURES =
15+
16+
ifeq ($(ENABLE_YOUKI), true)
17+
RUNC_FEATURES = youki
18+
VMM_TASK_FEATURES = youki
19+
endif
1220

1321
.PHONY: vmm wasm quark clean all install-vmm install-wasm install-quark install \
1422
bin/vmm-sandboxer bin/vmm-task bin/vmlinux.bin bin/kuasar.img bin/kuasar.initrd \
@@ -21,7 +29,7 @@ bin/vmm-sandboxer:
2129
@mkdir -p bin && cp vmm/sandbox/target/release/${HYPERVISOR} bin/vmm-sandboxer
2230

2331
bin/vmm-task:
24-
@cd vmm/task && cargo build --release --target=${ARCH}-unknown-linux-musl
32+
@cd vmm/task && cargo build --release --target=${ARCH}-unknown-linux-musl --features=${VMM_TASK_FEATURES}
2533
@mkdir -p bin && cp vmm/task/target/${ARCH}-unknown-linux-musl/release/vmm-task bin/vmm-task
2634

2735
bin/vmlinux.bin:
@@ -45,17 +53,18 @@ bin/quark-sandboxer:
4553
@mkdir -p bin && cp quark/target/release/quark-sandboxer bin/quark-sandboxer
4654

4755
bin/runc-sandboxer:
48-
@cd runc && cargo build --release
56+
@cd runc && cargo build --release --features=${RUNC_FEATURES}
4957
@mkdir -p bin && cp runc/target/release/runc-sandboxer bin/runc-sandboxer
5058

5159
wasm: bin/wasm-sandboxer
5260
quark: bin/quark-sandboxer
5361
runc: bin/runc-sandboxer
5462

55-
ifeq ($(HYPERVISOR), stratovirt)
56-
vmm: bin/vmm-sandboxer bin/kuasar.initrd bin/vmlinux.bin
57-
else
63+
ifeq ($(HYPERVISOR), cloud_hypervisor)
5864
vmm: bin/vmm-sandboxer bin/kuasar.img bin/vmlinux.bin
65+
else
66+
# stratovirt or qemu
67+
vmm: bin/vmm-sandboxer bin/kuasar.initrd bin/vmlinux.bin
5968
endif
6069

6170
clean:
@@ -76,12 +85,13 @@ install-vmm:
7685
@install -d -m 750 ${DEST_DIR}${SYSTEMD_CONF_DIR}
7786
@install -p -m 640 vmm/service/kuasar-vmm ${DEST_DIR}${SYSTEMD_CONF_DIR}/kuasar-vmm
7887

79-
ifeq ($(HYPERVISOR), stratovirt)
80-
@install -p -m 640 bin/kuasar.initrd ${DEST_DIR}${INSTALL_DIR}/kuasar.initrd
81-
@install -p -m 640 vmm/sandbox/config_stratovirt_${ARCH}.toml ${DEST_DIR}${INSTALL_DIR}/config_stratovirt.toml
82-
else
88+
ifeq ($(HYPERVISOR), cloud_hypervisor)
8389
@install -p -m 640 bin/kuasar.img ${DEST_DIR}${INSTALL_DIR}/kuasar.img
84-
@install -p -m 640 vmm/sandbox/config_clh.toml ${DEST_DIR}${INSTALL_DIR}/config_clh.toml
90+
@install -p -m 640 vmm/sandbox/config_clh.toml ${DEST_DIR}${INSTALL_DIR}/config.toml
91+
else
92+
# stratovirt or qemu
93+
@install -p -m 640 bin/kuasar.initrd ${DEST_DIR}${INSTALL_DIR}/kuasar.initrd
94+
@install -p -m 640 vmm/sandbox/config_${HYPERVISOR}_${ARCH}.toml ${DEST_DIR}${INSTALL_DIR}/config.toml
8595
endif
8696

8797
install-wasm:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Since Kuasar is a low-level container runtime, all interactions should be done v
169169

170170
+ For vmm, quark or runc, run the following scripts:
171171

172-
`examples/run_example_container.sh vmm`, `examples/run_example_container.sh quark` or `examples/run_example_container.sh runc`
172+
`examples/run_example_container.sh kuasar-vmm`, `examples/run_example_container.sh kuasar-quark` or `examples/run_example_container.sh kuasar-runc`
173173

174174
+ For wasm: Wasm container needs its own container image so our script has to build and import the container image at first.
175175

docs/wasm/How-to-run-Llama-3-8B-with-Kubernetes.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ details in: https://www.secondstate.io/articles/wasm-runtime-agi/.
1010

1111
## How to run a llm inference application in Kuasar?
1212

13-
Since Kuasar v0.8.0, Kuasar wasm-sandboxer with `wasmedge` and `wasmedge_wasi_nn`
13+
Since Kuasar v1.0.0, Kuasar wasm-sandboxer with `wasmedge` and `wasmedge_wasi_nn`
1414
features allows your WasmEdge application use the ability of WASI API for
1515
performing Machine Learning inference: https://github.com/WebAssembly/wasi-nn.
1616

@@ -22,7 +22,6 @@ which introducing how to create an OpenAI-compatible API service for Llama-3-8B.
2222
+ Install WasmEdge and plugins:
2323
`curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -v 0.13.5 --plugins wasi_logging wasi_nn-ggml`
2424

25-
2625
### 1. Build docker image
2726

2827
We already have an example docker image on dockerhub: `docker.io/kuasario/llama-api-server:v1`.
@@ -50,6 +49,18 @@ CMD ["llama-api-server.wasm", "--prompt-template", "llama-3-chat", "--ctx-size",
5049
```
5150
Build it with `docker build -t docker.io/kuasario/llama-api-server:v1 .`
5251

52+
Otherwise, you can use this DOCKERFILE if you are debugging while developing:
53+
```dockerfile
54+
FROM ubuntu:22.04
55+
RUN apt-get update && apt-get install -y curl
56+
RUN curl -LO https://huggingface.co/second-state/Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3-8B-Instruct-Q5_K_M.gguf
57+
RUN curl -LO https://github.com/second-state/chatbot-ui/releases/latest/download/chatbot-ui.tar.gz; tar xzf chatbot-ui.tar.gz; rm chatbot-ui.tar.gz
58+
COPY *.wasm .
59+
```
60+
61+
This would download all prerequisites to docker image cache, allowing you pay attention only on development.
62+
`docker build -f Dockerfile -t docker.io/kuasario/llama-api-server:v2 $path_to_app`
63+
5364
### 2. Build and run Kuasar Wasm Sandboxer
5465

5566
```bash

runc/src/sandbox.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,19 @@ impl Sandboxer for RuncSandboxer {
165165
let mut sandbox = sandbox.lock().await;
166166
let mut sandbox_parent = self.sandbox_parent.lock().await;
167167
let sandbox_pid = sandbox_parent.fork_sandbox_process(id, &sandbox.data.netns)?;
168-
sandbox.prepare_sandbox_ns(sandbox_pid).await.map_err(|e| {
169-
kill(Pid::from_raw(sandbox_pid), Signal::SIGKILL).unwrap_or_default();
170-
e
171-
})?;
168+
sandbox
169+
.prepare_sandbox_ns(sandbox_pid)
170+
.await
171+
.inspect_err(|_| {
172+
kill(Pid::from_raw(sandbox_pid), Signal::SIGKILL).unwrap_or_default();
173+
})?;
172174

173175
sandbox
174176
.data
175177
.task_address
176178
.clone_from(&format!("ttrpc+{}", self.task_address));
177-
sandbox.dump().await.map_err(|e| {
179+
sandbox.dump().await.inspect_err(|_| {
178180
kill(Pid::from_raw(sandbox_pid), Signal::SIGKILL).unwrap_or_default();
179-
e
180181
})?;
181182
Ok(())
182183
}

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "1.81"
3+
components = ["rustfmt", "clippy", "llvm-tools"]

vmm/common/Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ ttrpc = { version = "0.7", features = ["async"] }
1818
protobuf = "3.2"
1919
async-trait = "0.1"
2020
regex = "1.5.6"
21+
futures = { version = "0.3.21" }
22+
signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] }
23+
24+
tracing = "0.1.40"
25+
tracing-opentelemetry = "0.21.0"
26+
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
27+
28+
opentelemetry = { version = "0.20.0", features = ["rt-tokio"] }
29+
opentelemetry-otlp = "0.13.0"
2130

2231
[build-dependencies]
2332
ttrpc-codegen = { git = "https://github.com/kuasar-io/ttrpc-rust.git", branch = "v0.7.1-kuasar" }
24-
tonic-build = "0.7.2"
33+
tonic-build = "0.7.2"

vmm/common/build.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
use std::fs;
18+
1719
use ttrpc_codegen::{Codegen, Customize, ProtobufCustomize};
1820

1921
fn main() {
@@ -45,4 +47,24 @@ fn main() {
4547
)
4648
.run()
4749
.expect("Gen protos code failed");
50+
51+
// Protobuf-rust 3.5.1 no longer generates the `#![allow(box_pointers)]` lint.
52+
// However, ttrpc-rust has not yet upgraded to protobuf-rust 3.5.1.
53+
// As a temporary measure, we are modifying the files to suppress the warning.
54+
remove_box_pointers("src/api").expect("Remove api box_pointer failed");
55+
}
56+
57+
fn remove_box_pointers(dir: &str) -> std::io::Result<()> {
58+
for entry in fs::read_dir(dir)? {
59+
let entry = entry?;
60+
let path = entry.path();
61+
62+
if path.is_file() {
63+
let content = fs::read_to_string(&path)?;
64+
let new_content = content.replace("#![allow(box_pointers)]", "");
65+
66+
fs::write(path, new_content)?;
67+
}
68+
}
69+
Ok(())
4870
}

vmm/common/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ pub use containerd_sandbox::data::Io;
1818

1919
pub mod api;
2020
pub mod mount;
21+
pub mod signal;
2122
pub mod storage;
23+
pub mod trace;
2224

2325
pub const KUASAR_STATE_DIR: &str = "/run/kuasar/state";
2426

vmm/common/src/signal.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright 2024 The Kuasar Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
use futures::StreamExt;
18+
use nix::libc;
19+
use signal_hook_tokio::Signals;
20+
21+
use crate::trace;
22+
23+
pub async fn handle_signals(log_level: &str, otlp_service_name: &str) {
24+
let mut signals = Signals::new([libc::SIGUSR1])
25+
.expect("new signal failed")
26+
.fuse();
27+
28+
while let Some(sig) = signals.next().await {
29+
if sig == libc::SIGUSR1 {
30+
trace::set_enabled(!trace::is_enabled());
31+
let _ = trace::setup_tracing(log_level, otlp_service_name);
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)