Skip to content

Commit 92baa9d

Browse files
authored
[FAI-16250] Allow users to pass in additional docker volume mount (#135)
1 parent 7971137 commit 92baa9d

File tree

7 files changed

+106
-16
lines changed

7 files changed

+106
-16
lines changed

airbyte-local-cli-nodejs/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

airbyte-local-cli-nodejs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@faros-ai/airbyte-local-cli-nodejs",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "Airbyte local cli node js version",
55
"private": true,
66
"packageManager": "^[email protected]",

airbyte-local-cli-nodejs/src/docker.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
TMP_SPEC_CONFIG_FILENAME,
1515
TMP_WIZARD_CONFIG_FILENAME,
1616
} from './constants/constants';
17+
// Self-reference for unit test mocking
18+
import * as docker from './docker';
1719
import {logger} from './logger';
1820
import {
1921
AirbyteCatalog,
@@ -34,8 +36,8 @@ const DEFAULT_MAX_LOG_SIZE = '10m';
3436
let _docker = new Docker();
3537

3638
// For testing purposes
37-
export function setDocker(docker: Docker): void {
38-
_docker = docker;
39+
export function setDocker(testDocker: Docker): void {
40+
_docker = testDocker;
3941
}
4042

4143
/**
@@ -182,7 +184,7 @@ export function processSpecByLine(line: string): AirbyteSpec | undefined {
182184
* @param options - Docker container create options
183185
* @param outputStream - Writable stream to capture the output
184186
*/
185-
async function runDocker(
187+
export async function runDocker(
186188
options: Docker.ContainerCreateOptions,
187189
outputStream: Writable,
188190
inputStream?: ReadStream | PassThrough,
@@ -288,7 +290,7 @@ export async function runCheckSrcConnection(tmpDir: string, image: string, srcCo
288290
});
289291

290292
// run docker
291-
await runDocker(createOptions, containerOutputStream);
293+
await docker.runDocker(createOptions, containerOutputStream);
292294

293295
// capture connection status from the output
294296
let status: AirbyteConnectionStatusMessage | undefined;
@@ -348,7 +350,7 @@ export async function runDiscoverCatalog(tmpDir: string, image: string | undefin
348350
});
349351

350352
// run docker
351-
await runDocker(createOptions, containerOutputStream);
353+
await docker.runDocker(createOptions, containerOutputStream);
352354

353355
// capture catalog output
354356
let rawCatalog: AirbyteCatalogMessage | undefined;
@@ -438,8 +440,14 @@ export async function runSrcSync(tmpDir: string, config: FarosConfig, srcOutputS
438440
},
439441
},
440442
...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+
441450
// Default options: cannot be overridden by users
442-
Binds: [`${tmpDir}:${getBindsLocation(config.src.image)}`],
443451
AutoRemove: !config.keepContainers,
444452
Init: true,
445453
},
@@ -467,7 +475,7 @@ export async function runSrcSync(tmpDir: string, config: FarosConfig, srcOutputS
467475
});
468476

469477
// run docker
470-
await runDocker(createOptions, containerOutputStream);
478+
await docker.runDocker(createOptions, containerOutputStream);
471479

472480
// Close the container output stream
473481
// 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
564572
},
565573
},
566574
...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+
567582
// Default options: cannot be overridden by users
568-
Binds: [`${tmpDir}:${getBindsLocation(config.dst.image)}`],
569583
AutoRemove: !config.keepContainers,
570584
Init: true,
571585
},
@@ -593,7 +607,7 @@ export async function runDstSync(tmpDir: string, config: FarosConfig, srcPassThr
593607
const inputStream = srcPassThrough ?? createReadStream(`${tmpDir}/${SRC_OUTPUT_DATA_FILE}`);
594608

595609
// Start the container
596-
await runDocker(createOptions, containerOutputStream, inputStream);
610+
await docker.runDocker(createOptions, containerOutputStream, inputStream);
597611
logger.info('Destination connector completed.');
598612

599613
// Write the state file
@@ -651,7 +665,7 @@ export async function runSpec(image: string): Promise<AirbyteSpec> {
651665
});
652666

