mirror of
https://github.com/docker/build-push-action.git
synced 2024-12-25 00:02:13 -05: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
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -22,7 +22,7 @@ jobs:
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v2.3.1
|
uses: actions/checkout@v2.3.1
|
||||||
-
|
-
|
||||||
name: Build
|
name: Build and push
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
context: ./test
|
context: ./test
|
||||||
|
@ -68,7 +68,7 @@ jobs:
|
||||||
context: ./test
|
context: ./test
|
||||||
file: ./test/Dockerfile-${{ matrix.dockerfile }}
|
file: ./test/Dockerfile-${{ matrix.dockerfile }}
|
||||||
builder: ${{ steps.buildx.outputs.builder }}
|
builder: ${{ steps.buildx.outputs.builder }}
|
||||||
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x
|
platforms: linux/amd64,linux/arm64,linux/386
|
||||||
#push: true
|
#push: true
|
||||||
tags: |
|
tags: |
|
||||||
localhost:5000/name/app:latest
|
localhost:5000/name/app:latest
|
||||||
|
|
37
dist/index.js
generated
vendored
37
dist/index.js
generated
vendored
|
@ -1114,7 +1114,7 @@ run();
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 231:
|
/***/ 231:
|
||||||
/***/ (function(__unusedmodule, exports) {
|
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
@ -1127,8 +1127,25 @@ 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.parseImage = void 0;
|
exports.parseImage = exports.config = void 0;
|
||||||
|
const path_1 = __importDefault(__webpack_require__(622));
|
||||||
|
const os_1 = __importDefault(__webpack_require__(87));
|
||||||
|
const fs_1 = __importDefault(__webpack_require__(747));
|
||||||
|
function config() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const dockerHome = process.env.DOCKER_CONFIG || path_1.default.join(os_1.default.homedir(), '.docker');
|
||||||
|
const file = path_1.default.join(dockerHome, 'config.json');
|
||||||
|
if (!fs_1.default.existsSync(file)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return JSON.parse(fs_1.default.readFileSync(file, { encoding: 'utf-8' }));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.config = config;
|
||||||
exports.parseImage = (image) => __awaiter(void 0, void 0, void 0, function* () {
|
exports.parseImage = (image) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const match = image.match(/^(?:([^\/]+)\/)?(?:([^\/]+)\/)?([^@:\/]+)(?:[@:](.+))?$/);
|
const match = image.match(/^(?:([^\/]+)\/)?(?:([^\/]+)\/)?([^@:\/]+)(?:[@:](.+))?$/);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
|
@ -1895,14 +1912,9 @@ 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.isInstalled = exports.isAvailable = void 0;
|
exports.use = exports.isInstalled = exports.isAvailable = void 0;
|
||||||
const fs_1 = __importDefault(__webpack_require__(747));
|
const docker = __importStar(__webpack_require__(231));
|
||||||
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* () {
|
||||||
|
@ -1918,13 +1930,8 @@ exports.isAvailable = isAvailable;
|
||||||
function isInstalled() {
|
function isInstalled() {
|
||||||
var _a;
|
var _a;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const dockerHome = process.env.DOCKER_CONFIG || path_1.default.join(os_1.default.homedir(), '.docker');
|
const dockerCfg = yield docker.config();
|
||||||
const dockerCfgFile = path_1.default.join(dockerHome, 'config.json');
|
return ((_a = dockerCfg === null || dockerCfg === void 0 ? void 0 : dockerCfg.aliases) === null || _a === void 0 ? void 0 : _a.builder) == 'buildx';
|
||||||
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;
|
exports.isInstalled = isInstalled;
|
||||||
|
|
|
@ -1,17 +1,6 @@
|
||||||
import fs from 'fs';
|
import * as docker from './docker';
|
||||||
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) {
|
||||||
|
@ -22,15 +11,8 @@ export async function isAvailable(): Promise<Boolean> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function isInstalled(): Promise<Boolean> {
|
export async function isInstalled(): Promise<Boolean> {
|
||||||
const dockerHome: string = process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker');
|
const dockerCfg = await docker.config();
|
||||||
|
return dockerCfg?.aliases?.builder == 'buildx';
|
||||||
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> {
|
||||||
|
|
|
@ -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 {
|
export interface Image {
|
||||||
registry?: string;
|
registry?: string;
|
||||||
namespace?: string;
|
namespace?: string;
|
||||||
|
@ -5,6 +18,17 @@ export interface Image {
|
||||||
tag?: string;
|
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> => {
|
export const parseImage = async (image: string): Promise<Image | undefined> => {
|
||||||
const match = image.match(/^(?:([^\/]+)\/)?(?:([^\/]+)\/)?([^@:\/]+)(?:[@:](.+))?$/);
|
const match = image.match(/^(?:([^\/]+)\/)?(?:([^\/]+)\/)?([^@:\/]+)(?:[@:](.+))?$/);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
|
|
Loading…
Reference in a new issue