diff --git a/src/index.ts b/src/index.ts index d1c88ea..6279897 100644 --- a/src/index.ts +++ b/src/index.ts @@ -172,6 +172,18 @@ export const buildOne = function (service: string, options?: IDockerComposeBuild return execCompose('build', [ service ], options); }; +export const pullAll = function (options: IDockerComposeOptions = {}): Promise { + return execCompose('pull', [], options); +}; + +export const pullMany = function (services: string[], options: IDockerComposeOptions = {}): Promise { + return execCompose('pull', services, options); +}; + +export const pullOne = function (service: string, options?: IDockerComposeOptions): Promise { + return execCompose('pull', [ service ], options); +}; + export const config = function (options?: IDockerComposeOptions): Promise { return execCompose('config', [], options); }; diff --git a/test/index.test.ts b/test/index.test.ts index 9964d16..da8b44f 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -323,6 +323,59 @@ test('build all services', async (): Promise => { await removeImagesStartingWith('compose-test-build-image'); }); +test('pull single service', async (): Promise => { + const opts = { + cwd: path.join(__dirname), + log: logOutput, + config: 'docker-compose.yml' + }; + + await removeImagesStartingWith('nginx:1.16.0'); + expect(await imageExists('nginx:1.16.0')).toBeFalsy(); + + await compose.pullOne('db', opts); + + expect(await imageExists('nginx:1.16.0')).toBeTruthy(); +}); + +test('pull multiple services', async (): Promise => { + const opts = { + cwd: path.join(__dirname), + log: logOutput, + config: 'docker-compose.yml' + }; + + await removeImagesStartingWith('nginx:1.16.0'); + await removeImagesStartingWith('alpine:3.7.3'); + + expect(await imageExists('nginx:1.16.0')).toBeFalsy(); + expect(await imageExists('alpine:3.7.3')).toBeFalsy(); + + await compose.pullMany([ 'db', 'alpine' ], opts); + + expect(await imageExists('nginx:1.16.0')).toBeTruthy(); + expect(await imageExists('alpine:3.7.3')).toBeTruthy(); +}); + +test('pull all services', async (): Promise => { + const opts = { + cwd: path.join(__dirname), + log: logOutput, + config: 'docker-compose.yml' + }; + + await removeImagesStartingWith('nginx:1.16.0'); + await removeImagesStartingWith('alpine:3.7.3'); + + expect(await imageExists('nginx:1.16.0')).toBeFalsy(); + expect(await imageExists('alpine:3.7.3')).toBeFalsy(); + + await compose.pullAll(opts); + + expect(await imageExists('nginx:1.16.0')).toBeTruthy(); + expect(await imageExists('alpine:3.7.3')).toBeTruthy(); +}); + test('teardown', async (): Promise => { interface Container { Names: string[];