@@ -14,6 +14,8 @@ import {
14
14
TMP_SPEC_CONFIG_FILENAME ,
15
15
TMP_WIZARD_CONFIG_FILENAME ,
16
16
} from './constants/constants' ;
17
+ // Self-reference for unit test mocking
18
+ import * as docker from './docker' ;
17
19
import { logger } from './logger' ;
18
20
import {
19
21
AirbyteCatalog ,
@@ -34,8 +36,8 @@ const DEFAULT_MAX_LOG_SIZE = '10m';
34
36
let _docker = new Docker ( ) ;
35
37
36
38
// For testing purposes
37
- export function setDocker ( docker : Docker ) : void {
38
- _docker = docker ;
39
+ export function setDocker ( testDocker : Docker ) : void {
40
+ _docker = testDocker ;
39
41
}
40
42
41
43
/**
@@ -182,7 +184,7 @@ export function processSpecByLine(line: string): AirbyteSpec | undefined {
182
184
* @param options - Docker container create options
183
185
* @param outputStream - Writable stream to capture the output
184
186
*/
185
- async function runDocker (
187
+ export async function runDocker (
186
188
options : Docker . ContainerCreateOptions ,
187
189
outputStream : Writable ,
188
190
inputStream ?: ReadStream | PassThrough ,
@@ -288,7 +290,7 @@ export async function runCheckSrcConnection(tmpDir: string, image: string, srcCo
288
290
} ) ;
289
291
290
292
// run docker
291
- await runDocker ( createOptions , containerOutputStream ) ;
293
+ await docker . runDocker ( createOptions , containerOutputStream ) ;
292
294
293
295
// capture connection status from the output
294
296
let status : AirbyteConnectionStatusMessage | undefined ;
@@ -348,7 +350,7 @@ export async function runDiscoverCatalog(tmpDir: string, image: string | undefin
348
350
} ) ;
349
351
350
352
// run docker
351
- await runDocker ( createOptions , containerOutputStream ) ;
353
+ await docker . runDocker ( createOptions , containerOutputStream ) ;
352
354
353
355
// capture catalog output
354
356
let rawCatalog : AirbyteCatalogMessage | undefined ;
@@ -438,8 +440,14 @@ export async function runSrcSync(tmpDir: string, config: FarosConfig, srcOutputS
438
440
} ,
439
441
} ,
440
442
...config . src ?. dockerOptions ?. additionalOptions ?. HostConfig ,
443
+
444
+ // Allow users to add bind mount but not override the default one
445
+ Binds : [
446
+ `${ tmpDir } :${ getBindsLocation ( config . src . image ) } ` ,
447
+ ...( config . src ?. dockerOptions ?. additionalOptions ?. HostConfig ?. Binds || [ ] ) ,
448
+ ] ,
449
+
441
450
// Default options: cannot be overridden by users
442
- Binds : [ `${ tmpDir } :${ getBindsLocation ( config . src . image ) } ` ] ,
443
451
AutoRemove : ! config . keepContainers ,
444
452
Init : true ,
445
453
} ,
@@ -467,7 +475,7 @@ export async function runSrcSync(tmpDir: string, config: FarosConfig, srcOutputS
467
475
} ) ;
468
476
469
477
// run docker
470
- await runDocker ( createOptions , containerOutputStream ) ;
478
+ await docker . runDocker ( createOptions , containerOutputStream ) ;
471
479
472
480
// Close the container output stream
473
481
// This is required to notify the dst connector that inputs are done
@@ -564,8 +572,14 @@ export async function runDstSync(tmpDir: string, config: FarosConfig, srcPassThr
564
572
} ,
565
573
} ,
566
574
...config . dst ?. dockerOptions ?. additionalOptions ?. HostConfig ,
575
+
576
+ // Allow users to add bind mount but not override the default one
577
+ Binds : [
578
+ `${ tmpDir } :${ getBindsLocation ( config . dst . image ) } ` ,
579
+ ...( config . dst ?. dockerOptions ?. additionalOptions ?. HostConfig ?. Binds || [ ] ) ,
580
+ ] ,
581
+
567
582
// Default options: cannot be overridden by users
568
- Binds : [ `${ tmpDir } :${ getBindsLocation ( config . dst . image ) } ` ] ,
569
583
AutoRemove : ! config . keepContainers ,
570
584
Init : true ,
571
585
} ,
@@ -593,7 +607,7 @@ export async function runDstSync(tmpDir: string, config: FarosConfig, srcPassThr
593
607
const inputStream = srcPassThrough ?? createReadStream ( `${ tmpDir } /${ SRC_OUTPUT_DATA_FILE } ` ) ;
594
608
595
609
// Start the container
596
- await runDocker ( createOptions , containerOutputStream , inputStream ) ;
610
+ await docker . runDocker ( createOptions , containerOutputStream , inputStream ) ;
597
611
logger . info ( 'Destination connector completed.' ) ;
598
612
599
613
// Write the state file
@@ -651,7 +665,7 @@ export async function runSpec(image: string): Promise<AirbyteSpec> {
651
665
} ) ;
652
666
653
667
// run docker
654
- await runDocker ( createOptions , containerOutputStream ) ;
668
+ await docker . runDocker ( createOptions , containerOutputStream ) ;
655
669
656
670
// write spec to the file
657
671
if ( specs . length > 0 ) {
@@ -713,7 +727,7 @@ export async function runWizard(tmpDir: string, image: string, spec: AirbyteSpec
713
727
} ;
714
728
715
729
// run docker
716
- await runDocker ( createOptions , process . stdout ) ;
730
+ await docker . runDocker ( createOptions , process . stdout ) ;
717
731
718
732
const resultConfig = JSON . parse ( readFileSync ( `${ tmpDir } /${ TMP_WIZARD_CONFIG_FILENAME } ` , 'utf-8' ) ) ;
719
733
return resultConfig ;
0 commit comments