Files
api/app/core/utils/clients/docker.ts
Alexis Tyler 855ba2fc75 chore: lint
2021-01-29 12:03:26 +10:30

29 lines
827 B
XML

/*!
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
* Written by: Alexis Tyler
*/
import pify from 'pify';
import Docker from 'dockerode';
import { paths } from '../../paths';
// Borrowed from https://stackoverflow.com/a/52731696 until pify
// adds their own types, check https://github.com/sindresorhus/pify/issues/74
type UnpackedPromise<T> = T extends Promise<infer U> ? U : T;
type GenericFunction<TS extends any[], R> = (...args: TS) => R;
type Promisify<T> = {
[K in keyof T]: T[K] extends GenericFunction<infer TS, infer R>
? (...args: TS) => Promise<UnpackedPromise<R>>
: never
};
const socketPath = paths.get('docker-socket') ?? '/var/run/docker.sock';
const client = new Docker({
socketPath
});
/**
* Docker client
*/
export const docker = pify(client) as unknown as Promisify<Docker>;