Skip to content

Commit c3ff244

Browse files
committed
dockerized worker
1 parent c77764a commit c3ff244

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

ui/src/worker.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,44 @@ impl From<(JobReport, serde_json::Value, ResponseKind)> for WSResponse {
624624
}
625625
}
626626

627+
macro_rules! docker_command {
628+
($($arg:expr),* $(,)?) => ({
629+
let mut cmd = Command::new("docker");
630+
$( cmd.arg($arg); )*
631+
cmd
632+
});
633+
}
634+
635+
fn basic_secure_docker_command() -> Command {
636+
docker_command!(
637+
"run",
638+
"--platform",
639+
"linux/amd64",
640+
"--cap-drop=ALL",
641+
// Needed to allow overwriting the file
642+
"--security-opt=no-new-privileges",
643+
"--net",
644+
"none",
645+
"--memory",
646+
"512m",
647+
"--memory-swap",
648+
"640m",
649+
"--pids-limit",
650+
"512",
651+
)
652+
}
653+
654+
627655
fn run_worker_in_background() -> Result<(ChildStdin, ChildStdout)> {
628-
const WORKER_FILEPATH: &str = "../worker-message/target/debug/worker";
656+
// For local development.
657+
// const WORKER_FILEPATH: &str = "../worker-message/target/debug/worker";
658+
629659
// No need to track Child.
630660
// We know whether it exits via channels.
631-
let mut child = Command::new(WORKER_FILEPATH)
661+
// let mut child = Command::new(WORKER_FILEPATH)
662+
let mut child = basic_secure_docker_command()
663+
.arg("-i")
664+
.arg("adwinw/rust-playground-worker")
632665
.stdin(Stdio::piped())
633666
.stdout(Stdio::piped())
634667
.spawn()

worker-message/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 1. This tells docker to use the Rust official image
2+
FROM rust:1.68
3+
4+
# 2. Copy the files in your machine to the Docker image
5+
COPY ./ ./
6+
7+
# Build your program for release
8+
RUN cargo build --release
9+
10+
# Run the binary
11+
CMD ["./target/release/worker"]

worker-message/src/worker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub async fn listen() {
7373

7474
let project_path = project_dir.path();
7575
loop {
76-
let coordinator_msg = coordinator_rx.recv().await.expect("Failed to received CoordinatorMessage from deserialization task");
76+
let coordinator_msg = coordinator_rx.recv().await.expect("Failed to receive CoordinatorMessage from deserialization task");
7777
info!("{:#?}", coordinator_msg);
7878
match coordinator_msg {
7979
CoordinatorMessage::Request(job_id, job) => {

0 commit comments

Comments
 (0)