Refactor Docker config

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2020-08-16 02:37:47 +02:00
parent ac03ceb5e6
commit f7cac3b071
4 changed files with 51 additions and 38 deletions

View File

@ -1,3 +1,16 @@
import path from 'path';
import os from 'os';
import fs from 'fs';
export interface Config {
credsStore?: string;
experimental?: string;
stackOrchestrator?: string;
aliases?: {
builder?: string;
};
}
export interface Image {
registry?: string;
namespace?: string;
@ -5,6 +18,17 @@ export interface Image {
tag?: string;
}
export async function config(): Promise<Config | undefined> {
const dockerHome: string = process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker');
const file: string = path.join(dockerHome, 'config.json');
if (!fs.existsSync(file)) {
return;
}
return JSON.parse(fs.readFileSync(file, {encoding: 'utf-8'})) as Config;
}
export const parseImage = async (image: string): Promise<Image | undefined> => {
const match = image.match(/^(?:([^\/]+)\/)?(?:([^\/]+)\/)?([^@:\/]+)(?:[@:](.+))?$/);
if (!match) {