mirror of
https://github.com/docker/build-push-action.git
synced 2025-04-21 02:36:46 +00:00
Check if buildx installed (builder alias)
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
6b0b71d882
commit
ac03ceb5e6
3 changed files with 52 additions and 5 deletions
|
@ -1,5 +1,17 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
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) {
|
||||
|
@ -9,6 +21,18 @@ 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';
|
||||
}
|
||||
|
||||
export async function use(builder: string): Promise<void> {
|
||||
return await exec.exec(`docker`, ['buildx', 'use', '--builder', builder], false).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue