Support creating docker networks from the plugin

This commit is contained in:
RMidhunSuresh 2022-09-06 01:29:37 +05:30
parent 3ff83f3d3d
commit 888a509c37

View File

@ -78,6 +78,31 @@ export function dockerExec(args: {
}); });
} }
/**
* Create a docker network; does not fail if network already exists
*/
export function dockerCreateNetwork(args: {
networkName: string;
}): Promise<void> {
return new Promise<void>((resolve, reject) => {
childProcess.execFile("docker", [
"network",
"create",
args.networkName
], { encoding: 'utf8' }, (err, stdout, stderr) => {
if(err) {
if (stderr.includes(`network with name ${args.networkName} already exists`)) {
// Don't consider this as error
resolve();
}
reject(err);
return;
}
resolve();
})
});
}
export async function dockerLogs(args: { export async function dockerLogs(args: {
containerId: string; containerId: string;
stdoutFile?: string; stdoutFile?: string;
@ -142,5 +167,6 @@ export function docker(on: PluginEvents, config: PluginConfigOptions) {
dockerLogs, dockerLogs,
dockerStop, dockerStop,
dockerRm, dockerRm,
dockerCreateNetwork
}); });
} }