Skip to content

Commit

Permalink
invoke nsc buildkit buildx cleanup on completion
Browse files Browse the repository at this point in the history
  • Loading branch information
n-g committed May 10, 2023
1 parent 9263066 commit b8cba8c
Show file tree
Hide file tree
Showing 7 changed files with 4,229 additions and 58 deletions.
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ description: "Configure buildx to use the Namespace Cloud build cluster"
runs:
using: node16
main: dist/main/index.js
post: dist/post/index.js
1 change: 1 addition & 0 deletions common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const nscRemoteBuilderName = "remote-nsc";
80 changes: 27 additions & 53 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4288,35 +4288,6 @@ module.exports = require("util");
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __nccwpck_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __nccwpck_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __nccwpck_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
Expand All @@ -4337,16 +4308,19 @@ var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
(() => {
"use strict";
// ESM COMPAT FLAG
__nccwpck_require__.r(__webpack_exports__);
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
/* harmony export */ "nscRemoteBuilderName": () => (/* binding */ nscRemoteBuilderName)
/* harmony export */ });
/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(186);
/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _actions_exec__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(514);
/* harmony import */ var _actions_exec__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__nccwpck_require__.n(_actions_exec__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(147);
/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__nccwpck_require__.n(fs__WEBPACK_IMPORTED_MODULE_2__);

// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
var core = __nccwpck_require__(186);
// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js
var exec = __nccwpck_require__(514);
// EXTERNAL MODULE: external "fs"
var external_fs_ = __nccwpck_require__(147);
;// CONCATENATED MODULE: ./common.ts
const nscRemoteBuilderName = "remote-nsc";

;// CONCATENATED MODULE: ./main.ts
var __awaiter = (undefined && undefined.__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) {
Expand All @@ -4359,14 +4333,14 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume



const nscRemoteBuilderName = "remote-nsc";

function run() {
return __awaiter(this, void 0, void 0, function* () {
var commandExists = __nccwpck_require__(724);
commandExists("nsc")
.then(prepareBuildx)
.catch(function () {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed(`Namespace Cloud CLI not found.
core.setFailed(`Namespace Cloud CLI not found.
Please add a step this step to your workflow's job definition:
Expand All @@ -4377,47 +4351,47 @@ Please add a step this step to your workflow's job definition:
function prepareBuildx() {
return __awaiter(this, void 0, void 0, function* () {
try {
const exists = yield _actions_core__WEBPACK_IMPORTED_MODULE_0__.group(`Ensure Namespace Builder proxy is already configured`, () => __awaiter(this, void 0, void 0, function* () {
const exists = yield core.group(`Ensure Namespace Builder proxy is already configured`, () => __awaiter(this, void 0, void 0, function* () {
const builderExists = yield remoteNscBuilderExists();
if (builderExists) {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`GitHub runner is already configured to use Namespace Cloud build cluster.`);
core.info(`GitHub runner is already configured to use Namespace Cloud build cluster.`);
return true;
}
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Namespace Builder is not yet configured.`);
core.info(`Namespace Builder is not yet configured.`);
return false;
}));
if (!exists) {
yield _actions_core__WEBPACK_IMPORTED_MODULE_0__.group(`Proxy Buildkit from Namespace Cloud`, () => __awaiter(this, void 0, void 0, function* () {
yield core.group(`Proxy Buildkit from Namespace Cloud`, () => __awaiter(this, void 0, void 0, function* () {
yield ensureNscloudToken();
yield _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec(`nsc buildkit setup-buildx --name=${nscRemoteBuilderName} --background --use`);
yield exec.exec(`nsc buildkit buildx setup --name=${nscRemoteBuilderName} --background --use`);
}));
}
yield _actions_core__WEBPACK_IMPORTED_MODULE_0__.group(`Builder`, () => __awaiter(this, void 0, void 0, function* () {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(nscRemoteBuilderName);
yield core.group(`Builder`, () => __awaiter(this, void 0, void 0, function* () {
core.info(nscRemoteBuilderName);
}));
// New line to separate from groups.
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`
core.info(`
Configured buildx to use remote Namespace Cloud build cluster.`);
}
catch (error) {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed(error.message);
core.setFailed(error.message);
}
});
}
function ensureNscloudToken() {
return __awaiter(this, void 0, void 0, function* () {
const tokenFile = "/var/run/nsc/token.json";
if (fs__WEBPACK_IMPORTED_MODULE_2__.existsSync(tokenFile)) {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.exportVariable("NSC_TOKEN_FILE", tokenFile);
if (external_fs_.existsSync(tokenFile)) {
core.exportVariable("NSC_TOKEN_FILE", tokenFile);
return;
}
// We only need a valid token when opening the proxy
yield _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec("nsc auth exchange-github-token --ensure=5m");
yield exec.exec("nsc auth exchange-github-token --ensure=5m");
});
}
function remoteNscBuilderExists() {
return __awaiter(this, void 0, void 0, function* () {
const { stdout, stderr } = yield _actions_exec__WEBPACK_IMPORTED_MODULE_1__.getExecOutput(`docker buildx inspect ${nscRemoteBuilderName}`, null, { ignoreReturnCode: true, silent: true });
const { stdout, stderr } = yield exec.getExecOutput(`docker buildx inspect ${nscRemoteBuilderName}`, null, { ignoreReturnCode: true, silent: true });
const builderNotFoundStr = `no builder "${nscRemoteBuilderName}" found`;
return !(stdout.includes(builderNotFoundStr) || stderr.includes(builderNotFoundStr));
});
Expand Down
Loading

0 comments on commit b8cba8c

Please sign in to comment.