2
0
Fork 0
mirror of https://code.forgejo.org/docker/build-push-action.git synced 2025-08-05 17:00:58 +00:00

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
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
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) {