Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit db3a740

Browse files
committed
Add Dockerfile, Makefile, start.sh
1 parent fa8444d commit db3a740

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM public.ecr.aws/docker/library/rust:1.72.0-slim-bookworm as rust-builder
2+
3+
WORKDIR /src/
4+
5+
COPY ./Cargo.toml ./Cargo.lock ./
6+
COPY ./src src/
7+
8+
RUN cargo build --locked --release
9+
10+
FROM public.ecr.aws/docker/library/debian:12.1-slim
11+
12+
RUN apt update && apt install -y procps
13+
14+
COPY start.sh /usr/local/bin
15+
RUN chmod +x /usr/local/bin/start.sh
16+
17+
COPY --from=rust-builder /src/target/release/vsock-experiment /usr/local/bin/
18+
19+
CMD ["/usr/local/bin/start.sh"]

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
all: run
2+
3+
install-relay:
4+
cargo install vsock-relay
5+
6+
run-relay:
7+
vsock-relay -s 0.0.0.0:8080 -l 4:8080
8+
9+
build: src/*.rs Cargo.toml Dockerfile
10+
docker build -t vsock-experiment .
11+
nitro-cli build-enclave --docker-uri vsock-experiment:latest --output-file vsock-experiment.eif
12+
13+
run: build
14+
nitro-cli terminate-enclave --all
15+
nitro-cli run-enclave \
16+
--cpu-count 8 \
17+
--memory 512 \
18+
--enclave-cid 4 \
19+
--eif-path "vsock-experiment.eif" \
20+
--debug-mode \
21+
--attach-console

src/main.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
use futures::StreamExt;
2+
use std::net::Shutdown;
3+
use std::process::exit;
4+
use std::time::Duration;
25
use tokio::io::AsyncWriteExt;
6+
use tokio::time::sleep;
37
use tokio_vsock::VsockListener;
48

59
#[tokio::main]
610
async fn main() {
7-
let listener = VsockListener::bind(4, 1234).expect("Failed to bind to address");
11+
let listener = VsockListener::bind(4, 8080).expect("Failed to bind to address");
12+
13+
tokio::spawn(async {
14+
sleep(Duration::from_secs(30)).await;
15+
println!("I'm out!");
16+
exit(0);
17+
});
818

919
let mut incoming = listener.incoming();
1020
while let Some(result) = incoming.next().await {
@@ -13,6 +23,7 @@ async fn main() {
1323
let response = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nHello, World!";
1424

1525
stream.write_all(response.as_bytes()).await.ok();
26+
stream.shutdown(Shutdown::Both).ok();
1627
});
1728
}
1829
}

start.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
sh -c 'while true; do top -b -n 1 -o %MEM | head -n 13; sleep 2; done' &
4+
#sh -c 'while true; do cat /proc/meminfo; sleep 10; done' &
5+
#sh -c 'while true; do slabtop -o; sleep 10; done' &
6+
#sh -c 'while true; do cat /proc/meminfo; slabtop -o; echo "alloc calls:"; cat /sys/kernel/slab/kmalloc-4096/alloc_calls; echo "free calls:"; cat /sys/kernel/slab/kmalloc-4096/free_calls; echo 3 > /proc/sys/vm/drop_caches; sleep 10; done' &
7+
8+
vsock-experiment &
9+
10+
sleep infinity

0 commit comments

Comments
 (0)