mirror of
https://github.com/docker/build-push-action.git
synced 2025-05-06 21:49:33 +02:00
Refactor Docker config
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
ac03ceb5e6
commit
f7cac3b071
4 changed files with 51 additions and 38 deletions
|
@ -1,17 +1,6 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
import * as docker from './docker';
|
||||
import * as exec from './exec';
|
||||
|
||||
interface DockerConfig {
|
||||
credsStore?: string;
|
||||
experimental?: string;
|
||||
stackOrchestrator?: string;
|
||||
aliases?: {
|
||||
builder?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export async function isAvailable(): Promise<Boolean> {
|
||||
return await exec.exec(`docker`, ['buildx'], true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
|
@ -22,15 +11,8 @@ export async function isAvailable(): Promise<Boolean> {
|
|||
}
|
||||
|
||||
export async function isInstalled(): Promise<Boolean> {
|
||||
const dockerHome: string = process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker');
|
||||
|
||||
const dockerCfgFile: string = path.join(dockerHome, 'config.json');
|
||||
if (!fs.existsSync(dockerCfgFile)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const dockerCfg: DockerConfig = JSON.parse(fs.readFileSync(dockerCfgFile, {encoding: 'utf-8'}));
|
||||
return dockerCfg.aliases?.builder == 'buildx';
|
||||
const dockerCfg = await docker.config();
|
||||
return dockerCfg?.aliases?.builder == 'buildx';
|
||||
}
|
||||
|
||||
export async function use(builder: string): Promise<void> {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue