Skip to content

Commit

Permalink
auth: use token.spec for authN file if exist locally (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
edganiukov authored Apr 3, 2023
1 parent 3ff4313 commit 16ba436
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
20 changes: 16 additions & 4 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4315,10 +4315,10 @@ __nccwpck_require__.r(__webpack_exports__);
var core = __nccwpck_require__(186);
// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js
var exec = __nccwpck_require__(514);
// EXTERNAL MODULE: external "path"
var external_path_ = __nccwpck_require__(17);
// EXTERNAL MODULE: external "fs"
var external_fs_ = __nccwpck_require__(147);
// EXTERNAL MODULE: external "path"
var external_path_ = __nccwpck_require__(17);
;// CONCATENATED MODULE: ./common.ts


Expand All @@ -4344,6 +4344,7 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume




function run() {
return __awaiter(this, void 0, void 0, function* () {
var commandExists = __nccwpck_require__(724);
Expand All @@ -4363,8 +4364,7 @@ function prepareBuildx() {
try {
const sock = tmpFile("buildkit-proxy.sock");
yield core.group(`Proxy Buildkit from Namespace Cloud`, () => __awaiter(this, void 0, void 0, function* () {
// We only need a valid token when opening the proxy
yield exec.exec("nsc auth exchange-github-token --ensure=5m");
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`);
}));
Expand All @@ -4380,6 +4380,18 @@ Configured buildx to use remote Namespace Cloud build cluster.`);
}
});
}
function ensureNscloudToken() {
return __awaiter(this, void 0, void 0, function* () {
const tokenSpecFile = "/var/run/nsc/token.spec";
if (external_fs_.existsSync(tokenSpecFile)) {
const tokenSpec = external_fs_.readFileSync(tokenSpecFile, "utf8");
core.exportVariable("NSC_TOKEN_SPEC", tokenSpec);
return;
}
// We only need a valid token when opening the proxy
yield exec.exec("nsc auth exchange-github-token --ensure=5m");
});
}
run();

})();
Expand Down
16 changes: 14 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as fs from "fs";
import { ProxyPidFile, tmpFile } from "./common";

async function run(): Promise<void> {
Expand All @@ -21,8 +22,7 @@ async function prepareBuildx(): Promise<void> {
const sock = tmpFile("buildkit-proxy.sock");

await core.group(`Proxy Buildkit from Namespace Cloud`, async () => {
// We only need a valid token when opening the proxy
await exec.exec("nsc auth exchange-github-token --ensure=5m");
await ensureNscloudToken();

await exec.exec(
`nsc cluster proxy --kind=buildkit --cluster=build-cluster --sock_path=${sock} --background=${ProxyPidFile}`
Expand All @@ -45,4 +45,16 @@ Configured buildx to use remote Namespace Cloud build cluster.`);
}
}

async function ensureNscloudToken() {
const tokenSpecFile = "/var/run/nsc/token.spec";
if (fs.existsSync(tokenSpecFile)) {
const tokenSpec = fs.readFileSync(tokenSpecFile, "utf8");
core.exportVariable("NSC_TOKEN_SPEC", tokenSpec);
return
}

// We only need a valid token when opening the proxy
await exec.exec("nsc auth exchange-github-token --ensure=5m");
}

run();

0 comments on commit 16ba436

Please sign in to comment.