From ffb0d94f19a63dc5a4a44a79cd7e32dcb4c81cc5 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 16 Apr 2021 15:57:56 +0200 Subject: [PATCH] Remove os limitation Signed-off-by: CrazyMax --- README.md | 5 ----- dist/index.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++--- src/docker.ts | 7 +++++++ src/main.ts | 11 +++++++--- 4 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 src/docker.ts diff --git a/README.md b/README.md index a678746..fffc3c5 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,6 @@ ___ * [Customizing](#customizing) * [inputs](#inputs) * [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot) -* [Limitation](#limitation) ## Usage @@ -82,7 +81,3 @@ updates: schedule: interval: "daily" ``` - -## Limitation - -This action is only available for Linux [virtual environments](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#supported-virtual-environments-and-hardware-resources). diff --git a/dist/index.js b/dist/index.js index f9aa90f..72f7b10 100644 --- a/dist/index.js +++ b/dist/index.js @@ -90,19 +90,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); -const os = __importStar(__webpack_require__(87)); +const docker = __importStar(__webpack_require__(758)); const mexec = __importStar(__webpack_require__(757)); const core = __importStar(__webpack_require__(186)); const exec = __importStar(__webpack_require__(514)); function run() { return __awaiter(this, void 0, void 0, function* () { try { - if (os.platform() !== 'linux') { - core.setFailed('Only supported on linux platform'); + if (!(yield docker.isDaemonRunning())) { + core.setFailed('Cannot connect to the Docker daemon. Is the docker daemon running?'); return; } const image = core.getInput('image') || 'tonistiigi/binfmt:latest'; const platforms = core.getInput('platforms') || 'all'; + core.startGroup(`Docker info`); + yield exec.exec('docker', ['version']); + yield exec.exec('docker', ['info']); + core.endGroup(); core.startGroup(`Pulling binfmt Docker image`); yield exec.exec('docker', ['pull', image]); core.endGroup(); @@ -1582,6 +1586,54 @@ exports.exec = (command, args = [], silent) => __awaiter(void 0, void 0, void 0, /***/ }), +/***/ 758: +/***/ (function(__unusedmodule, exports, __webpack_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isDaemonRunning = void 0; +const exec = __importStar(__webpack_require__(757)); +function isDaemonRunning() { + return __awaiter(this, void 0, void 0, function* () { + return yield exec.exec(`docker`, ['system', 'info'], true).then(res => { + return res.success; + }); + }); +} +exports.isDaemonRunning = isDaemonRunning; +//# sourceMappingURL=docker.js.map + +/***/ }), + /***/ 962: /***/ (function(__unusedmodule, exports, __webpack_require__) { diff --git a/src/docker.ts b/src/docker.ts new file mode 100644 index 0000000..2c232c3 --- /dev/null +++ b/src/docker.ts @@ -0,0 +1,7 @@ +import * as exec from './exec'; + +export async function isDaemonRunning(): Promise { + return await exec.exec(`docker`, ['system', 'info'], true).then(res => { + return res.success; + }); +} diff --git a/src/main.ts b/src/main.ts index 3af5e2b..b4164a9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import * as os from 'os'; +import * as docker from './docker'; import * as mexec from './exec'; import * as core from '@actions/core'; import * as exec from '@actions/exec'; @@ -10,14 +10,19 @@ interface Platforms { async function run(): Promise { try { - if (os.platform() !== 'linux') { - core.setFailed('Only supported on linux platform'); + if (!(await docker.isDaemonRunning())) { + core.setFailed('Cannot connect to the Docker daemon. Is the docker daemon running?'); return; } const image: string = core.getInput('image') || 'tonistiigi/binfmt:latest'; const platforms: string = core.getInput('platforms') || 'all'; + core.startGroup(`Docker info`); + await exec.exec('docker', ['version']); + await exec.exec('docker', ['info']); + core.endGroup(); + core.startGroup(`Pulling binfmt Docker image`); await exec.exec('docker', ['pull', image]); core.endGroup();