mirror of
https://github.com/danbulant/docker-compose
synced 2026-05-24 12:35:32 +00:00
style: run prettier
This commit is contained in:
parent
bdbfc17de1
commit
46cb725156
3 changed files with 643 additions and 483 deletions
|
|
@ -3,7 +3,6 @@ module.exports = {
|
||||||
'eslint:recommended',
|
'eslint:recommended',
|
||||||
'plugin:jest/recommended',
|
'plugin:jest/recommended',
|
||||||
'plugin:@typescript-eslint/recommended',
|
'plugin:@typescript-eslint/recommended',
|
||||||
'prettier/@typescript-eslint',
|
|
||||||
'plugin:prettier/recommended'
|
'plugin:prettier/recommended'
|
||||||
],
|
],
|
||||||
env: {
|
env: {
|
||||||
|
|
|
||||||
405
src/index.ts
405
src/index.ts
|
|
@ -1,31 +1,31 @@
|
||||||
import childProcess from 'child_process';
|
import childProcess from 'child_process'
|
||||||
import { Readable } from 'stream'
|
import { Readable } from 'stream'
|
||||||
export interface IDockerComposeOptions {
|
export interface IDockerComposeOptions {
|
||||||
cwd?: string;
|
cwd?: string
|
||||||
config?: string | string[];
|
config?: string | string[]
|
||||||
configAsString?: string;
|
configAsString?: string
|
||||||
log?: boolean;
|
log?: boolean
|
||||||
composeOptions?: string[] | (string | string[])[];
|
composeOptions?: string[] | (string | string[])[]
|
||||||
commandOptions?: string[] | (string | string[])[];
|
commandOptions?: string[] | (string | string[])[]
|
||||||
env?: NodeJS.ProcessEnv;
|
env?: NodeJS.ProcessEnv
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
|
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
|
||||||
follow?: boolean;
|
follow?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDockerComposeBuildOptions extends IDockerComposeOptions {
|
export interface IDockerComposeBuildOptions extends IDockerComposeOptions {
|
||||||
parallel?: boolean;
|
parallel?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDockerComposePushOptions extends IDockerComposeOptions {
|
export interface IDockerComposePushOptions extends IDockerComposeOptions {
|
||||||
ignorePushFailures?: boolean;
|
ignorePushFailures?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDockerComposeResult {
|
export interface IDockerComposeResult {
|
||||||
exitCode: number | null;
|
exitCode: number | null
|
||||||
out: string;
|
out: string
|
||||||
err: string;
|
err: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -34,231 +34,328 @@ export interface IDockerComposeResult {
|
||||||
*/
|
*/
|
||||||
const configToArgs = (config): string[] => {
|
const configToArgs = (config): string[] => {
|
||||||
if (typeof config === 'undefined') {
|
if (typeof config === 'undefined') {
|
||||||
return [];
|
return []
|
||||||
} else if (typeof config === 'string') {
|
} else if (typeof config === 'string') {
|
||||||
return [ '-f', config ];
|
return ['-f', config]
|
||||||
} else if (config instanceof Array) {
|
} else if (config instanceof Array) {
|
||||||
return config.reduce((args, item): string[] => args.concat([ '-f', item ]), []);
|
return config.reduce(
|
||||||
|
(args, item): string[] => args.concat(['-f', item]),
|
||||||
|
[]
|
||||||
|
)
|
||||||
}
|
}
|
||||||
throw new Error(`Invalid argument supplied: ${config}`);
|
throw new Error(`Invalid argument supplied: ${config}`)
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts docker-compose commandline options to cli arguments
|
* Converts docker-compose commandline options to cli arguments
|
||||||
*/
|
*/
|
||||||
const composeOptionsToArgs = (composeOptions): string[] => {
|
const composeOptionsToArgs = (composeOptions): string[] => {
|
||||||
let composeArgs: string[] = [];
|
let composeArgs: string[] = []
|
||||||
|
|
||||||
composeOptions.forEach((option: string[] | string): void => {
|
composeOptions.forEach((option: string[] | string): void => {
|
||||||
if (option instanceof Array) {
|
if (option instanceof Array) {
|
||||||
composeArgs = composeArgs.concat(option);
|
composeArgs = composeArgs.concat(option)
|
||||||
}
|
}
|
||||||
if (typeof option === 'string') {
|
if (typeof option === 'string') {
|
||||||
composeArgs = composeArgs.concat([ option ]);
|
composeArgs = composeArgs.concat([option])
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
return composeArgs;
|
return composeArgs
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes docker-compose command with common options
|
* Executes docker-compose command with common options
|
||||||
*/
|
*/
|
||||||
const execCompose = (command, args, options: IDockerComposeOptions = {}): Promise<IDockerComposeResult> => new Promise((resolve, reject): void => {
|
const execCompose = (
|
||||||
const composeOptions = options.composeOptions || [];
|
command,
|
||||||
const commandOptions = options.commandOptions || [];
|
args,
|
||||||
let composeArgs = composeOptionsToArgs(composeOptions);
|
options: IDockerComposeOptions = {}
|
||||||
const isConfigProvidedAsString = !!options.configAsString;
|
): Promise<IDockerComposeResult> =>
|
||||||
|
new Promise((resolve, reject): void => {
|
||||||
|
const composeOptions = options.composeOptions || []
|
||||||
|
const commandOptions = options.commandOptions || []
|
||||||
|
let composeArgs = composeOptionsToArgs(composeOptions)
|
||||||
|
const isConfigProvidedAsString = !!options.configAsString
|
||||||
|
|
||||||
const configArgs = isConfigProvidedAsString ? [ '-f', '-' ] : configToArgs(options.config);
|
const configArgs = isConfigProvidedAsString
|
||||||
|
? ['-f', '-']
|
||||||
|
: configToArgs(options.config)
|
||||||
|
|
||||||
composeArgs = composeArgs.concat(configArgs.concat([ command ].concat(composeOptionsToArgs(commandOptions), args)));
|
composeArgs = composeArgs.concat(
|
||||||
|
configArgs.concat(
|
||||||
|
[command].concat(composeOptionsToArgs(commandOptions), args)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
const cwd = options.cwd;
|
const cwd = options.cwd
|
||||||
const env = options.env || undefined;
|
const env = options.env || undefined
|
||||||
|
|
||||||
const childProc = childProcess.spawn('docker-compose', composeArgs, { cwd, env });
|
const childProc = childProcess.spawn('docker-compose', composeArgs, {
|
||||||
|
cwd,
|
||||||
|
env
|
||||||
|
})
|
||||||
|
|
||||||
childProc.on('error', (err): void => {
|
childProc.on('error', (err): void => {
|
||||||
reject(err);
|
reject(err)
|
||||||
});
|
})
|
||||||
|
|
||||||
const result: IDockerComposeResult = {
|
const result: IDockerComposeResult = {
|
||||||
exitCode: null,
|
exitCode: null,
|
||||||
err: '',
|
err: '',
|
||||||
out: ''
|
out: ''
|
||||||
};
|
}
|
||||||
|
|
||||||
childProc.stdout.on('data', (chunk): void => {
|
childProc.stdout.on('data', (chunk): void => {
|
||||||
result.out += chunk.toString();
|
result.out += chunk.toString()
|
||||||
});
|
})
|
||||||
|
|
||||||
childProc.stderr.on('data', (chunk): void => {
|
childProc.stderr.on('data', (chunk): void => {
|
||||||
result.err += chunk.toString();
|
result.err += chunk.toString()
|
||||||
});
|
})
|
||||||
|
|
||||||
childProc.on('exit', (exitCode): void => {
|
childProc.on('exit', (exitCode): void => {
|
||||||
result.exitCode = exitCode;
|
result.exitCode = exitCode
|
||||||
if (exitCode === 0) {
|
if (exitCode === 0) {
|
||||||
resolve(result);
|
resolve(result)
|
||||||
} else {
|
} else {
|
||||||
reject(result);
|
reject(result)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
if (isConfigProvidedAsString) {
|
if (isConfigProvidedAsString) {
|
||||||
childProc.stdin.write(options.configAsString);
|
childProc.stdin.write(options.configAsString)
|
||||||
childProc.stdin.end();
|
childProc.stdin.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.log) {
|
if (options.log) {
|
||||||
childProc.stdout.pipe(process.stdout);
|
childProc.stdout.pipe(process.stdout)
|
||||||
childProc.stderr.pipe(process.stderr);
|
childProc.stderr.pipe(process.stderr)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether or not to use the default non-interactive flag -d for up commands
|
* Determines whether or not to use the default non-interactive flag -d for up commands
|
||||||
*/
|
*/
|
||||||
const shouldUseDefaultNonInteractiveFlag = function(options: IDockerComposeOptions = {}): boolean {
|
const shouldUseDefaultNonInteractiveFlag = function (
|
||||||
const commandOptions = options.commandOptions || [];
|
options: IDockerComposeOptions = {}
|
||||||
const containsOtherNonInteractiveFlag = commandOptions.reduce((memo: boolean, item: string | string[]) => {
|
): boolean {
|
||||||
return memo && !item.includes('--abort-on-container-exit') && !item.includes('--no-start');
|
const commandOptions = options.commandOptions || []
|
||||||
}, true);
|
const containsOtherNonInteractiveFlag = commandOptions.reduce(
|
||||||
return containsOtherNonInteractiveFlag;
|
(memo: boolean, item: string | string[]) => {
|
||||||
};
|
return (
|
||||||
|
memo &&
|
||||||
|
!item.includes('--abort-on-container-exit') &&
|
||||||
|
!item.includes('--no-start')
|
||||||
|
)
|
||||||
|
},
|
||||||
|
true
|
||||||
|
)
|
||||||
|
return containsOtherNonInteractiveFlag
|
||||||
|
}
|
||||||
|
|
||||||
export const upAll = function (options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const upAll = function (
|
||||||
const args = shouldUseDefaultNonInteractiveFlag(options) ? [ '-d' ] : [];
|
options?: IDockerComposeOptions
|
||||||
return execCompose('up', args, options);
|
): Promise<IDockerComposeResult> {
|
||||||
};
|
const args = shouldUseDefaultNonInteractiveFlag(options) ? ['-d'] : []
|
||||||
|
return execCompose('up', args, options)
|
||||||
|
}
|
||||||
|
|
||||||
export const upMany = function (services: string[], options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const upMany = function (
|
||||||
const args = shouldUseDefaultNonInteractiveFlag(options) ? [ '-d' ].concat(services) : services;
|
services: string[],
|
||||||
return execCompose('up', args, options);
|
options?: IDockerComposeOptions
|
||||||
};
|
): Promise<IDockerComposeResult> {
|
||||||
|
const args = shouldUseDefaultNonInteractiveFlag(options)
|
||||||
|
? ['-d'].concat(services)
|
||||||
|
: services
|
||||||
|
return execCompose('up', args, options)
|
||||||
|
}
|
||||||
|
|
||||||
export const upOne = function (service: string, options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const upOne = function (
|
||||||
const args = shouldUseDefaultNonInteractiveFlag(options) ? [ '-d', service ] : [ service ];
|
service: string,
|
||||||
return execCompose('up', args, options);
|
options?: IDockerComposeOptions
|
||||||
};
|
): Promise<IDockerComposeResult> {
|
||||||
|
const args = shouldUseDefaultNonInteractiveFlag(options)
|
||||||
|
? ['-d', service]
|
||||||
|
: [service]
|
||||||
|
return execCompose('up', args, options)
|
||||||
|
}
|
||||||
|
|
||||||
export const down = function (options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const down = function (
|
||||||
return execCompose('down', [], options);
|
options?: IDockerComposeOptions
|
||||||
};
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('down', [], options)
|
||||||
|
}
|
||||||
|
|
||||||
export const stop = function (options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const stop = function (
|
||||||
return execCompose('stop', [], options);
|
options?: IDockerComposeOptions
|
||||||
};
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('stop', [], options)
|
||||||
|
}
|
||||||
|
|
||||||
export const stopOne = function (service: string, options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const stopOne = function (
|
||||||
return execCompose('stop', [ service ], options);
|
service: string,
|
||||||
};
|
options?: IDockerComposeOptions
|
||||||
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('stop', [service], options)
|
||||||
|
}
|
||||||
|
|
||||||
export const kill = function (options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const kill = function (
|
||||||
return execCompose('kill', [], options);
|
options?: IDockerComposeOptions
|
||||||
};
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('kill', [], options)
|
||||||
|
}
|
||||||
|
|
||||||
export const rm = function (options?: IDockerComposeOptions, ...services: string[]): Promise<IDockerComposeResult> {
|
export const rm = function (
|
||||||
return execCompose('rm', [ '-f', ...services ], options);
|
options?: IDockerComposeOptions,
|
||||||
};
|
...services: string[]
|
||||||
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('rm', ['-f', ...services], options)
|
||||||
|
}
|
||||||
|
|
||||||
export const exec = function (container: string, command: string | string[], options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const exec = function (
|
||||||
const args = Array.isArray(command) ? command : command.split(/\s+/);
|
container: string,
|
||||||
|
command: string | string[],
|
||||||
|
options?: IDockerComposeOptions
|
||||||
|
): Promise<IDockerComposeResult> {
|
||||||
|
const args = Array.isArray(command) ? command : command.split(/\s+/)
|
||||||
|
|
||||||
return execCompose('exec', [ '-T', container ].concat(args), options);
|
return execCompose('exec', ['-T', container].concat(args), options)
|
||||||
};
|
}
|
||||||
|
|
||||||
export const run = function (container: string, command: string | string[], options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const run = function (
|
||||||
const args = Array.isArray(command) ? command : command.split(/\s+/);
|
container: string,
|
||||||
|
command: string | string[],
|
||||||
|
options?: IDockerComposeOptions
|
||||||
|
): Promise<IDockerComposeResult> {
|
||||||
|
const args = Array.isArray(command) ? command : command.split(/\s+/)
|
||||||
|
|
||||||
return execCompose('run', [ '-T', container ].concat(args), options);
|
return execCompose('run', ['-T', container].concat(args), options)
|
||||||
};
|
}
|
||||||
|
|
||||||
export const buildAll = function (options: IDockerComposeBuildOptions = {}): Promise<IDockerComposeResult> {
|
export const buildAll = function (
|
||||||
|
options: IDockerComposeBuildOptions = {}
|
||||||
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('build', options.parallel ? ['--parallel'] : [], options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const buildMany = function (
|
||||||
|
services: string[],
|
||||||
|
options: IDockerComposeBuildOptions = {}
|
||||||
|
): Promise<IDockerComposeResult> {
|
||||||
return execCompose(
|
return execCompose(
|
||||||
'build',
|
'build',
|
||||||
options.parallel ? [ '--parallel' ] : [],
|
options.parallel ? ['--parallel'].concat(services) : services,
|
||||||
options
|
options
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
export const buildMany = function (services: string[], options: IDockerComposeBuildOptions = {}): Promise<IDockerComposeResult> {
|
export const buildOne = function (
|
||||||
return execCompose(
|
service: string,
|
||||||
'build',
|
options?: IDockerComposeBuildOptions
|
||||||
options.parallel ? [ '--parallel' ].concat(services) : services,
|
): Promise<IDockerComposeResult> {
|
||||||
options
|
return execCompose('build', [service], options)
|
||||||
);
|
}
|
||||||
};
|
|
||||||
|
|
||||||
export const buildOne = function (service: string, options?: IDockerComposeBuildOptions): Promise<IDockerComposeResult> {
|
export const pullAll = function (
|
||||||
return execCompose('build', [ service ], options);
|
options: IDockerComposeOptions = {}
|
||||||
};
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('pull', [], options)
|
||||||
|
}
|
||||||
|
|
||||||
export const pullAll = function (options: IDockerComposeOptions = {}): Promise<IDockerComposeResult> {
|
export const pullMany = function (
|
||||||
return execCompose('pull', [], options);
|
services: string[],
|
||||||
};
|
options: IDockerComposeOptions = {}
|
||||||
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('pull', services, options)
|
||||||
|
}
|
||||||
|
|
||||||
export const pullMany = function (services: string[], options: IDockerComposeOptions = {}): Promise<IDockerComposeResult> {
|
export const pullOne = function (
|
||||||
return execCompose('pull', services, options);
|
service: string,
|
||||||
};
|
options?: IDockerComposeOptions
|
||||||
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('pull', [service], options)
|
||||||
|
}
|
||||||
|
|
||||||
export const pullOne = function (service: string, options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const config = function (
|
||||||
return execCompose('pull', [ service ], options);
|
options?: IDockerComposeOptions
|
||||||
};
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('config', [], options)
|
||||||
|
}
|
||||||
|
|
||||||
export const config = function (options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const configServices = function (
|
||||||
return execCompose('config', [], options);
|
options?: IDockerComposeOptions
|
||||||
};
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('config', ['--services'], options)
|
||||||
|
}
|
||||||
|
|
||||||
export const configServices = function (options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const configVolumes = function (
|
||||||
return execCompose('config', [ '--services' ], options);
|
options?: IDockerComposeOptions
|
||||||
};
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('config', ['--volumes'], options)
|
||||||
|
}
|
||||||
|
|
||||||
export const configVolumes = function (options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const ps = function (
|
||||||
return execCompose('config', [ '--volumes' ], options);
|
options?: IDockerComposeOptions
|
||||||
};
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('ps', [], options)
|
||||||
|
}
|
||||||
|
|
||||||
export const ps = function (options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const push = function (
|
||||||
return execCompose('ps', [], options);
|
options: IDockerComposePushOptions = {}
|
||||||
};
|
): Promise<IDockerComposeResult> {
|
||||||
|
|
||||||
export const push = function (options: IDockerComposePushOptions = {}): Promise<IDockerComposeResult> {
|
|
||||||
return execCompose(
|
return execCompose(
|
||||||
'push',
|
'push',
|
||||||
options.ignorePushFailures ? [ '--ignore-push-failures' ] : [],
|
options.ignorePushFailures ? ['--ignore-push-failures'] : [],
|
||||||
options
|
options
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
export const restartAll = function (options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const restartAll = function (
|
||||||
return execCompose('restart', [], options);
|
options?: IDockerComposeOptions
|
||||||
};
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('restart', [], options)
|
||||||
|
}
|
||||||
|
|
||||||
export const restartMany = function (services: string[], options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const restartMany = function (
|
||||||
return execCompose('restart', services, options);
|
services: string[],
|
||||||
};
|
options?: IDockerComposeOptions
|
||||||
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('restart', services, options)
|
||||||
|
}
|
||||||
|
|
||||||
export const restartOne = function (service: string, options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const restartOne = function (
|
||||||
return restartMany([ service ], options);
|
service: string,
|
||||||
};
|
options?: IDockerComposeOptions
|
||||||
|
): Promise<IDockerComposeResult> {
|
||||||
|
return restartMany([service], options)
|
||||||
|
}
|
||||||
|
|
||||||
export const logs = function (services: string | string[], options: IDockerComposeLogOptions = {}): Promise<IDockerComposeResult> {
|
export const logs = function (
|
||||||
let args = Array.isArray(services) ? services : [ services ];
|
services: string | string[],
|
||||||
|
options: IDockerComposeLogOptions = {}
|
||||||
|
): Promise<IDockerComposeResult> {
|
||||||
|
let args = Array.isArray(services) ? services : [services]
|
||||||
|
|
||||||
if (options.follow) {
|
if (options.follow) {
|
||||||
args = [ '--follow', ...args ];
|
args = ['--follow', ...args]
|
||||||
}
|
}
|
||||||
|
|
||||||
return execCompose('logs', args, options);
|
return execCompose('logs', args, options)
|
||||||
};
|
}
|
||||||
|
|
||||||
export const port = function (service: string, containerPort: string | number, options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const port = function (
|
||||||
const args = [ service, containerPort ];
|
service: string,
|
||||||
|
containerPort: string | number,
|
||||||
|
options?: IDockerComposeOptions
|
||||||
|
): Promise<IDockerComposeResult> {
|
||||||
|
const args = [service, containerPort]
|
||||||
|
|
||||||
return execCompose('port', args, options);
|
return execCompose('port', args, options)
|
||||||
};
|
}
|
||||||
|
|
||||||
export const version = function (options?: IDockerComposeOptions): Promise<IDockerComposeResult> {
|
export const version = function (
|
||||||
return execCompose('version', [ '--short' ], options);
|
options?: IDockerComposeOptions
|
||||||
};
|
): Promise<IDockerComposeResult> {
|
||||||
|
return execCompose('version', ['--short'], options)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,578 +1,642 @@
|
||||||
import Docker from 'dockerode';
|
import Docker from 'dockerode'
|
||||||
import * as compose from '../src/index';
|
import * as compose from '../src/index'
|
||||||
import * as path from 'path';
|
import * as path from 'path'
|
||||||
import { readFile } from 'fs'
|
import { readFile } from 'fs'
|
||||||
const docker = new Docker();
|
const docker = new Docker()
|
||||||
|
|
||||||
// Docker commands, especially builds, can take some time. This makes sure that they can take the time they need.
|
// Docker commands, especially builds, can take some time. This makes sure that they can take the time they need.
|
||||||
jest.setTimeout(25000);
|
jest.setTimeout(25000)
|
||||||
|
|
||||||
// Set to true if you need to diagnose using output
|
// Set to true if you need to diagnose using output
|
||||||
const logOutput = false;
|
const logOutput = false
|
||||||
|
|
||||||
const isContainerRunning = async (name: string): Promise<boolean> => new Promise((resolve, reject): void => {
|
const isContainerRunning = async (name: string): Promise<boolean> =>
|
||||||
|
new Promise((resolve, reject): void => {
|
||||||
docker.listContainers((err, containers): void => {
|
docker.listContainers((err, containers): void => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
const running = (containers || []).filter((container): boolean => container.Names.includes(name));
|
const running = (containers || []).filter((container): boolean =>
|
||||||
|
container.Names.includes(name)
|
||||||
|
)
|
||||||
|
|
||||||
resolve(running.length > 0);
|
resolve(running.length > 0)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
const repoTags = (imageInfo): string[] => imageInfo.RepoTags || [];
|
const repoTags = (imageInfo): string[] => imageInfo.RepoTags || []
|
||||||
|
|
||||||
const imageExists = async (name: string): Promise<boolean> => {
|
const imageExists = async (name: string): Promise<boolean> => {
|
||||||
const images = await docker.listImages();
|
const images = await docker.listImages()
|
||||||
|
|
||||||
const foundImage = images.findIndex((imageInfo): boolean => repoTags(imageInfo).includes(name));
|
const foundImage = images.findIndex((imageInfo): boolean =>
|
||||||
|
repoTags(imageInfo).includes(name)
|
||||||
|
)
|
||||||
|
|
||||||
return foundImage > -1;
|
return foundImage > -1
|
||||||
};
|
}
|
||||||
|
|
||||||
const removeImagesStartingWith = async (searchString: string): Promise<void> => {
|
const removeImagesStartingWith = async (
|
||||||
const images = await docker.listImages();
|
searchString: string
|
||||||
|
): Promise<void> => {
|
||||||
|
const images = await docker.listImages()
|
||||||
|
|
||||||
for (const image of images) {
|
for (const image of images) {
|
||||||
for (const repoTag of repoTags(image)) {
|
for (const repoTag of repoTags(image)) {
|
||||||
if (repoTag.startsWith(searchString)) {
|
if (repoTag.startsWith(searchString)) {
|
||||||
const dockerImage = docker.getImage(repoTag);
|
const dockerImage = docker.getImage(repoTag)
|
||||||
|
|
||||||
if (logOutput) {
|
if (logOutput) {
|
||||||
process.stdout.write(`removing image ${repoTag} ${dockerImage.id || ''}`);
|
process.stdout.write(
|
||||||
|
`removing image ${repoTag} ${dockerImage.id || ''}`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
await dockerImage.remove();
|
await dockerImage.remove()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
test('ensure container gets started', async (): Promise<void> => {
|
test('ensure container gets started', async (): Promise<void> => {
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
await compose.upAll({ cwd: path.join(__dirname), log: logOutput });
|
await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
|
||||||
|
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy()
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ensure exit code is returned correctly', async (): Promise<void> => {
|
test('ensure exit code is returned correctly', async (): Promise<void> => {
|
||||||
let result = await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
let result = await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
|
|
||||||
await expect(result).toMatchObject({
|
await expect(result).toMatchObject({
|
||||||
exitCode: 0
|
exitCode: 0
|
||||||
});
|
})
|
||||||
|
|
||||||
result = await compose.upAll({ cwd: path.join(__dirname), log: logOutput });
|
result = await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
|
||||||
expect(result).toMatchObject({
|
expect(result).toMatchObject({
|
||||||
exitCode: 0
|
exitCode: 0
|
||||||
});
|
})
|
||||||
try {
|
try {
|
||||||
await compose.logs('non_existent_service', { cwd: path.join(__dirname) });
|
await compose.logs('non_existent_service', { cwd: path.join(__dirname) })
|
||||||
expect(false).toBeTruthy();
|
expect(false).toBeTruthy()
|
||||||
} catch (rejectionResult) {
|
} catch (rejectionResult) {
|
||||||
expect(rejectionResult.exitCode).toBe(1);
|
expect(rejectionResult.exitCode).toBe(1)
|
||||||
}
|
}
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
describe('starts containers properly with --build and --timeout options', (): void => {
|
describe('starts containers properly with --build and --timeout options', (): void => {
|
||||||
beforeEach(async (): Promise<void> => {
|
beforeEach(
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput, config: 'docker-compose-build.yml' });
|
async (): Promise<void> => {
|
||||||
});
|
await compose.down({
|
||||||
|
cwd: path.join(__dirname),
|
||||||
|
log: logOutput,
|
||||||
|
config: 'docker-compose-build.yml'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
afterEach(async (): Promise<void> => {
|
afterEach(
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput, config: 'docker-compose-build.yml' });
|
async (): Promise<void> => {
|
||||||
});
|
await compose.down({
|
||||||
|
cwd: path.join(__dirname),
|
||||||
|
log: logOutput,
|
||||||
|
config: 'docker-compose-build.yml'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
test('ensure container gets started with --build option', async (): Promise<void> => {
|
test('ensure container gets started with --build option', async (): Promise<void> => {
|
||||||
await compose.upAll({
|
await compose.upAll({
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
log: logOutput,
|
log: logOutput,
|
||||||
config: 'docker-compose-build.yml',
|
config: 'docker-compose-build.yml',
|
||||||
commandOptions: [ '--build' ]
|
commandOptions: ['--build']
|
||||||
});
|
})
|
||||||
|
|
||||||
expect(await isContainerRunning('/compose_test_nginx')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_nginx')).toBeTruthy()
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ensure container gets started with --build and --timeout option', async (): Promise<void> => {
|
test('ensure container gets started with --build and --timeout option', async (): Promise<void> => {
|
||||||
await compose.upAll({
|
await compose.upAll({
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
log: logOutput,
|
log: logOutput,
|
||||||
config: 'docker-compose-build.yml',
|
config: 'docker-compose-build.yml',
|
||||||
commandOptions: [[ '--build' ], [ '--timeout', '5' ]]
|
commandOptions: [['--build'], ['--timeout', '5']]
|
||||||
});
|
})
|
||||||
|
|
||||||
expect(await isContainerRunning('/compose_test_nginx')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_nginx')).toBeTruthy()
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ensure container gets started with --build and --timeout option with different command style', async (): Promise<void> => {
|
test('ensure container gets started with --build and --timeout option with different command style', async (): Promise<void> => {
|
||||||
await compose.upAll({
|
await compose.upAll({
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
log: logOutput,
|
log: logOutput,
|
||||||
config: 'docker-compose-build.yml',
|
config: 'docker-compose-build.yml',
|
||||||
commandOptions: [ '--build', [ '--timeout', '5' ]]
|
commandOptions: ['--build', ['--timeout', '5']]
|
||||||
});
|
})
|
||||||
|
|
||||||
expect(await isContainerRunning('/compose_test_nginx')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_nginx')).toBeTruthy()
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ensure container command executed with --workdir command option', async (): Promise<void> => {
|
test('ensure container command executed with --workdir command option', async (): Promise<void> => {
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput, config: 'docker-compose-42.yml' });
|
await compose.down({
|
||||||
|
cwd: path.join(__dirname),
|
||||||
|
log: logOutput,
|
||||||
|
config: 'docker-compose-42.yml'
|
||||||
|
})
|
||||||
const result = await compose.run('some-service', 'pwd', {
|
const result = await compose.run('some-service', 'pwd', {
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
log: true,
|
log: true,
|
||||||
config: 'docker-compose-42.yml',
|
config: 'docker-compose-42.yml',
|
||||||
composeOptions: [ '--verbose' ],
|
composeOptions: ['--verbose'],
|
||||||
|
|
||||||
// Alpine has "/" as default
|
// Alpine has "/" as default
|
||||||
commandOptions: [ '--workdir', '/home/root' ]
|
commandOptions: ['--workdir', '/home/root']
|
||||||
});
|
})
|
||||||
|
|
||||||
expect(result.out).toBe('/home/root\n');
|
expect(result.out).toBe('/home/root\n')
|
||||||
|
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput, config: 'docker-compose-42.yml' });
|
await compose.down({
|
||||||
});
|
cwd: path.join(__dirname),
|
||||||
|
log: logOutput,
|
||||||
|
config: 'docker-compose-42.yml'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('ensure only single container gets started', async (): Promise<void> => {
|
test('ensure only single container gets started', async (): Promise<void> => {
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
await compose.upOne('web', { cwd: path.join(__dirname), log: logOutput });
|
await compose.upOne('web', { cwd: path.join(__dirname), log: logOutput })
|
||||||
|
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy()
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ensure only multiple containers get started', async (): Promise<void> => {
|
test('ensure only multiple containers get started', async (): Promise<void> => {
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
await compose.upMany([ 'web' ], { cwd: path.join(__dirname), log: logOutput });
|
await compose.upMany(['web'], { cwd: path.join(__dirname), log: logOutput })
|
||||||
|
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy()
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ensure container gets down', async (): Promise<void> => {
|
test('ensure container gets down', async (): Promise<void> => {
|
||||||
await compose.upAll({ cwd: path.join(__dirname), log: logOutput });
|
await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy()
|
||||||
|
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_web')).toBeFalsy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy()
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ensure container gets stopped', async (): Promise<void> => {
|
test('ensure container gets stopped', async (): Promise<void> => {
|
||||||
await compose.upAll({ cwd: path.join(__dirname), log: logOutput });
|
await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy()
|
||||||
|
|
||||||
await compose.stop({ cwd: path.join(__dirname), log: logOutput });
|
await compose.stop({ cwd: path.join(__dirname), log: logOutput })
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_web')).toBeFalsy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy()
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ensure only single container gets stopped', async (): Promise<void> => {
|
test('ensure only single container gets stopped', async (): Promise<void> => {
|
||||||
await compose.upAll({ cwd: path.join(__dirname), log: logOutput });
|
await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy()
|
||||||
|
|
||||||
await compose.stopOne('proxy', { cwd: path.join(__dirname), log: logOutput });
|
await compose.stopOne('proxy', { cwd: path.join(__dirname), log: logOutput })
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy()
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ensure container gets started with --abort-on-container-exit option', async (): Promise<void> => {
|
test('ensure container gets started with --abort-on-container-exit option', async (): Promise<void> => {
|
||||||
const result = await compose.upAll({
|
const result = await compose.upAll({
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
log: logOutput,
|
log: logOutput,
|
||||||
commandOptions: [ '--abort-on-container-exit' ]
|
commandOptions: ['--abort-on-container-exit']
|
||||||
});
|
})
|
||||||
|
|
||||||
expect(result).toMatchObject({
|
expect(result).toMatchObject({
|
||||||
exitCode: 0
|
exitCode: 0
|
||||||
});
|
})
|
||||||
|
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_web')).toBeFalsy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy()
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ensure container gets started with --abort-on-container-exit option correctly aborts all services when a container exits', async (): Promise<void> => {
|
test('ensure container gets started with --abort-on-container-exit option correctly aborts all services when a container exits', async (): Promise<void> => {
|
||||||
const result = await compose.upAll({
|
const result = await compose.upAll({
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
log: logOutput,
|
log: logOutput,
|
||||||
commandOptions: [ '--abort-on-container-exit' ]
|
commandOptions: ['--abort-on-container-exit']
|
||||||
});
|
})
|
||||||
|
|
||||||
expect(result.out).toMatch(/Aborting on container exit/);
|
expect(result.out).toMatch(/Aborting on container exit/)
|
||||||
|
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_web')).toBeFalsy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy()
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ensure container gets killed', async (): Promise<void> => {
|
test('ensure container gets killed', async (): Promise<void> => {
|
||||||
await compose.upAll({ cwd: path.join(__dirname), log: logOutput });
|
await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy()
|
||||||
|
|
||||||
await compose.kill({ cwd: path.join(__dirname), log: logOutput });
|
await compose.kill({ cwd: path.join(__dirname), log: logOutput })
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_web')).toBeFalsy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy()
|
||||||
|
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ensure custom ymls are working', async (): Promise<void> => {
|
test('ensure custom ymls are working', async (): Promise<void> => {
|
||||||
const config = './docker-compose-2.yml';
|
const config = './docker-compose-2.yml'
|
||||||
const cwd = path.join(__dirname);
|
const cwd = path.join(__dirname)
|
||||||
|
|
||||||
await compose.upAll({ cwd, log: logOutput, config });
|
await compose.upAll({ cwd, log: logOutput, config })
|
||||||
expect(await isContainerRunning('/compose_test_web_2')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web_2')).toBeTruthy()
|
||||||
|
|
||||||
// config & [config] are the same thing, ensures that multiple configs are handled properly
|
// config & [config] are the same thing, ensures that multiple configs are handled properly
|
||||||
await compose.kill({ cwd, log: logOutput, config: [ config ]});
|
await compose.kill({ cwd, log: logOutput, config: [config] })
|
||||||
expect(await isContainerRunning('/compose_test_web_2')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_web_2')).toBeFalsy()
|
||||||
|
|
||||||
await compose.down({ cwd, log: logOutput, config });
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
await compose.down({ cwd, log: logOutput, config })
|
||||||
|
})
|
||||||
|
|
||||||
test('ensure run and exec are working', async (): Promise<void> => {
|
test('ensure run and exec are working', async (): Promise<void> => {
|
||||||
const checkOSID = (out, id): void => {
|
const checkOSID = (out, id): void => {
|
||||||
// parse /etc/os-release contents
|
// parse /etc/os-release contents
|
||||||
const re = /([\w,_]+)=(.*)/g;
|
const re = /([\w,_]+)=(.*)/g
|
||||||
let match;
|
let match
|
||||||
const os: {ID?: string} = {};
|
const os: { ID?: string } = {}
|
||||||
|
|
||||||
while ((match = re.exec(out)) !== null) { // eslint-disable-line no-cond-assign
|
while ((match = re.exec(out)) !== null) {
|
||||||
os[match[1]] = match[2];
|
// eslint-disable-line no-cond-assign
|
||||||
|
os[match[1]] = match[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(os.ID).toBe(id);
|
expect(os.ID).toBe(id)
|
||||||
};
|
}
|
||||||
|
|
||||||
const opts = { cwd: path.join(__dirname), log: logOutput };
|
const opts = { cwd: path.join(__dirname), log: logOutput }
|
||||||
|
|
||||||
await compose.upAll(opts);
|
await compose.upAll(opts)
|
||||||
const console = require('console');
|
const console = require('console')
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
|
||||||
|
|
||||||
let std = await compose.exec('web', 'cat /etc/os-release', opts);
|
let std = await compose.exec('web', 'cat /etc/os-release', opts)
|
||||||
|
|
||||||
checkOSID(std.out, 'debian');
|
checkOSID(std.out, 'debian')
|
||||||
|
|
||||||
std = await compose.run('proxy', 'cat /etc/os-release', opts);
|
std = await compose.run('proxy', 'cat /etc/os-release', opts)
|
||||||
|
|
||||||
checkOSID(std.out, 'alpine');
|
checkOSID(std.out, 'alpine')
|
||||||
|
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ensure run and exec with command defined as array are working', async (): Promise<void> => {
|
test('ensure run and exec with command defined as array are working', async (): Promise<void> => {
|
||||||
const checkOSID = (out, id): void => {
|
const checkOSID = (out, id): void => {
|
||||||
// parse /etc/os-release contents
|
// parse /etc/os-release contents
|
||||||
const re = /([\w,_]+)=(.*)/g;
|
const re = /([\w,_]+)=(.*)/g
|
||||||
let match;
|
let match
|
||||||
const os: {ID?: string} = {};
|
const os: { ID?: string } = {}
|
||||||
|
|
||||||
while ((match = re.exec(out)) !== null) { // eslint-disable-line no-cond-assign
|
while ((match = re.exec(out)) !== null) {
|
||||||
os[match[1]] = match[2];
|
// eslint-disable-line no-cond-assign
|
||||||
|
os[match[1]] = match[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(os.ID).toBe(id);
|
expect(os.ID).toBe(id)
|
||||||
};
|
}
|
||||||
|
|
||||||
const opts = { cwd: path.join(__dirname), log: false };
|
const opts = { cwd: path.join(__dirname), log: false }
|
||||||
|
|
||||||
await compose.upAll(opts);
|
await compose.upAll(opts)
|
||||||
|
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBe(true);
|
expect(await isContainerRunning('/compose_test_web')).toBe(true)
|
||||||
|
|
||||||
let std = await compose.exec('web', [ '/bin/sh', '-c', 'cat /etc/os-release' ], opts);
|
let std = await compose.exec(
|
||||||
|
'web',
|
||||||
|
['/bin/sh', '-c', 'cat /etc/os-release'],
|
||||||
|
opts
|
||||||
|
)
|
||||||
|
|
||||||
checkOSID(std.out, 'debian');
|
checkOSID(std.out, 'debian')
|
||||||
|
|
||||||
std = await compose.run('proxy', [ '/bin/sh', '-c', 'cat /etc/os-release' ], opts);
|
std = await compose.run(
|
||||||
checkOSID(std.out, 'alpine');
|
'proxy',
|
||||||
|
['/bin/sh', '-c', 'cat /etc/os-release'],
|
||||||
|
opts
|
||||||
|
)
|
||||||
|
checkOSID(std.out, 'alpine')
|
||||||
|
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('build accepts config as string', async (): Promise<void> => {
|
test('build accepts config as string', async (): Promise<void> => {
|
||||||
const configuration = await new Promise<string>(function (resolve, reject): void {
|
const configuration = await new Promise<string>(function (
|
||||||
readFile(path.join(__dirname, 'docker-compose-2.yml'), function (err, content) {
|
resolve,
|
||||||
|
reject
|
||||||
|
): void {
|
||||||
|
readFile(
|
||||||
|
path.join(__dirname, 'docker-compose-2.yml'),
|
||||||
|
function (err, content) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
resolve(content.toString());
|
resolve(content.toString())
|
||||||
|
}
|
||||||
|
)
|
||||||
})
|
})
|
||||||
});
|
|
||||||
const config = {
|
const config = {
|
||||||
configAsString: configuration,
|
configAsString: configuration,
|
||||||
log: logOutput,
|
log: logOutput
|
||||||
};
|
}
|
||||||
|
|
||||||
await compose.upAll(config);
|
await compose.upAll(config)
|
||||||
const port = await compose.port('web', 8888, config);
|
const port = await compose.port('web', 8888, config)
|
||||||
|
|
||||||
expect(port.out).toMatch(/.*:[0-9]{1,5}/);
|
expect(port.out).toMatch(/.*:[0-9]{1,5}/)
|
||||||
await compose.down(config);
|
await compose.down(config)
|
||||||
});
|
})
|
||||||
|
|
||||||
test('build single service', async (): Promise<void> => {
|
test('build single service', async (): Promise<void> => {
|
||||||
const opts = {
|
const opts = {
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
log: logOutput,
|
log: logOutput,
|
||||||
config: 'docker-compose-build.yml'
|
config: 'docker-compose-build.yml'
|
||||||
};
|
}
|
||||||
|
|
||||||
await removeImagesStartingWith('compose-test-build-image');
|
await removeImagesStartingWith('compose-test-build-image')
|
||||||
|
|
||||||
await compose.buildOne('build_test_1', opts);
|
await compose.buildOne('build_test_1', opts)
|
||||||
|
|
||||||
expect(await imageExists('compose-test-build-image-1:test')).toBeTruthy();
|
expect(await imageExists('compose-test-build-image-1:test')).toBeTruthy()
|
||||||
expect(await imageExists('compose-test-build-image-2:test')).toBeFalsy();
|
expect(await imageExists('compose-test-build-image-2:test')).toBeFalsy()
|
||||||
expect(await imageExists('compose-test-build-image-3:test')).toBeFalsy();
|
expect(await imageExists('compose-test-build-image-3:test')).toBeFalsy()
|
||||||
expect(await imageExists('compose-test-build-image-4:test')).toBeFalsy();
|
expect(await imageExists('compose-test-build-image-4:test')).toBeFalsy()
|
||||||
|
|
||||||
await removeImagesStartingWith('compose-test-build-image');
|
await removeImagesStartingWith('compose-test-build-image')
|
||||||
});
|
})
|
||||||
|
|
||||||
test('build multiple services', async (): Promise<void> => {
|
test('build multiple services', async (): Promise<void> => {
|
||||||
const opts = {
|
const opts = {
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
log: logOutput,
|
log: logOutput,
|
||||||
config: 'docker-compose-build.yml'
|
config: 'docker-compose-build.yml'
|
||||||
};
|
}
|
||||||
|
|
||||||
await compose.buildMany([ 'build_test_2', 'build_test_3' ], opts);
|
await compose.buildMany(['build_test_2', 'build_test_3'], opts)
|
||||||
|
|
||||||
expect(await imageExists('compose-test-build-image-1:test')).toBeFalsy();
|
expect(await imageExists('compose-test-build-image-1:test')).toBeFalsy()
|
||||||
expect(await imageExists('compose-test-build-image-2:test')).toBeTruthy();
|
expect(await imageExists('compose-test-build-image-2:test')).toBeTruthy()
|
||||||
expect(await imageExists('compose-test-build-image-3:test')).toBeTruthy();
|
expect(await imageExists('compose-test-build-image-3:test')).toBeTruthy()
|
||||||
expect(await imageExists('compose-test-build-image-4:test')).toBeFalsy();
|
expect(await imageExists('compose-test-build-image-4:test')).toBeFalsy()
|
||||||
|
|
||||||
await removeImagesStartingWith('compose-test-build-image');
|
await removeImagesStartingWith('compose-test-build-image')
|
||||||
});
|
})
|
||||||
|
|
||||||
test('build all services', async (): Promise<void> => {
|
test('build all services', async (): Promise<void> => {
|
||||||
const opts = {
|
const opts = {
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
log: logOutput,
|
log: logOutput,
|
||||||
config: 'docker-compose-build.yml'
|
config: 'docker-compose-build.yml'
|
||||||
};
|
}
|
||||||
|
|
||||||
await compose.buildAll(opts);
|
await compose.buildAll(opts)
|
||||||
|
|
||||||
expect(await imageExists('compose-test-build-image-1:test')).toBeTruthy();
|
expect(await imageExists('compose-test-build-image-1:test')).toBeTruthy()
|
||||||
expect(await imageExists('compose-test-build-image-2:test')).toBeTruthy();
|
expect(await imageExists('compose-test-build-image-2:test')).toBeTruthy()
|
||||||
expect(await imageExists('compose-test-build-image-3:test')).toBeTruthy();
|
expect(await imageExists('compose-test-build-image-3:test')).toBeTruthy()
|
||||||
expect(await imageExists('compose-test-build-image-4:test')).toBeTruthy();
|
expect(await imageExists('compose-test-build-image-4:test')).toBeTruthy()
|
||||||
|
|
||||||
await removeImagesStartingWith('compose-test-build-image');
|
await removeImagesStartingWith('compose-test-build-image')
|
||||||
});
|
})
|
||||||
|
|
||||||
test('pull single service', async (): Promise<void> => {
|
test('pull single service', async (): Promise<void> => {
|
||||||
const opts = {
|
const opts = {
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
log: logOutput,
|
log: logOutput,
|
||||||
config: 'docker-compose.yml'
|
config: 'docker-compose.yml'
|
||||||
};
|
}
|
||||||
|
|
||||||
await removeImagesStartingWith('nginx:1.19.9-alpine');
|
await removeImagesStartingWith('nginx:1.19.9-alpine')
|
||||||
expect(await imageExists('nginx:1.19.9-alpine')).toBeFalsy();
|
expect(await imageExists('nginx:1.19.9-alpine')).toBeFalsy()
|
||||||
|
|
||||||
await compose.pullOne('proxy', opts);
|
await compose.pullOne('proxy', opts)
|
||||||
|
|
||||||
expect(await imageExists('nginx:1.19.9-alpine')).toBeTruthy();
|
expect(await imageExists('nginx:1.19.9-alpine')).toBeTruthy()
|
||||||
});
|
})
|
||||||
|
|
||||||
test('pull multiple services', async (): Promise<void> => {
|
test('pull multiple services', async (): Promise<void> => {
|
||||||
const opts = {
|
const opts = {
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
log: logOutput,
|
log: logOutput,
|
||||||
config: 'docker-compose.yml'
|
config: 'docker-compose.yml'
|
||||||
};
|
}
|
||||||
|
|
||||||
await removeImagesStartingWith('nginx:1.16.0');
|
await removeImagesStartingWith('nginx:1.16.0')
|
||||||
await removeImagesStartingWith('nginx:1.19.9-alpine');
|
await removeImagesStartingWith('nginx:1.19.9-alpine')
|
||||||
|
|
||||||
expect(await imageExists('nginx:1.16.0')).toBeFalsy();
|
expect(await imageExists('nginx:1.16.0')).toBeFalsy()
|
||||||
expect(await imageExists('nginx:1.19.9-alpine')).toBeFalsy();
|
expect(await imageExists('nginx:1.19.9-alpine')).toBeFalsy()
|
||||||
|
|
||||||
await compose.pullMany([ 'web', 'proxy' ], opts);
|
await compose.pullMany(['web', 'proxy'], opts)
|
||||||
|
|
||||||
expect(await imageExists('nginx:1.16.0')).toBeTruthy();
|
expect(await imageExists('nginx:1.16.0')).toBeTruthy()
|
||||||
expect(await imageExists('nginx:1.19.9-alpine')).toBeTruthy();
|
expect(await imageExists('nginx:1.19.9-alpine')).toBeTruthy()
|
||||||
});
|
})
|
||||||
|
|
||||||
test('pull all services', async (): Promise<void> => {
|
test('pull all services', async (): Promise<void> => {
|
||||||
const opts = {
|
const opts = {
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
log: logOutput,
|
log: logOutput,
|
||||||
config: 'docker-compose.yml'
|
config: 'docker-compose.yml'
|
||||||
};
|
}
|
||||||
|
|
||||||
await removeImagesStartingWith('nginx:1.16.0');
|
await removeImagesStartingWith('nginx:1.16.0')
|
||||||
await removeImagesStartingWith('nginx:1.19.9-alpine');
|
await removeImagesStartingWith('nginx:1.19.9-alpine')
|
||||||
|
|
||||||
expect(await imageExists('nginx:1.16.0')).toBeFalsy();
|
expect(await imageExists('nginx:1.16.0')).toBeFalsy()
|
||||||
expect(await imageExists('nginx:1.19.9-alpine')).toBeFalsy();
|
expect(await imageExists('nginx:1.19.9-alpine')).toBeFalsy()
|
||||||
|
|
||||||
await compose.pullAll(opts);
|
await compose.pullAll(opts)
|
||||||
|
|
||||||
expect(await imageExists('nginx:1.16.0')).toBeTruthy();
|
expect(await imageExists('nginx:1.16.0')).toBeTruthy()
|
||||||
expect(await imageExists('nginx:1.19.9-alpine')).toBeTruthy();
|
expect(await imageExists('nginx:1.19.9-alpine')).toBeTruthy()
|
||||||
});
|
})
|
||||||
|
|
||||||
test('teardown', async (): Promise<void> => {
|
test('teardown', async (): Promise<void> => {
|
||||||
interface Container {
|
interface Container {
|
||||||
Names: string[];
|
Names: string[]
|
||||||
Id: string;
|
Id: string
|
||||||
}
|
}
|
||||||
|
|
||||||
docker.listContainers((err, containers: Container[]): void => {
|
docker.listContainers((err, containers: Container[]): void => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err
|
||||||
}
|
}
|
||||||
|
|
||||||
containers.forEach((container): void => {
|
containers.forEach((container): void => {
|
||||||
container.Names.forEach((name: string): void => {
|
container.Names.forEach((name: string): void => {
|
||||||
if (name.startsWith('/compose_test_')) {
|
if (name.startsWith('/compose_test_')) {
|
||||||
console.log(`stopping ${container.Id} ${container.Names}`);
|
console.log(`stopping ${container.Id} ${container.Names}`)
|
||||||
docker.getContainer(container.Id).stop();
|
docker.getContainer(container.Id).stop()
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
await removeImagesStartingWith('compose-test-build-image');
|
await removeImagesStartingWith('compose-test-build-image')
|
||||||
});
|
})
|
||||||
|
|
||||||
test('config show data for docker-compose files', async (): Promise<void> => {
|
test('config show data for docker-compose files', async (): Promise<void> => {
|
||||||
const std = await compose.config({ cwd: path.join(__dirname), log: logOutput, config: 'docker-compose-42.yml' });
|
const std = await compose.config({
|
||||||
|
cwd: path.join(__dirname),
|
||||||
|
log: logOutput,
|
||||||
|
config: 'docker-compose-42.yml'
|
||||||
|
})
|
||||||
|
|
||||||
expect(std.err).toBeFalsy();
|
expect(std.err).toBeFalsy()
|
||||||
expect(std.out.includes('some-service')).toBeTruthy();
|
expect(std.out.includes('some-service')).toBeTruthy()
|
||||||
expect(std.out.includes('test/volume:/mountedvolume:rw')).toBeTruthy();
|
expect(std.out.includes('test/volume:/mountedvolume:rw')).toBeTruthy()
|
||||||
});
|
})
|
||||||
|
|
||||||
test('config show data for docker-compose files (services)', async (): Promise<void> => {
|
test('config show data for docker-compose files (services)', async (): Promise<void> => {
|
||||||
const std = await compose.configServices({ cwd: path.join(__dirname), log: logOutput, config: 'docker-compose-42.yml' });
|
const std = await compose.configServices({
|
||||||
|
cwd: path.join(__dirname),
|
||||||
|
log: logOutput,
|
||||||
|
config: 'docker-compose-42.yml'
|
||||||
|
})
|
||||||
|
|
||||||
expect(std.err).toBeFalsy();
|
expect(std.err).toBeFalsy()
|
||||||
expect(std.out.includes('some-service')).toBeTruthy();
|
expect(std.out.includes('some-service')).toBeTruthy()
|
||||||
});
|
})
|
||||||
|
|
||||||
test('config show data for docker-compose files (volumes)', async (): Promise<void> => {
|
test('config show data for docker-compose files (volumes)', async (): Promise<void> => {
|
||||||
const std = await compose.configVolumes({ cwd: path.join(__dirname), log: logOutput, config: 'docker-compose-42.yml' });
|
const std = await compose.configVolumes({
|
||||||
|
cwd: path.join(__dirname),
|
||||||
|
log: logOutput,
|
||||||
|
config: 'docker-compose-42.yml'
|
||||||
|
})
|
||||||
|
|
||||||
expect(std.err).toBeFalsy();
|
expect(std.err).toBeFalsy()
|
||||||
expect(std.out.includes('db-data')).toBeTruthy();
|
expect(std.out.includes('db-data')).toBeTruthy()
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ps shows status data for started containers', async (): Promise<void> => {
|
test('ps shows status data for started containers', async (): Promise<void> => {
|
||||||
await compose.upAll({ cwd: path.join(__dirname), log: logOutput });
|
await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
|
||||||
|
|
||||||
const std = await compose.ps({ cwd: path.join(__dirname), log: logOutput });
|
const std = await compose.ps({ cwd: path.join(__dirname), log: logOutput })
|
||||||
|
|
||||||
expect(std.err).toBeFalsy();
|
expect(std.err).toBeFalsy()
|
||||||
expect(std.out.includes('compose_test_web')).toBeTruthy();
|
expect(std.out.includes('compose_test_web')).toBeTruthy()
|
||||||
expect(std.out.includes('compose_test_proxy')).toBeTruthy();
|
expect(std.out.includes('compose_test_proxy')).toBeTruthy()
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('ps does not show status data for stopped containers', async (): Promise<void> => {
|
test('ps does not show status data for stopped containers', async (): Promise<void> => {
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
await compose.upOne('web', { cwd: path.join(__dirname), log: logOutput });
|
await compose.upOne('web', { cwd: path.join(__dirname), log: logOutput })
|
||||||
|
|
||||||
const std = await compose.ps({ cwd: path.join(__dirname), log: logOutput });
|
const std = await compose.ps({ cwd: path.join(__dirname), log: logOutput })
|
||||||
|
|
||||||
expect(std.err).toBeFalsy();
|
expect(std.err).toBeFalsy()
|
||||||
expect(std.out.includes('compose_test_web')).toBeTruthy();
|
expect(std.out.includes('compose_test_web')).toBeTruthy()
|
||||||
expect(std.out.includes('compose_test_proxy')).toBeFalsy();
|
expect(std.out.includes('compose_test_proxy')).toBeFalsy()
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('restartAll does restart all containers', async (): Promise<void> => {
|
test('restartAll does restart all containers', async (): Promise<void> => {
|
||||||
await compose.upAll({ cwd: path.join(__dirname), log: logOutput });
|
await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
|
||||||
await compose.restartAll({ cwd: path.join(__dirname), log: logOutput });
|
await compose.restartAll({ cwd: path.join(__dirname), log: logOutput })
|
||||||
|
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy()
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('restartMany does restart selected containers', async (): Promise<void> => {
|
test('restartMany does restart selected containers', async (): Promise<void> => {
|
||||||
await compose.upAll({ cwd: path.join(__dirname), log: logOutput });
|
await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
|
||||||
await compose.restartMany([ 'web', 'proxy' ], { cwd: path.join(__dirname), log: logOutput });
|
await compose.restartMany(['web', 'proxy'], {
|
||||||
|
cwd: path.join(__dirname),
|
||||||
|
log: logOutput
|
||||||
|
})
|
||||||
|
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('restartOne does restart container', async (): Promise<void> => {
|
test('restartOne does restart container', async (): Promise<void> => {
|
||||||
await compose.upAll({ cwd: path.join(__dirname), log: logOutput });
|
await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
|
||||||
await compose.restartOne('proxy', { cwd: path.join(__dirname), log: logOutput });
|
await compose.restartOne('proxy', {
|
||||||
|
cwd: path.join(__dirname),
|
||||||
|
log: logOutput
|
||||||
|
})
|
||||||
|
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy()
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('logs does follow service logs', async (): Promise<void> => {
|
test('logs does follow service logs', async (): Promise<void> => {
|
||||||
await compose.upAll({ cwd: path.join(__dirname), log: logOutput });
|
await compose.upAll({ cwd: path.join(__dirname), log: logOutput })
|
||||||
const std = await compose.logs('proxy', { cwd: path.join(__dirname), log: logOutput });
|
const std = await compose.logs('proxy', {
|
||||||
|
cwd: path.join(__dirname),
|
||||||
|
log: logOutput
|
||||||
|
})
|
||||||
|
|
||||||
expect(std.out.includes('compose_test_proxy')).toBeTruthy();
|
expect(std.out.includes('compose_test_proxy')).toBeTruthy()
|
||||||
await compose.down({ cwd: path.join(__dirname), log: logOutput });
|
await compose.down({ cwd: path.join(__dirname), log: logOutput })
|
||||||
});
|
})
|
||||||
|
|
||||||
test('returns the port for a started service', async (): Promise<void> => {
|
test('returns the port for a started service', async (): Promise<void> => {
|
||||||
const config = {
|
const config = {
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
config: './docker-compose-2.yml',
|
config: './docker-compose-2.yml',
|
||||||
log: logOutput
|
log: logOutput
|
||||||
};
|
}
|
||||||
|
|
||||||
await compose.upAll(config);
|
await compose.upAll(config)
|
||||||
const port = await compose.port('web', 8888, config);
|
const port = await compose.port('web', 8888, config)
|
||||||
|
|
||||||
expect(port.out).toMatch(/.*:[0-9]{1,5}/);
|
expect(port.out).toMatch(/.*:[0-9]{1,5}/)
|
||||||
await compose.down(config);
|
await compose.down(config)
|
||||||
});
|
})
|
||||||
|
|
||||||
test('removes container', async (): Promise<void> => {
|
test('removes container', async (): Promise<void> => {
|
||||||
const config = {
|
const config = {
|
||||||
cwd: path.join(__dirname),
|
cwd: path.join(__dirname),
|
||||||
config: './docker-compose.yml',
|
config: './docker-compose.yml',
|
||||||
log: logOutput
|
log: logOutput
|
||||||
};
|
}
|
||||||
|
|
||||||
await compose.upAll(config);
|
await compose.upAll(config)
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeTruthy()
|
||||||
|
|
||||||
await compose.rm({ ...config, commandOptions: ['-s'] }, 'proxy');
|
await compose.rm({ ...config, commandOptions: ['-s'] }, 'proxy')
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeTruthy();
|
expect(await isContainerRunning('/compose_test_web')).toBeTruthy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy()
|
||||||
|
|
||||||
await compose.rm({ ...config, commandOptions: ['-s'] }, 'proxy', 'web');
|
await compose.rm({ ...config, commandOptions: ['-s'] }, 'proxy', 'web')
|
||||||
expect(await isContainerRunning('/compose_test_web')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_web')).toBeFalsy()
|
||||||
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy();
|
expect(await isContainerRunning('/compose_test_proxy')).toBeFalsy()
|
||||||
});
|
})
|
||||||
|
|
||||||
test('returns version information', async (): Promise<void> => {
|
test('returns version information', async (): Promise<void> => {
|
||||||
const version = await compose.version();
|
const version = await compose.version()
|
||||||
|
|
||||||
expect(version.out).toBeTruthy();
|
expect(version.out).toBeTruthy()
|
||||||
});
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue