@@ -29,6 +29,9 @@ import { buildWithProxy } from './buildWithProxy'
29
29
30
30
const templateCheckInterval = 500 // 0.5 sec
31
31
32
+ // Custom image URI is used for Bring Your Own Compute with self-hosted Docker registry
33
+ export const imageUriMask = process . env . E2B_IMAGE_URI_MASK
34
+
32
35
async function getTemplateBuildLogs ( {
33
36
templateID,
34
37
buildID,
@@ -340,20 +343,23 @@ export const buildCommand = new commander.Command('build')
340
343
true ,
341
344
)
342
345
343
- try {
344
- child_process . execSync (
345
- `echo "${ accessToken } " | docker login docker.${ connectionConfig . domain } -u _e2b_access_token --password-stdin` ,
346
- {
347
- stdio : 'inherit' ,
348
- cwd : root ,
349
- } ,
350
- )
351
- } catch ( err : any ) {
352
- console . error (
353
- 'Docker login failed. Please try to log in with `e2b auth login` and try again.' ,
354
- )
355
- process . exit ( 1 )
346
+ if ( imageUriMask == undefined ) {
347
+ try {
348
+ child_process . execSync (
349
+ `echo "${ accessToken } " | docker login docker.${ connectionConfig . domain } -u _e2b_access_token --password-stdin` ,
350
+ {
351
+ stdio : 'inherit' ,
352
+ cwd : root ,
353
+ } ,
354
+ )
355
+ } catch ( err : any ) {
356
+ console . error (
357
+ 'Docker login failed. Please try to log in with `e2b auth login` and try again.' ,
358
+ )
359
+ process . exit ( 1 )
360
+ }
356
361
}
362
+
357
363
process . stdout . write ( '\n' )
358
364
359
365
const buildArgs = Object . entries ( dockerBuildArgs )
@@ -362,11 +368,16 @@ export const buildCommand = new commander.Command('build')
362
368
363
369
const noCache = opts . noCache ? '--no-cache' : ''
364
370
371
+ const imageUrl = dockerImageUrl ( templateID , template . buildID , connectionConfig . domain , imageUriMask )
372
+ if ( imageUriMask != undefined ) {
373
+ console . log ( 'Using custom docker image URI:' , imageUrl )
374
+ }
375
+
365
376
const cmd = [
366
377
'docker build' ,
367
378
`-f ${ dockerfileRelativePath } ` ,
368
379
'--pull --platform linux/amd64' ,
369
- `-t docker. ${ connectionConfig . domain } /e2b/custom-envs/ ${ templateID } : ${ template . buildID } ` ,
380
+ `-t ${ imageUrl } ` ,
370
381
buildArgs ,
371
382
noCache ,
372
383
'.' ,
@@ -386,7 +397,7 @@ export const buildCommand = new commander.Command('build')
386
397
} )
387
398
console . log ( '> Docker image built.\n' )
388
399
389
- const pushCmd = `docker push docker. ${ connectionConfig . domain } /e2b/custom-envs/ ${ templateID } : ${ template . buildID } `
400
+ const pushCmd = `docker push ${ imageUrl } `
390
401
console . log (
391
402
`Pushing docker image with the following command:\n${ asBold (
392
403
pushCmd ,
@@ -616,3 +627,11 @@ async function triggerBuild(templateID: string, buildID: string) {
616
627
617
628
return
618
629
}
630
+
631
+ function dockerImageUrl ( templateID : string , buildID : string , defaultDomain : string , imageUrlMask ?: string ) : string {
632
+ if ( imageUrlMask == undefined ) {
633
+ return `docker.${ defaultDomain } /e2b/custom-envs/${ templateID } :${ buildID } `
634
+ }
635
+
636
+ return imageUrlMask . replaceAll ( '{templateID}' , templateID ) . replaceAll ( '{buildID}' , buildID )
637
+ }
0 commit comments