@computesdk/docker 1.2.45 → 1.2.46
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/README.md +19 -79
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,26 +35,6 @@ Common environment variables (used by Docker/dockerode):
|
|
|
35
35
|
|
|
36
36
|
## Usage
|
|
37
37
|
|
|
38
|
-
### Gateway Mode (Recommended)
|
|
39
|
-
|
|
40
|
-
Use the gateway for zero-config auto-detection:
|
|
41
|
-
|
|
42
|
-
```ts
|
|
43
|
-
import { compute } from 'computesdk';
|
|
44
|
-
|
|
45
|
-
// Auto-detects Docker (requires Docker daemon running)
|
|
46
|
-
const sandbox = await compute.sandbox.create();
|
|
47
|
-
|
|
48
|
-
const result = await sandbox.runCommand('python -c "print(\"Hello from Python\")"');
|
|
49
|
-
console.log(result.stdout.trim()); // Hello from Python
|
|
50
|
-
|
|
51
|
-
await sandbox.destroy();
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Direct Mode
|
|
55
|
-
|
|
56
|
-
For direct SDK usage without the gateway:
|
|
57
|
-
|
|
58
38
|
```ts
|
|
59
39
|
import { docker } from '@computesdk/docker';
|
|
60
40
|
|
|
@@ -90,7 +70,7 @@ const sandbox = await compute.sandbox.create();
|
|
|
90
70
|
const result = await sandbox.runCommand('node -e "console.log(\"Hello, World!\")"');
|
|
91
71
|
console.log(result.stdout.trim()); // Hello, World!
|
|
92
72
|
|
|
93
|
-
const cmd = await sandbox.runCommand('
|
|
73
|
+
const cmd = await sandbox.runCommand('echo Hello from command');
|
|
94
74
|
console.log(cmd.stdout.trim()); // Hello from command
|
|
95
75
|
|
|
96
76
|
await sandbox.destroy();
|
|
@@ -186,24 +166,15 @@ Type: `DockerConfig`
|
|
|
186
166
|
|
|
187
167
|
## API Reference
|
|
188
168
|
|
|
189
|
-
### Code Execution
|
|
190
|
-
|
|
191
|
-
```ts
|
|
192
|
-
sandbox.runCommand(code: string, runtime?: 'python' | 'node'): Promise<ExecutionResult>
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
* If `runtime` omitted, the sandbox’s runtime (set at creation) is used.
|
|
196
|
-
* Returns `{ stdout, stderr, exitCode, executionTime, sandboxId, provider }`
|
|
197
|
-
* Syntax errors are **thrown** as `Error("Syntax error: …")`.
|
|
198
|
-
|
|
199
169
|
### Command Execution
|
|
200
170
|
|
|
201
171
|
```ts
|
|
202
|
-
sandbox.runCommand(command: string,
|
|
172
|
+
sandbox.runCommand(command: string, options?: RunCommandOptions): Promise<CommandResult>
|
|
203
173
|
```
|
|
204
174
|
|
|
205
175
|
* Runs via `/bin/sh -c "…"` with stdout/stderr capture.
|
|
206
|
-
*
|
|
176
|
+
* Returns `{ stdout, stderr, exitCode, durationMs }`.
|
|
177
|
+
* Options: `{ cwd?, env?, timeout?, background? }`.
|
|
207
178
|
|
|
208
179
|
### Filesystem Operations
|
|
209
180
|
|
|
@@ -220,14 +191,14 @@ sandbox.filesystem.remove(path)
|
|
|
220
191
|
|
|
221
192
|
### Terminal Operations
|
|
222
193
|
|
|
223
|
-
Interactive terminals aren’t exposed. Use `runCommand('
|
|
194
|
+
Interactive terminals aren’t exposed. Use `runCommand('…')` for non-interactive sessions.
|
|
224
195
|
|
|
225
196
|
### Sandbox Management
|
|
226
197
|
|
|
227
198
|
```ts
|
|
228
|
-
const sandbox = await compute.sandbox.create(
|
|
199
|
+
const sandbox = await compute.sandbox.create();
|
|
229
200
|
|
|
230
|
-
await sandbox.getInfo(); // { id, provider,
|
|
201
|
+
await sandbox.getInfo(); // { id, provider, status, createdAt, timeout, metadata }
|
|
231
202
|
await sandbox.getUrl({ port, protocol?: 'http' | 'https' });
|
|
232
203
|
sandbox.getInstance(); // { docker: Docker, container: Container, ... }
|
|
233
204
|
await sandbox.destroy();
|
|
@@ -235,25 +206,13 @@ await sandbox.destroy();
|
|
|
235
206
|
|
|
236
207
|
---
|
|
237
208
|
|
|
238
|
-
## Runtime Detection
|
|
239
|
-
|
|
240
|
-
There’s **no auto-detection**. Resolution is:
|
|
241
|
-
|
|
242
|
-
1. provider `config.runtime`, else
|
|
243
|
-
2. fallback default in provider config
|
|
244
|
-
|
|
245
|
-
Use `runCommand('python -c "..."')` or `runCommand('node -e "..."')` when you need language-specific execution.
|
|
246
|
-
|
|
247
|
-
---
|
|
248
|
-
|
|
249
209
|
## Error Handling
|
|
250
210
|
|
|
251
|
-
* **
|
|
252
|
-
* **Runtime/command errors** → returned as non-zero `exitCode` with `stderr`
|
|
211
|
+
* **Command errors** → returned as non-zero `exitCode` with `stderr`
|
|
253
212
|
* **Docker errors** (pull/start/exec) → **thrown**
|
|
254
213
|
|
|
255
214
|
```ts
|
|
256
|
-
const res = await sb.runCommand('
|
|
215
|
+
const res = await sb.runCommand('bad-command');
|
|
257
216
|
if (res.exitCode !== 0) {
|
|
258
217
|
console.error('stderr:', res.stderr);
|
|
259
218
|
}
|
|
@@ -261,55 +220,36 @@ if (res.exitCode !== 0) {
|
|
|
261
220
|
|
|
262
221
|
---
|
|
263
222
|
|
|
264
|
-
## Web Framework Integration
|
|
265
|
-
|
|
266
|
-
```ts
|
|
267
|
-
import { handleComputeRequest } from 'computesdk';
|
|
268
|
-
import { docker } from '@computesdk/docker';
|
|
269
|
-
|
|
270
|
-
const compute = docker({
|
|
271
|
-
runtime: 'node',
|
|
272
|
-
image: { name: 'node:20-alpine' },
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
export async function POST(req: Request) {
|
|
276
|
-
const body = await req.json(); // ComputeRequest
|
|
277
|
-
return handleComputeRequest(body, compute);
|
|
278
|
-
}
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
---
|
|
282
|
-
|
|
283
223
|
## Examples
|
|
284
224
|
|
|
285
225
|
### Data Science Workflow (Python)
|
|
286
226
|
|
|
287
227
|
```ts
|
|
288
|
-
const sandbox = await compute.sandbox.create(
|
|
289
|
-
await sandbox.runCommand('
|
|
228
|
+
const sandbox = await compute.sandbox.create();
|
|
229
|
+
await sandbox.runCommand('python3 -m pip install --no-cache-dir pandas');
|
|
290
230
|
await sandbox.filesystem.writeFile('/workspace/app.py', `
|
|
291
231
|
import pandas as pd
|
|
292
232
|
print("rows:", len(pd.DataFrame({"x":[1,2,3]})))
|
|
293
233
|
`);
|
|
294
|
-
const run = await sandbox.runCommand('
|
|
234
|
+
const run = await sandbox.runCommand('python3 /workspace/app.py');
|
|
295
235
|
console.log(run.stdout.trim()); // rows: 3
|
|
296
236
|
await sandbox.destroy();
|
|
297
237
|
```
|
|
298
238
|
|
|
299
|
-
###
|
|
239
|
+
### Stateful Loop
|
|
300
240
|
|
|
301
241
|
```ts
|
|
302
|
-
const sandbox = await compute.sandbox.create(
|
|
303
|
-
await sandbox.runCommand('
|
|
304
|
-
await sandbox.runCommand('
|
|
242
|
+
const sandbox = await compute.sandbox.create();
|
|
243
|
+
await sandbox.runCommand('echo boot > /tmp/state');
|
|
244
|
+
const res = await sandbox.runCommand('cat /tmp/state'); // 'boot'
|
|
305
245
|
await sandbox.destroy();
|
|
306
246
|
```
|
|
307
247
|
|
|
308
|
-
###
|
|
248
|
+
### Background Process + Ports
|
|
309
249
|
|
|
310
250
|
```ts
|
|
311
|
-
const sandbox = await compute.sandbox.create(
|
|
312
|
-
|
|
251
|
+
const sandbox = await compute.sandbox.create();
|
|
252
|
+
await sandbox.runCommand('python3 -m http.server 8080', { background: true });
|
|
313
253
|
const url = await sandbox.getUrl({ port: 8080 });
|
|
314
254
|
console.log('Serving at', url);
|
|
315
255
|
await sandbox.destroy();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@computesdk/docker",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.46",
|
|
4
4
|
"description": "Docker provider for ComputeSDK - local containerized sandboxes for development and testing",
|
|
5
5
|
"author": "IberAI",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"dockerode": "^4.0.8",
|
|
22
|
-
"@computesdk/provider": "2.
|
|
23
|
-
"computesdk": "4.
|
|
22
|
+
"@computesdk/provider": "2.1.0",
|
|
23
|
+
"computesdk": "4.1.0"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [
|
|
26
26
|
"computesdk",
|