MCPcopy Create free account
hub / github.com/cloudflare/computer / bootContainer

Function bootContainer

script/computerd-fuse-flush.mjs:42–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40const ADD_HOST_GATEWAY = process.platform === "linux";
41
42async function bootContainer() {
43 const args = [
44 "run",
45 "--rm",
46 "-d",
47 "--platform",
48 "linux/amd64",
49 "--privileged",
50 "--device",
51 "/dev/fuse",
52 "--cap-add",
53 "SYS_ADMIN",
54 "--cap-add",
55 "MKNOD",
56 "--security-opt",
57 "apparmor=unconfined",
58 "--security-opt",
59 "seccomp=unconfined",
60 ];
61 if (ADD_HOST_GATEWAY) {
62 args.push("--add-host", "host.docker.internal:host-gateway");
63 }
64 args.push(
65 "-v",
66 `${BINARY}:/usr/local/bin/computerd:ro`,
67 "-p",
68 "0:8080",
69 "-e",
70 "PORT=8080",
71 "-e",
72 "MOUNT_POINT=/workspace",
73 "debian:stable-slim",
74 "bash",
75 "-c",
76 // libfuse2 + a long-lived shell so we can `docker exec` into the
77 // same mount namespace where computerd mounted FUSE. computerd backgrounds
78 // and we tail /tmp/computerd.log for debugging.
79 "apt-get update >/dev/null 2>&1 && " +
80 "apt-get install -y --no-install-recommends fuse3 libfuse2t64 >/dev/null 2>&1 && " +
81 "mkdir -p /workspace && " +
82 "/usr/local/bin/computerd >/tmp/computerd.log 2>&1 & " +
83 "COMPUTERD_PID=$!; " +
84 "trap 'kill $COMPUTERD_PID 2>/dev/null' EXIT; " +
85 "wait $COMPUTERD_PID",
86 );
87 const { stdout } = await execFileP("docker", args);
88 const cid = stdout.trim();
89 const { stdout: portOut } = await execFileP("docker", ["port", cid, "8080/tcp"]);
90 const port = Number(portOut.split("\n")[0].split(":").pop());
91 const url = `http://127.0.0.1:${port}`;
92
93 const deadline = Date.now() + 60_000;
94 while (Date.now() < deadline) {
95 try {
96 const r = await fetch(`${url}/health`);
97 if (r.ok) return { cid, url, port };
98 } catch {
99 /* not ready */

Callers 1

mainFunction · 0.70

Calls 2

pushMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected