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

Function bootContainer

script/computerd-soak.mjs:93–148  ·  view source on GitHub ↗
(extraEnv = {})

Source from the content-addressed store, hash-verified

91}
92
93async function bootContainer(extraEnv = {}) {
94 const args = ["run", "--rm", "-d", "--platform", "linux/amd64"];
95 if (!DISABLE_FUSE) {
96 args.push(
97 "--privileged",
98 "--device",
99 "/dev/fuse",
100 "--cap-add",
101 "SYS_ADMIN",
102 "--cap-add",
103 "MKNOD",
104 "--security-opt",
105 "apparmor=unconfined",
106 "--security-opt",
107 "seccomp=unconfined",
108 );
109 }
110 if (ADD_HOST_GATEWAY) {
111 args.push("--add-host", "host.docker.internal:host-gateway");
112 }
113 args.push(
114 "-v",
115 `${BINARY}:/usr/local/bin/computerd:ro`,
116 "-p",
117 "0:8080",
118 "-e",
119 "PORT=8080",
120 "-e",
121 "MOUNT_POINT=/workspace",
122 );
123 if (DISABLE_FUSE) {
124 args.push("-e", "FUSE_MOUNT=none");
125 }
126 for (const [k, v] of Object.entries(extraEnv)) {
127 args.push("-e", `${k}=${v}`);
128 }
129 const image = DISABLE_FUSE ? "debian:stable-slim" : IMAGE_TAG;
130 args.push(image, "/usr/local/bin/computerd");
131 const { stdout } = await execFileP("docker", args);
132 const cid = stdout.trim();
133 const { stdout: portOut } = await execFileP("docker", ["port", cid, "8080/tcp"]);
134 const port = Number(portOut.split("\n")[0].split(":").pop());
135 const url = `http://127.0.0.1:${port}`;
136 // Wait for /health
137 const deadline = Date.now() + 30_000;
138 while (Date.now() < deadline) {
139 try {
140 const r = await fetch(`${url}/health`);
141 if (r.ok) return { cid, url, port };
142 } catch {
143 /* not ready */
144 }
145 await new Promise((r) => setTimeout(r, 250));
146 }
147 throw new Error(`container ${cid} did not become healthy`);
148}
149
150async function kill(cid) {

Callers 1

mainFunction · 0.70

Calls 2

pushMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected