mirror of
https://github.com/docker/build-push-action.git
synced 2024-11-26 20:59:04 +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
27
dist/index.js
generated
vendored
27
dist/index.js
generated
vendored
@ -1015,11 +1015,13 @@ function run() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const inputs = yield context_helper_1.loadInputs();
|
const inputs = yield context_helper_1.loadInputs();
|
||||||
|
const buildxAvailable = yield buildx.isAvailable();
|
||||||
|
const buildxInstalled = buildxAvailable && (yield buildx.isInstalled());
|
||||||
|
const buildxEnabled = (yield context_helper_1.mustBuildx(inputs)) || buildxInstalled;
|
||||||
let buildArgs = [];
|
let buildArgs = [];
|
||||||
const buildxEnabled = yield context_helper_1.mustBuildx(inputs);
|
|
||||||
// Check buildx
|
// Check buildx
|
||||||
if (buildxEnabled) {
|
if (buildxEnabled) {
|
||||||
if (yield !buildx.isAvailable()) {
|
if (!buildxAvailable) {
|
||||||
core.setFailed(`Buildx is required but not available`);
|
core.setFailed(`Buildx is required but not available`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1893,8 +1895,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.use = exports.isAvailable = void 0;
|
exports.use = exports.isInstalled = exports.isAvailable = void 0;
|
||||||
|
const fs_1 = __importDefault(__webpack_require__(747));
|
||||||
|
const path_1 = __importDefault(__webpack_require__(622));
|
||||||
|
const os_1 = __importDefault(__webpack_require__(87));
|
||||||
const exec = __importStar(__webpack_require__(807));
|
const exec = __importStar(__webpack_require__(807));
|
||||||
function isAvailable() {
|
function isAvailable() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
@ -1907,6 +1915,19 @@ function isAvailable() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.isAvailable = isAvailable;
|
exports.isAvailable = isAvailable;
|
||||||
|
function isInstalled() {
|
||||||
|
var _a;
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const dockerHome = process.env.DOCKER_CONFIG || path_1.default.join(os_1.default.homedir(), '.docker');
|
||||||
|
const dockerCfgFile = path_1.default.join(dockerHome, 'config.json');
|
||||||
|
if (!fs_1.default.existsSync(dockerCfgFile)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const dockerCfg = JSON.parse(fs_1.default.readFileSync(dockerCfgFile, { encoding: 'utf-8' }));
|
||||||
|
return ((_a = dockerCfg.aliases) === null || _a === void 0 ? void 0 : _a.builder) == 'buildx';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.isInstalled = isInstalled;
|
||||||
function use(builder) {
|
function use(builder) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
return yield exec.exec(`docker`, ['buildx', 'use', '--builder', builder], false).then(res => {
|
return yield exec.exec(`docker`, ['buildx', 'use', '--builder', builder], false).then(res => {
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import os from 'os';
|
||||||
import * as exec from './exec';
|
import * as exec from './exec';
|
||||||
|
|
||||||
|
interface DockerConfig {
|
||||||
|
credsStore?: string;
|
||||||
|
experimental?: string;
|
||||||
|
stackOrchestrator?: string;
|
||||||
|
aliases?: {
|
||||||
|
builder?: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function isAvailable(): Promise<Boolean> {
|
export async function isAvailable(): Promise<Boolean> {
|
||||||
return await exec.exec(`docker`, ['buildx'], true).then(res => {
|
return await exec.exec(`docker`, ['buildx'], true).then(res => {
|
||||||
if (res.stderr != '' && !res.success) {
|
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> {
|
export async function use(builder: string): Promise<void> {
|
||||||
return await exec.exec(`docker`, ['buildx', 'use', '--builder', builder], false).then(res => {
|
return await exec.exec(`docker`, ['buildx', 'use', '--builder', builder], false).then(res => {
|
||||||
if (res.stderr != '' && !res.success) {
|
if (res.stderr != '' && !res.success) {
|
||||||
|
@ -13,12 +13,14 @@ async function run(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const inputs: Inputs = await loadInputs();
|
const inputs: Inputs = await loadInputs();
|
||||||
|
const buildxAvailable = await buildx.isAvailable();
|
||||||
|
const buildxInstalled = buildxAvailable && (await buildx.isInstalled());
|
||||||
|
const buildxEnabled = (await mustBuildx(inputs)) || buildxInstalled;
|
||||||
let buildArgs: Array<string> = [];
|
let buildArgs: Array<string> = [];
|
||||||
const buildxEnabled = await mustBuildx(inputs);
|
|
||||||
|
|
||||||
// Check buildx
|
// Check buildx
|
||||||
if (buildxEnabled) {
|
if (buildxEnabled) {
|
||||||
if (await !buildx.isAvailable()) {
|
if (!buildxAvailable) {
|
||||||
core.setFailed(`Buildx is required but not available`);
|
core.setFailed(`Buildx is required but not available`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user