@daytonaio/sdk 0.17.0 → 0.18.0-alpha.1
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/dist/Daytona.d.ts +73 -4
- package/dist/Daytona.js +113 -34
- package/dist/Image.d.ts +261 -0
- package/dist/Image.js +557 -0
- package/dist/ObjectStorage.d.ts +85 -0
- package/dist/ObjectStorage.js +223 -0
- package/dist/Process.d.ts +0 -1
- package/dist/Process.js +4 -69
- package/dist/Sandbox.d.ts +1 -1
- package/dist/Sandbox.js +12 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/utils/Stream.d.ts +2 -0
- package/dist/utils/Stream.js +66 -0
- package/package.json +13 -4
package/dist/Daytona.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CreateWorkspaceTargetEnum as SandboxTargetRegion, WorkspaceVolume } from '@daytonaio/api-client';
|
|
2
|
+
import { Image } from './Image';
|
|
2
3
|
import { Sandbox, Sandbox as Workspace } from './Sandbox';
|
|
3
4
|
import { VolumeService } from './Volume';
|
|
4
5
|
/**
|
|
@@ -88,7 +89,7 @@ export interface SandboxResources {
|
|
|
88
89
|
* Parameters for creating a new Sandbox.
|
|
89
90
|
*
|
|
90
91
|
* @interface
|
|
91
|
-
* @property {string} [image] - Optional Docker image to use for the Sandbox
|
|
92
|
+
* @property {string | Image} [image] - Optional Docker image to use for the Sandbox or an Image instance
|
|
92
93
|
* @property {string} [user] - Optional os user to use for the Sandbox
|
|
93
94
|
* @property {CodeLanguage | string} [language] - Programming language for direct code execution
|
|
94
95
|
* @property {Record<string, string>} [envVars] - Optional environment variables to set in the Sandbox
|
|
@@ -113,8 +114,8 @@ export interface SandboxResources {
|
|
|
113
114
|
* const sandbox = await daytona.create(params, 50);
|
|
114
115
|
*/
|
|
115
116
|
export type CreateSandboxParams = {
|
|
116
|
-
/** Optional Docker image to use for the Sandbox */
|
|
117
|
-
image?: string;
|
|
117
|
+
/** Optional Docker image to use for the Sandbox or an Image instance */
|
|
118
|
+
image?: string | Image;
|
|
118
119
|
/** Optional os user to use for the Sandbox */
|
|
119
120
|
user?: string;
|
|
120
121
|
/** Programming language for direct code execution */
|
|
@@ -179,6 +180,8 @@ export type SandboxFilter = {
|
|
|
179
180
|
export declare class Daytona {
|
|
180
181
|
private readonly sandboxApi;
|
|
181
182
|
private readonly toolboxApi;
|
|
183
|
+
private readonly imagesApi;
|
|
184
|
+
private readonly objectStorageApi;
|
|
182
185
|
private readonly target;
|
|
183
186
|
private readonly apiKey?;
|
|
184
187
|
private readonly jwtToken?;
|
|
@@ -193,6 +196,8 @@ export declare class Daytona {
|
|
|
193
196
|
*/
|
|
194
197
|
constructor(config?: DaytonaConfig);
|
|
195
198
|
/**
|
|
199
|
+
* @deprecated Use `create` with `options` object instead. This method will be removed in a future version.
|
|
200
|
+
*
|
|
196
201
|
* Creates Sandboxes with default or custom configurations. You can specify various parameters,
|
|
197
202
|
* including language, image, resources, environment variables, and volumes for the Sandbox.
|
|
198
203
|
*
|
|
@@ -221,7 +226,45 @@ export declare class Daytona {
|
|
|
221
226
|
* };
|
|
222
227
|
* const sandbox = await daytona.create(params, 40);
|
|
223
228
|
*/
|
|
224
|
-
create(params?: CreateSandboxParams,
|
|
229
|
+
create(params?: CreateSandboxParams, options?: number): Promise<Sandbox>;
|
|
230
|
+
/**
|
|
231
|
+
* Creates Sandboxes with default or custom configurations. You can specify various parameters,
|
|
232
|
+
* including language, image, resources, environment variables, and volumes for the Sandbox.
|
|
233
|
+
*
|
|
234
|
+
* @param {CreateSandboxParams} [params] - Parameters for Sandbox creation
|
|
235
|
+
* @param {object} [options] - Options for the create operation
|
|
236
|
+
* @param {number} [options.timeout] - Timeout in seconds (0 means no timeout, default is 60)
|
|
237
|
+
* @param {function} [options.onImageBuildLogs] - Callback function to handle image build logs.
|
|
238
|
+
* It's invoked only when `params.image` is an instance of `Image` and there's no existing
|
|
239
|
+
* image in Daytona with the same configuration.
|
|
240
|
+
* @returns {Promise<Sandbox>} The created Sandbox instance
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* const image = Image.debianSlim('3.12').pipInstall('numpy');
|
|
244
|
+
* const sandbox = await daytona.create({ image }, { timeout: 90, onImageBuildLogs: console.log });
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* // Create a custom sandbox
|
|
248
|
+
* const image = Image.debianSlim('3.12').pipInstall('numpy');
|
|
249
|
+
* const params: CreateSandboxParams = {
|
|
250
|
+
* language: 'typescript',
|
|
251
|
+
* image,
|
|
252
|
+
* envVars: {
|
|
253
|
+
* NODE_ENV: 'development',
|
|
254
|
+
* DEBUG: 'true'
|
|
255
|
+
* },
|
|
256
|
+
* resources: {
|
|
257
|
+
* cpu: 2,
|
|
258
|
+
* memory: 4 // 4GB RAM
|
|
259
|
+
* },
|
|
260
|
+
* autoStopInterval: 60
|
|
261
|
+
* };
|
|
262
|
+
* const sandbox = await daytona.create(params, { timeout: 100, onImageBuildLogs: console.log });
|
|
263
|
+
*/
|
|
264
|
+
create(params?: CreateSandboxParams, options?: {
|
|
265
|
+
onImageBuildLogs?: (chunk: string) => void;
|
|
266
|
+
timeout?: number;
|
|
267
|
+
}): Promise<Sandbox>;
|
|
225
268
|
/**
|
|
226
269
|
* Gets a Sandbox by its ID.
|
|
227
270
|
*
|
|
@@ -315,6 +358,24 @@ export declare class Daytona {
|
|
|
315
358
|
* console.log(`Current sandbox state: ${sandbox.instance.state}`);
|
|
316
359
|
*/
|
|
317
360
|
getCurrentSandbox(sandboxId: string): Promise<Sandbox>;
|
|
361
|
+
/**
|
|
362
|
+
* Creates and registers a new image from the given Image definition.
|
|
363
|
+
*
|
|
364
|
+
* @param {string} name - The name of the image to create.
|
|
365
|
+
* @param {Image} image - The Image instance.
|
|
366
|
+
* @param {object} options - Options for the create operation.
|
|
367
|
+
* @param {boolean} options.verbose - Default is false. Whether to log progress information upon each state change of the image.
|
|
368
|
+
* @param {number} options.timeout - Default is no timeout. Timeout in seconds (0 means no timeout).
|
|
369
|
+
* @returns {Promise<void>}
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* const image = Image.debianSlim('3.12').pipInstall('numpy');
|
|
373
|
+
* await daytona.createImage('my-python-image', image);
|
|
374
|
+
*/
|
|
375
|
+
createImage(name: string, image: Image, options?: {
|
|
376
|
+
onLogs?: (chunk: string) => void;
|
|
377
|
+
timeout?: number;
|
|
378
|
+
}): Promise<void>;
|
|
318
379
|
/**
|
|
319
380
|
* Gets the appropriate code toolbox based on language.
|
|
320
381
|
*
|
|
@@ -324,4 +385,12 @@ export declare class Daytona {
|
|
|
324
385
|
* @throws {DaytonaError} - `DaytonaError` - When an unsupported language is specified
|
|
325
386
|
*/
|
|
326
387
|
private getCodeToolbox;
|
|
388
|
+
/**
|
|
389
|
+
* Processes the image contexts by uploading them to object storage
|
|
390
|
+
*
|
|
391
|
+
* @private
|
|
392
|
+
* @param {Image} image - The Image instance.
|
|
393
|
+
* @returns {Promise<string[]>} The list of context hashes stored in object storage.
|
|
394
|
+
*/
|
|
395
|
+
private processImageContext;
|
|
327
396
|
}
|
package/dist/Daytona.js
CHANGED
|
@@ -43,7 +43,10 @@ const dotenv_1 = __importDefault(require("dotenv"));
|
|
|
43
43
|
const SandboxPythonCodeToolbox_1 = require("./code-toolbox/SandboxPythonCodeToolbox");
|
|
44
44
|
const SandboxTsCodeToolbox_1 = require("./code-toolbox/SandboxTsCodeToolbox");
|
|
45
45
|
const DaytonaError_1 = require("./errors/DaytonaError");
|
|
46
|
+
const Image_1 = require("./Image");
|
|
47
|
+
const ObjectStorage_1 = require("./ObjectStorage");
|
|
46
48
|
const Sandbox_1 = require("./Sandbox");
|
|
49
|
+
const Stream_1 = require("./utils/Stream");
|
|
47
50
|
const Volume_1 = require("./Volume");
|
|
48
51
|
/**
|
|
49
52
|
* Supported programming languages for code execution
|
|
@@ -158,39 +161,16 @@ class Daytona {
|
|
|
158
161
|
this.sandboxApi = new api_client_1.WorkspaceApi(configuration, '', axiosInstance);
|
|
159
162
|
this.toolboxApi = new api_client_1.ToolboxApi(configuration, '', axiosInstance);
|
|
160
163
|
this.volume = new Volume_1.VolumeService(new api_client_1.VolumesApi(configuration, '', axiosInstance));
|
|
164
|
+
this.imagesApi = new api_client_1.ImagesApi(configuration, '', axiosInstance);
|
|
165
|
+
this.objectStorageApi = new api_client_1.ObjectStorageApi(configuration, '', axiosInstance);
|
|
161
166
|
}
|
|
162
|
-
|
|
163
|
-
* Creates Sandboxes with default or custom configurations. You can specify various parameters,
|
|
164
|
-
* including language, image, resources, environment variables, and volumes for the Sandbox.
|
|
165
|
-
*
|
|
166
|
-
* @param {CreateSandboxParams} [params] - Parameters for Sandbox creation
|
|
167
|
-
* @param {number} [timeout] - Timeout in seconds (0 means no timeout, default is 60)
|
|
168
|
-
* @returns {Promise<Sandbox>} The created Sandbox instance
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* // Create a default sandbox
|
|
172
|
-
* const sandbox = await daytona.create();
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* // Create a custom sandbox
|
|
176
|
-
* const params: CreateSandboxParams = {
|
|
177
|
-
* language: 'typescript',
|
|
178
|
-
* image: 'node:18',
|
|
179
|
-
* envVars: {
|
|
180
|
-
* NODE_ENV: 'development',
|
|
181
|
-
* DEBUG: 'true'
|
|
182
|
-
* },
|
|
183
|
-
* resources: {
|
|
184
|
-
* cpu: 2,
|
|
185
|
-
* memory: 4 // 4GB RAM
|
|
186
|
-
* },
|
|
187
|
-
* autoStopInterval: 60
|
|
188
|
-
* };
|
|
189
|
-
* const sandbox = await daytona.create(params, 40);
|
|
190
|
-
*/
|
|
191
|
-
async create(params, timeout = 60) {
|
|
167
|
+
async create(params, options = { timeout: 60 }) {
|
|
192
168
|
var _a, _b, _c, _d;
|
|
193
169
|
const startTime = Date.now();
|
|
170
|
+
options = typeof options === 'number' ? { timeout: options } : { ...options };
|
|
171
|
+
if (options.timeout == undefined || options.timeout == null) {
|
|
172
|
+
options.timeout = 60;
|
|
173
|
+
}
|
|
194
174
|
if (params == null) {
|
|
195
175
|
params = { language: 'python' };
|
|
196
176
|
}
|
|
@@ -199,7 +179,7 @@ class Daytona {
|
|
|
199
179
|
labels['code-toolbox-language'] = params.language;
|
|
200
180
|
}
|
|
201
181
|
// remove this when params.timeout is removed
|
|
202
|
-
const effectiveTimeout = params.timeout || timeout;
|
|
182
|
+
const effectiveTimeout = params.timeout || options.timeout;
|
|
203
183
|
if (effectiveTimeout < 0) {
|
|
204
184
|
throw new DaytonaError_1.DaytonaError('Timeout must be a non-negative number');
|
|
205
185
|
}
|
|
@@ -209,8 +189,22 @@ class Daytona {
|
|
|
209
189
|
}
|
|
210
190
|
const codeToolbox = this.getCodeToolbox(params.language);
|
|
211
191
|
try {
|
|
192
|
+
// Handle Image instance if provided
|
|
193
|
+
let imageStr;
|
|
194
|
+
let buildInfo;
|
|
195
|
+
if (typeof params.image === 'string') {
|
|
196
|
+
imageStr = params.image;
|
|
197
|
+
}
|
|
198
|
+
else if (params.image instanceof Image_1.Image) {
|
|
199
|
+
const contextHashes = await this.processImageContext(params.image);
|
|
200
|
+
buildInfo = {
|
|
201
|
+
contextHashes,
|
|
202
|
+
dockerfileContent: params.image.dockerfile,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
212
205
|
const response = await this.sandboxApi.createWorkspace({
|
|
213
|
-
image:
|
|
206
|
+
image: imageStr,
|
|
207
|
+
buildInfo,
|
|
214
208
|
user: params.user,
|
|
215
209
|
env: params.envVars || {},
|
|
216
210
|
labels: params.labels,
|
|
@@ -225,14 +219,21 @@ class Daytona {
|
|
|
225
219
|
}, undefined, {
|
|
226
220
|
timeout: effectiveTimeout * 1000,
|
|
227
221
|
});
|
|
228
|
-
|
|
222
|
+
let sandboxInstance = response.data;
|
|
223
|
+
if (sandboxInstance.state === api_client_1.WorkspaceState.PENDING_BUILD && options.onImageBuildLogs) {
|
|
224
|
+
const terminalStates = [api_client_1.WorkspaceState.STARTED, api_client_1.WorkspaceState.STARTING, api_client_1.WorkspaceState.ERROR];
|
|
225
|
+
await (0, Stream_1.processStreamingResponse)(() => this.sandboxApi.getBuildLogs(sandboxInstance.id, undefined, true, { responseType: 'stream' }), options.onImageBuildLogs, async () => {
|
|
226
|
+
sandboxInstance = (await this.sandboxApi.getWorkspace(sandboxInstance.id)).data;
|
|
227
|
+
return sandboxInstance.state !== undefined && terminalStates.includes(sandboxInstance.state);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
229
230
|
const sandboxInfo = Sandbox_1.Sandbox.toSandboxInfo(sandboxInstance);
|
|
230
231
|
sandboxInstance.info = {
|
|
231
232
|
...sandboxInfo,
|
|
232
233
|
name: '',
|
|
233
234
|
};
|
|
234
235
|
const sandbox = new Sandbox_1.Sandbox(sandboxInstance.id, sandboxInstance, this.sandboxApi, this.toolboxApi, codeToolbox);
|
|
235
|
-
if (!params.async) {
|
|
236
|
+
if (!params.async && sandbox.instance.state !== 'started') {
|
|
236
237
|
const timeElapsed = Date.now() - startTime;
|
|
237
238
|
await sandbox.waitUntilStarted(effectiveTimeout ? effectiveTimeout - timeElapsed / 1000 : 0);
|
|
238
239
|
}
|
|
@@ -378,6 +379,58 @@ class Daytona {
|
|
|
378
379
|
async getCurrentSandbox(sandboxId) {
|
|
379
380
|
return await this.get(sandboxId);
|
|
380
381
|
}
|
|
382
|
+
/**
|
|
383
|
+
* Creates and registers a new image from the given Image definition.
|
|
384
|
+
*
|
|
385
|
+
* @param {string} name - The name of the image to create.
|
|
386
|
+
* @param {Image} image - The Image instance.
|
|
387
|
+
* @param {object} options - Options for the create operation.
|
|
388
|
+
* @param {boolean} options.verbose - Default is false. Whether to log progress information upon each state change of the image.
|
|
389
|
+
* @param {number} options.timeout - Default is no timeout. Timeout in seconds (0 means no timeout).
|
|
390
|
+
* @returns {Promise<void>}
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* const image = Image.debianSlim('3.12').pipInstall('numpy');
|
|
394
|
+
* await daytona.createImage('my-python-image', image);
|
|
395
|
+
*/
|
|
396
|
+
async createImage(name, image, options = {}) {
|
|
397
|
+
const contextHashes = await this.processImageContext(image);
|
|
398
|
+
let builtImage = (await this.imagesApi.buildImage({
|
|
399
|
+
name,
|
|
400
|
+
buildInfo: {
|
|
401
|
+
contextHashes,
|
|
402
|
+
dockerfileContent: image.dockerfile,
|
|
403
|
+
},
|
|
404
|
+
}, undefined, {
|
|
405
|
+
timeout: (options.timeout || 0) * 1000,
|
|
406
|
+
})).data;
|
|
407
|
+
const terminalStates = [api_client_1.ImageState.ACTIVE, api_client_1.ImageState.ERROR];
|
|
408
|
+
const imageRef = { builtImage };
|
|
409
|
+
let streamPromise;
|
|
410
|
+
if (options.onLogs) {
|
|
411
|
+
options.onLogs(`Building image ${builtImage.name} (${builtImage.state})`);
|
|
412
|
+
streamPromise = (0, Stream_1.processStreamingResponse)(() => this.imagesApi.getImageBuildLogs(builtImage.id, undefined, true, { responseType: 'stream' }), options.onLogs, async () => terminalStates.includes(imageRef.builtImage.state));
|
|
413
|
+
}
|
|
414
|
+
let previousState = builtImage.state;
|
|
415
|
+
while (!terminalStates.includes(builtImage.state)) {
|
|
416
|
+
if (options.onLogs && previousState !== builtImage.state) {
|
|
417
|
+
options.onLogs(`Building image ${builtImage.name} (${builtImage.state})`);
|
|
418
|
+
previousState = builtImage.state;
|
|
419
|
+
}
|
|
420
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
421
|
+
builtImage = (await this.imagesApi.getImage(builtImage.id)).data;
|
|
422
|
+
imageRef.builtImage = builtImage;
|
|
423
|
+
}
|
|
424
|
+
if (options.onLogs) {
|
|
425
|
+
await streamPromise;
|
|
426
|
+
if (builtImage.state === api_client_1.ImageState.ACTIVE) {
|
|
427
|
+
options.onLogs(`Built image ${builtImage.name} (${builtImage.state})`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (builtImage.state === api_client_1.ImageState.ERROR) {
|
|
431
|
+
throw new DaytonaError_1.DaytonaError(`Failed to build image. Image ended in the ERROR state. name: ${builtImage.name}; error reason: ${builtImage.errorReason}`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
381
434
|
/**
|
|
382
435
|
* Gets the appropriate code toolbox based on language.
|
|
383
436
|
*
|
|
@@ -398,5 +451,31 @@ class Daytona {
|
|
|
398
451
|
throw new DaytonaError_1.DaytonaError(`Unsupported language: ${language}, supported languages: ${Object.values(CodeLanguage).join(', ')}`);
|
|
399
452
|
}
|
|
400
453
|
}
|
|
454
|
+
/**
|
|
455
|
+
* Processes the image contexts by uploading them to object storage
|
|
456
|
+
*
|
|
457
|
+
* @private
|
|
458
|
+
* @param {Image} image - The Image instance.
|
|
459
|
+
* @returns {Promise<string[]>} The list of context hashes stored in object storage.
|
|
460
|
+
*/
|
|
461
|
+
async processImageContext(image) {
|
|
462
|
+
if (!image.contextList || !image.contextList.length) {
|
|
463
|
+
return [];
|
|
464
|
+
}
|
|
465
|
+
const pushAccessCreds = (await this.objectStorageApi.getPushAccess()).data;
|
|
466
|
+
const objectStorage = new ObjectStorage_1.ObjectStorage({
|
|
467
|
+
endpointUrl: pushAccessCreds.storageUrl,
|
|
468
|
+
accessKeyId: pushAccessCreds.accessKey,
|
|
469
|
+
secretAccessKey: pushAccessCreds.secret,
|
|
470
|
+
sessionToken: pushAccessCreds.sessionToken,
|
|
471
|
+
bucketName: pushAccessCreds.bucket,
|
|
472
|
+
});
|
|
473
|
+
const contextHashes = [];
|
|
474
|
+
for (const context of image.contextList) {
|
|
475
|
+
const contextHash = await objectStorage.upload(context.sourcePath, pushAccessCreds.organizationId, context.archivePath);
|
|
476
|
+
contextHashes.push(contextHash);
|
|
477
|
+
}
|
|
478
|
+
return contextHashes;
|
|
479
|
+
}
|
|
401
480
|
}
|
|
402
481
|
exports.Daytona = Daytona;
|
package/dist/Image.d.ts
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
declare const SUPPORTED_PYTHON_SERIES: readonly ["3.9", "3.10", "3.11", "3.12", "3.13"];
|
|
2
|
+
type SupportedPythonSeries = (typeof SUPPORTED_PYTHON_SERIES)[number];
|
|
3
|
+
/**
|
|
4
|
+
* Represents a context file to be added to the image.
|
|
5
|
+
*
|
|
6
|
+
* @interface
|
|
7
|
+
* @property {string} sourcePath - The path to the source file or directory.
|
|
8
|
+
* @property {string} archivePath - The path inside the archive file in object storage.
|
|
9
|
+
*/
|
|
10
|
+
export interface Context {
|
|
11
|
+
sourcePath: string;
|
|
12
|
+
archivePath?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Options for the pip install command.
|
|
16
|
+
*
|
|
17
|
+
* @interface
|
|
18
|
+
* @property {string[]} findLinks - The find-links to use for the pip install command.
|
|
19
|
+
* @property {string} indexUrl - The index URL to use for the pip install command.
|
|
20
|
+
* @property {string[]} extraIndexUrls - The extra index URLs to use for the pip install command.
|
|
21
|
+
* @property {boolean} pre - Whether to install pre-release versions.
|
|
22
|
+
* @property {string} extraOptions - The extra options to use for the pip install command. Given string is passed directly to the pip install command.
|
|
23
|
+
*/
|
|
24
|
+
export interface PipInstallOptions {
|
|
25
|
+
findLinks?: string[];
|
|
26
|
+
indexUrl?: string;
|
|
27
|
+
extraIndexUrls?: string[];
|
|
28
|
+
pre?: boolean;
|
|
29
|
+
extraOptions?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Options for the pip install command from a pyproject.toml file.
|
|
33
|
+
*
|
|
34
|
+
* @interface
|
|
35
|
+
* @property {string[]} optionalDependencies - The optional dependencies to install.
|
|
36
|
+
*
|
|
37
|
+
* @extends {PipInstallOptions}
|
|
38
|
+
*/
|
|
39
|
+
export interface PyprojectOptions extends PipInstallOptions {
|
|
40
|
+
optionalDependencies?: string[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Represents an image definition for a Daytona sandbox.
|
|
44
|
+
* Do not construct this class directly. Instead use one of its static factory methods,
|
|
45
|
+
* such as `Image.base()`, `Image.debianSlim()` or `Image.fromDockerfile()`.
|
|
46
|
+
*
|
|
47
|
+
* @class
|
|
48
|
+
* @property {string} dockerfile - The Dockerfile content.
|
|
49
|
+
* @property {Context[]} contextList - The list of context files to be added to the image.
|
|
50
|
+
*/
|
|
51
|
+
export declare class Image {
|
|
52
|
+
private _dockerfile;
|
|
53
|
+
private _contextList;
|
|
54
|
+
private constructor();
|
|
55
|
+
get dockerfile(): string;
|
|
56
|
+
get contextList(): Context[];
|
|
57
|
+
/**
|
|
58
|
+
* Adds commands to install packages using pip.
|
|
59
|
+
*
|
|
60
|
+
* @param {string | string[]} packages - The packages to install.
|
|
61
|
+
* @param {Object} options - The options for the pip install command.
|
|
62
|
+
* @param {string[]} options.findLinks - The find-links to use for the pip install command.
|
|
63
|
+
* @returns {Image} The Image instance.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* const image = Image.debianSlim('3.12').pipInstall('numpy', { findLinks: ['https://pypi.org/simple'] })
|
|
67
|
+
*/
|
|
68
|
+
pipInstall(packages: string | string[], options?: PipInstallOptions): Image;
|
|
69
|
+
/**
|
|
70
|
+
* Installs dependencies from a requirements.txt file.
|
|
71
|
+
*
|
|
72
|
+
* @param {string} requirementsTxt - The path to the requirements.txt file.
|
|
73
|
+
* @param {PipInstallOptions} options - The options for the pip install command.
|
|
74
|
+
* @returns {Image} The Image instance.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* const image = Image.debianSlim('3.12')
|
|
78
|
+
* image.pipInstallFromRequirements('requirements.txt', { findLinks: ['https://pypi.org/simple'] })
|
|
79
|
+
*/
|
|
80
|
+
pipInstallFromRequirements(requirementsTxt: string, options?: PipInstallOptions): Image;
|
|
81
|
+
/**
|
|
82
|
+
* Installs dependencies from a pyproject.toml file.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} pyprojectToml - The path to the pyproject.toml file.
|
|
85
|
+
* @param {PyprojectOptions} options - The options for the pip install command.
|
|
86
|
+
* @returns {Image} The Image instance.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* const image = Image.debianSlim('3.12')
|
|
90
|
+
* image.pipInstallFromPyproject('pyproject.toml', { optionalDependencies: ['dev'] })
|
|
91
|
+
*/
|
|
92
|
+
pipInstallFromPyproject(pyprojectToml: string, options?: PyprojectOptions): Image;
|
|
93
|
+
/**
|
|
94
|
+
* Adds a local file to the image.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} localPath - The path to the local file.
|
|
97
|
+
* @param {string} remotePath - The path of the file in the image.
|
|
98
|
+
* @returns {Image} The Image instance.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* const image = Image
|
|
102
|
+
* .debianSlim('3.12')
|
|
103
|
+
* .addLocalFile('requirements.txt', '/home/daytona/requirements.txt')
|
|
104
|
+
*/
|
|
105
|
+
addLocalFile(localPath: string, remotePath: string): Image;
|
|
106
|
+
/**
|
|
107
|
+
* Adds a local directory to the image.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} localPath - The path to the local directory.
|
|
110
|
+
* @param {string} remotePath - The path of the directory in the image.
|
|
111
|
+
* @returns {Image} The Image instance.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* const image = Image
|
|
115
|
+
* .debianSlim('3.12')
|
|
116
|
+
* .addLocalDir('src', '/home/daytona/src')
|
|
117
|
+
*/
|
|
118
|
+
addLocalDir(localPath: string, remotePath: string): Image;
|
|
119
|
+
/**
|
|
120
|
+
* Runs commands in the image.
|
|
121
|
+
*
|
|
122
|
+
* @param {string | string[]} commands - The commands to run.
|
|
123
|
+
* @returns {Image} The Image instance.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* const image = Image
|
|
127
|
+
* .debianSlim('3.12')
|
|
128
|
+
* .runCommands('echo "Hello, world!"')
|
|
129
|
+
*/
|
|
130
|
+
runCommands(...commands: (string | string[])[]): Image;
|
|
131
|
+
/**
|
|
132
|
+
* Sets environment variables in the image.
|
|
133
|
+
*
|
|
134
|
+
* @param {Record<string, string>} envVars - The environment variables to set.
|
|
135
|
+
* @returns {Image} The Image instance.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* const image = Image
|
|
139
|
+
* .debianSlim('3.12')
|
|
140
|
+
* .env({ FOO: 'bar' })
|
|
141
|
+
*/
|
|
142
|
+
env(envVars: Record<string, string>): Image;
|
|
143
|
+
/**
|
|
144
|
+
* Sets the working directory in the image.
|
|
145
|
+
*
|
|
146
|
+
* @param {string} dirPath - The path to the working directory.
|
|
147
|
+
* @returns {Image} The Image instance.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* const image = Image
|
|
151
|
+
* .debianSlim('3.12')
|
|
152
|
+
* .workdir('/home/daytona')
|
|
153
|
+
*/
|
|
154
|
+
workdir(dirPath: string): Image;
|
|
155
|
+
/**
|
|
156
|
+
* Sets the entrypoint for the image.
|
|
157
|
+
*
|
|
158
|
+
* @param {string[]} entrypointCommands - The commands to set as the entrypoint.
|
|
159
|
+
* @returns {Image} The Image instance.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* const image = Image
|
|
163
|
+
* .debianSlim('3.12')
|
|
164
|
+
* .entrypoint(['/bin/bash'])
|
|
165
|
+
*/
|
|
166
|
+
entrypoint(entrypointCommands: string[]): Image;
|
|
167
|
+
/**
|
|
168
|
+
* Sets the default command for the image.
|
|
169
|
+
*
|
|
170
|
+
* @param {string[]} cmd - The command to set as the default command.
|
|
171
|
+
* @returns {Image} The Image instance.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* const image = Image
|
|
175
|
+
* .debianSlim('3.12')
|
|
176
|
+
* .cmd(['/bin/bash'])
|
|
177
|
+
*/
|
|
178
|
+
cmd(cmd: string[]): Image;
|
|
179
|
+
/**
|
|
180
|
+
* Extends an image with arbitrary Dockerfile-like commands.
|
|
181
|
+
*
|
|
182
|
+
* @param {string | string[]} dockerfileCommands - The commands to add to the Dockerfile.
|
|
183
|
+
* @param {string} contextDir - The path to the context directory.
|
|
184
|
+
* @returns {Image} The Image instance.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* const image = Image
|
|
188
|
+
* .debianSlim('3.12')
|
|
189
|
+
* .dockerfileCommands(['RUN echo "Hello, world!"'])
|
|
190
|
+
*/
|
|
191
|
+
dockerfileCommands(dockerfileCommands: (string | string[])[], contextDir?: string): Image;
|
|
192
|
+
/**
|
|
193
|
+
* Creates an Image from an existing Dockerfile.
|
|
194
|
+
*
|
|
195
|
+
* @param {string} path - The path to the Dockerfile.
|
|
196
|
+
* @returns {Image} The Image instance.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* const image = Image.fromDockerfile('Dockerfile')
|
|
200
|
+
*/
|
|
201
|
+
static fromDockerfile(path: string): Image;
|
|
202
|
+
/**
|
|
203
|
+
* Creates an Image from an existing base image.
|
|
204
|
+
*
|
|
205
|
+
* @param {string} image - The base image to use.
|
|
206
|
+
* @returns {Image} The Image instance.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* const image = Image.base('python:3.12-slim-bookworm')
|
|
210
|
+
*/
|
|
211
|
+
static base(image: string): Image;
|
|
212
|
+
/**
|
|
213
|
+
* Creates a Debian slim image based on the official Python Docker image.
|
|
214
|
+
*
|
|
215
|
+
* @param {string} pythonVersion - The Python version to use.
|
|
216
|
+
* @returns {Image} The Image instance.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* const image = Image.debianSlim('3.12')
|
|
220
|
+
*/
|
|
221
|
+
static debianSlim(pythonVersion?: SupportedPythonSeries): Image;
|
|
222
|
+
/**
|
|
223
|
+
* Formats pip install arguments in a single string.
|
|
224
|
+
*
|
|
225
|
+
* @param {PipInstallOptions} options - The options for the pip install command.
|
|
226
|
+
* @returns {string} The formatted pip install arguments.
|
|
227
|
+
*/
|
|
228
|
+
private formatPipInstallArgs;
|
|
229
|
+
/**
|
|
230
|
+
* Flattens a string argument.
|
|
231
|
+
*
|
|
232
|
+
* @param {string} functionName - The name of the function.
|
|
233
|
+
* @param {string} argName - The name of the argument.
|
|
234
|
+
* @param {any} args - The argument to flatten.
|
|
235
|
+
* @returns {string[]} The flattened argument.
|
|
236
|
+
*/
|
|
237
|
+
private flattenStringArgs;
|
|
238
|
+
/**
|
|
239
|
+
* Processes the Python version.
|
|
240
|
+
*
|
|
241
|
+
* @param {string} pythonVersion - The Python version to use.
|
|
242
|
+
* @returns {string} The processed Python version.
|
|
243
|
+
*/
|
|
244
|
+
private static processPythonVersion;
|
|
245
|
+
/**
|
|
246
|
+
* Extracts source files from COPY commands in a Dockerfile.
|
|
247
|
+
*
|
|
248
|
+
* @param {string} dockerfileContent - The content of the Dockerfile.
|
|
249
|
+
* @param {string} pathPrefix - The path prefix to use for the sources.
|
|
250
|
+
* @returns {Array<[string, string]>} The list of the actual file path and its corresponding COPY-command source path.
|
|
251
|
+
*/
|
|
252
|
+
private static extractCopySources;
|
|
253
|
+
/**
|
|
254
|
+
* Parses a COPY command to extract sources and destination.
|
|
255
|
+
*
|
|
256
|
+
* @param {string} line - The line to parse.
|
|
257
|
+
* @returns {Object} The parsed sources and destination.
|
|
258
|
+
*/
|
|
259
|
+
private static parseCopyCommand;
|
|
260
|
+
}
|
|
261
|
+
export {};
|