Skip to content

Commit

Permalink
main: no-op if builder is already set
Browse files Browse the repository at this point in the history
  • Loading branch information
gmichelo committed May 8, 2023
1 parent dc4cf91 commit dc0bc91
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
40 changes: 39 additions & 1 deletion dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4288,6 +4288,23 @@ module.exports = require("util");
/******/ }
/******/
/************************************************************************/
/******/ /* 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 @@ -4311,6 +4328,11 @@ var __webpack_exports__ = {};
// ESM COMPAT FLAG
__nccwpck_require__.r(__webpack_exports__);

// EXPORTS
__nccwpck_require__.d(__webpack_exports__, {
"nscRemoteBuilderName": () => (/* binding */ nscRemoteBuilderName)
});

// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
var core = __nccwpck_require__(186);
// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js
Expand Down Expand Up @@ -4345,6 +4367,7 @@ 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);
Expand All @@ -4362,11 +4385,19 @@ Please add a step this step to your workflow's job definition:
function prepareBuildx() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield core.group(`Check if Namespace Cloud Remote Builder`, () => __awaiter(this, void 0, void 0, function* () {
const builderExists = yield remoteNscBuilderExists();
if (builderExists) {
core.info(`
GitHub runner is already configured to use Namespace Cloud build cluster.`);
return;
}
}));
const sock = tmpFile("buildkit-proxy.sock");
yield core.group(`Proxy Buildkit from Namespace Cloud`, () => __awaiter(this, void 0, void 0, function* () {
yield ensureNscloudToken();
yield exec.exec(`nsc cluster proxy --kind=buildkit --cluster=build-cluster --sock_path=${sock} --background=${ProxyPidFile}`);
yield exec.exec(`docker buildx create --name remote-nsc --driver remote unix://${sock} --use`);
yield exec.exec(`docker buildx create --name ${nscRemoteBuilderName} --driver remote unix://${sock} --use`);
}));
yield core.group(`Builder`, () => __awaiter(this, void 0, void 0, function* () {
core.info("remote-nsc");
Expand All @@ -4391,6 +4422,13 @@ function ensureNscloudToken() {
yield exec.exec("nsc auth exchange-github-token --ensure=5m");
});
}
function remoteNscBuilderExists() {
return __awaiter(this, void 0, void 0, function* () {
const { stdout, stderr } = yield exec.getExecOutput(`docker buildx inspect ${nscRemoteBuilderName}`);
const builderNotFoundStr = `no builder "${nscRemoteBuilderName}" found`;
return !(stdout.includes(builderNotFoundStr) || stderr.includes(builderNotFoundStr));
});
}
run();

})();
Expand Down
19 changes: 18 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as exec from "@actions/exec";
import * as fs from "fs";
import { ProxyPidFile, tmpFile } from "./common";

export const nscRemoteBuilderName = "remote-nsc";

async function run(): Promise<void> {
var commandExists = require("command-exists");

Expand All @@ -19,6 +21,15 @@ Please add a step this step to your workflow's job definition:

async function prepareBuildx(): Promise<void> {
try {
await core.group(`Check if Namespace Cloud Remote Builder`, async () => {
const builderExists = await remoteNscBuilderExists();
if (builderExists) {
core.info(`
GitHub runner is already configured to use Namespace Cloud build cluster.`);
return;
}
});

const sock = tmpFile("buildkit-proxy.sock");

await core.group(`Proxy Buildkit from Namespace Cloud`, async () => {
Expand All @@ -29,7 +40,7 @@ async function prepareBuildx(): Promise<void> {
);

await exec.exec(
`docker buildx create --name remote-nsc --driver remote unix://${sock} --use`
`docker buildx create --name ${nscRemoteBuilderName} --driver remote unix://${sock} --use`
);
});

Expand All @@ -56,4 +67,10 @@ async function ensureNscloudToken() {
await exec.exec("nsc auth exchange-github-token --ensure=5m");
}

async function remoteNscBuilderExists(): Promise<boolean> {
const { stdout, stderr } = await exec.getExecOutput(`docker buildx inspect ${nscRemoteBuilderName}`);
const builderNotFoundStr = `no builder "${nscRemoteBuilderName}" found`;
return !(stdout.includes(builderNotFoundStr) || stderr.includes(builderNotFoundStr))
}

run();

0 comments on commit dc0bc91

Please sign in to comment.