@farazirfan/costar-server-executor 1.7.34 → 1.7.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/postinstall.js +28 -64
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 1. Ensure the CLI entry point is executable
|
|
6
6
|
* 2. Attempt to install Playwright Chromium (for browser tool)
|
|
7
7
|
* 3. Create ~/.costar directory
|
|
8
|
-
* 4. Install Docker
|
|
8
|
+
* 4. Install Docker on Linux if missing (image auto-builds on first browser use)
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import fs from "node:fs";
|
|
@@ -109,80 +109,44 @@ function installPlaywrightBrowsers() {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
function
|
|
112
|
+
function ensureDocker() {
|
|
113
113
|
// Only on Linux (Hetzner / sandbox VMs)
|
|
114
114
|
if (process.platform !== "linux") return;
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// Step 1: Install Docker if not present
|
|
116
|
+
// Check if Docker is already installed
|
|
119
117
|
const dockerCheck = spawnSync("docker", ["--version"], { stdio: "pipe", timeout: 5000 });
|
|
120
|
-
if (dockerCheck.status
|
|
121
|
-
console.log("[postinstall] Docker not found, installing...");
|
|
122
|
-
const whoami = spawnSync("whoami", [], { stdio: "pipe", encoding: "utf-8", timeout: 3000 });
|
|
123
|
-
const isRoot = whoami.stdout?.trim() === "root";
|
|
124
|
-
const sudo = isRoot ? "" : "sudo ";
|
|
125
|
-
|
|
126
|
-
const installResult = spawnSync("sh", ["-c",
|
|
127
|
-
`curl -fsSL https://get.docker.com | ${sudo}sh 2>&1`
|
|
128
|
-
], {
|
|
129
|
-
stdio: "inherit",
|
|
130
|
-
timeout: 180_000, // 3 min
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
if (installResult.status !== 0) {
|
|
134
|
-
console.warn("[postinstall] Docker install failed (browser will work without live view)");
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
console.log("[postinstall] Docker installed successfully");
|
|
138
|
-
} else {
|
|
118
|
+
if (dockerCheck.status === 0) {
|
|
139
119
|
console.log("[postinstall] Docker already installed");
|
|
120
|
+
return;
|
|
140
121
|
}
|
|
141
122
|
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const isRoot = whoami.stdout?.trim() === "root";
|
|
148
|
-
const sudo = isRoot ? "" : "sudo ";
|
|
149
|
-
spawnSync("sh", ["-c", `${sudo}systemctl start docker 2>&1 || ${sudo}service docker start 2>&1`], {
|
|
150
|
-
stdio: "inherit",
|
|
151
|
-
timeout: 15_000,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
123
|
+
// Install Docker
|
|
124
|
+
console.log("[postinstall] Docker not found, installing...");
|
|
125
|
+
const whoami = spawnSync("whoami", [], { stdio: "pipe", encoding: "utf-8", timeout: 3000 });
|
|
126
|
+
const isRoot = whoami.stdout?.trim() === "root";
|
|
127
|
+
const sudo = isRoot ? "" : "sudo ";
|
|
154
128
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
129
|
+
const installResult = spawnSync("sh", ["-c",
|
|
130
|
+
`curl -fsSL https://get.docker.com | ${sudo}sh 2>&1`
|
|
131
|
+
], {
|
|
132
|
+
stdio: "inherit",
|
|
133
|
+
timeout: 180_000, // 3 min
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
if (installResult.status !== 0) {
|
|
137
|
+
console.warn("[postinstall] Docker install failed (browser sandbox will not be available)");
|
|
159
138
|
return;
|
|
160
139
|
}
|
|
140
|
+
console.log("[postinstall] Docker installed successfully");
|
|
161
141
|
|
|
162
|
-
//
|
|
163
|
-
|
|
164
|
-
stdio: "
|
|
165
|
-
timeout:
|
|
142
|
+
// Start Docker daemon
|
|
143
|
+
spawnSync("sh", ["-c", `${sudo}systemctl start docker 2>&1 || ${sudo}service docker start 2>&1`], {
|
|
144
|
+
stdio: "inherit",
|
|
145
|
+
timeout: 15_000,
|
|
166
146
|
});
|
|
167
|
-
if (imageCheck.status === 0) {
|
|
168
|
-
console.log("[postinstall] Docker sandbox browser image already exists");
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
147
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (fs.existsSync(setupScript)) {
|
|
175
|
-
const buildResult = spawnSync("bash", [setupScript], {
|
|
176
|
-
stdio: "inherit",
|
|
177
|
-
timeout: 300_000, // 5 min
|
|
178
|
-
cwd: repoRoot,
|
|
179
|
-
});
|
|
180
|
-
if (buildResult.status === 0) {
|
|
181
|
-
console.log("[postinstall] Sandbox browser Docker image built successfully");
|
|
182
|
-
} else {
|
|
183
|
-
console.warn("[postinstall] Docker image build failed (browser will work without live view)");
|
|
184
|
-
}
|
|
185
|
-
}
|
|
148
|
+
// Note: Docker image will be auto-built on first browser use (see browser-container.ts)
|
|
149
|
+
console.log("[postinstall] Docker image will be built automatically on first browser use");
|
|
186
150
|
}
|
|
187
151
|
|
|
188
152
|
// ─── Main ──────────────────────────────────────────────────────
|
|
@@ -206,8 +170,8 @@ try {
|
|
|
206
170
|
// Install Chromium (optional, may fail gracefully)
|
|
207
171
|
installPlaywrightBrowsers();
|
|
208
172
|
|
|
209
|
-
// Install Docker
|
|
210
|
-
|
|
173
|
+
// Install Docker on Linux (image auto-builds on first browser use)
|
|
174
|
+
ensureDocker();
|
|
211
175
|
}
|
|
212
176
|
} catch (err) {
|
|
213
177
|
// Postinstall should never fail the npm install
|