653667
// run docker
654-
await runDocker(createOptions, containerOutputStream);
668+
await docker.runDocker(createOptions, containerOutputStream);
655669

656670
// write spec to the file
657671
if (specs.length > 0) {
@@ -713,7 +727,7 @@ export async function runWizard(tmpDir: string, image: string, spec: AirbyteSpec
713727
};
714728

715729
// run docker
716-
await runDocker(createOptions, process.stdout);
730+
await docker.runDocker(createOptions, process.stdout);
717731

718732
const resultConfig = JSON.parse(readFileSync(`${tmpDir}/${TMP_WIZARD_CONFIG_FILENAME}`, 'utf-8'));
719733
return resultConfig;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const CLI_VERSION = '0.0.5';
1+
export const CLI_VERSION = '0.0.6';

airbyte-local-cli-nodejs/test/__snapshots__/utils.it.test.ts.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ exports[`parseConfigFile should parse utf16 encoding 1`] = `
9393
"username": "test-username",
9494
},
9595
"dockerOptions": {
96+
"additionalOptions": {
97+
"HostConfig": {
98+
"Binds": [
99+
"/test/path:/test/path/test.json",
100+
],
101+
},
102+
},
96103
"maxCpus": 2,
97104
"maxMemory": 2048,
98105
},
@@ -127,6 +134,13 @@ exports[`parseConfigFile should pass 1`] = `
127134
"username": "test-username",
128135
},
129136
"dockerOptions": {
137+
"additionalOptions": {
138+
"HostConfig": {
139+
"Binds": [
140+
"/test/path:/test/path/test.json",
141+
],
142+
},
143+
},
130144
"maxCpus": 2,
131145
"maxMemory": 2048,
132146
},
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as docker from '../src/docker';
2+
import {FarosConfig} from '../src/types';
3+
4+
describe('runSrcSync', () => {
5+
const testCfg: FarosConfig = {
6+
src: {
7+
image: 'farosai/airbyte-example-source',
8+
},
9+
srcCheckConnection: false,
10+
dstUseHostNetwork: false,
11+
srcPull: false,
12+
dstPull: false,
13+
fullRefresh: false,
14+
rawMessages: false,
15+
keepContainers: false,
16+
logLevel: 'info',
17+
debug: false,
18+
stateFile: undefined,
19+
connectionName: undefined,
20+
srcOutputFile: undefined,
21+
srcInputFile: undefined,
22+
silent: false,
23+
image: false,
24+
};
25+
26+
afterEach(() => {
27+
jest.clearAllMocks();
28+
});
29+
30+
it('should call runDocker with correct parameters', async () => {
31+
const mockRunDocker = jest.spyOn(docker, 'runDocker').mockResolvedValue(undefined);
32+
33+
const testCfgWithVolumeMount = {
34+
...testCfg,
35+
src: {
36+
...testCfg.src,
37+
dockerOptions: {
38+
additionalOptions: {
39+
HostConfig: {
40+
Binds: ['/path/to/tasks.xlsx:/tasks.xlsx'],
41+
},
42+
},
43+
},
44+
},
45+
} as FarosConfig;
46+
47+
await docker.runSrcSync('testTmpDir', testCfgWithVolumeMount, process.stdout);
48+
49+
expect(mockRunDocker).toHaveBeenCalled();
50+
expect(mockRunDocker.mock.calls[0]?.[0]?.HostConfig?.Binds).toMatchObject([
51+
'testTmpDir:/configs',
52+
'/path/to/tasks.xlsx:/tasks.xlsx',
53+
]);
54+
});
55+
});

airbyte-local-cli-nodejs/test/resources/test_config_file.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
"catalog": {},
1010
"dockerOptions": {
1111
"maxMemory": 2048,
12-
"maxCpus": 2
12+
"maxCpus": 2,
13+
"additionalOptions": {
14+
"HostConfig": {
15+
"Binds": [
16+
"/test/path:/test/path/test.json"
17+
]
18+
}
19+
}
1320
}
1421
},
1522
"dst": {

0 commit comments

Comments
 (0)