From b80dcd6000da216c2504b98cffb19c8674548aca Mon Sep 17 00:00:00 2001 From: Giulio Micheloni Date: Tue, 10 Sep 2024 11:19:02 +0200 Subject: [PATCH] make image loading optional --- action.yml | 5 +++++ dist/main/index.js | 13 +++++++++++-- main.ts | 18 ++++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index e8950c9..3a48e52 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,11 @@ name: '"Configure buildx with Namespace Cloud" Action For GitHub Actions' description: "Configure buildx to use the Namespace Cloud build cluster" +inputs: + load-to-docker: + description: 'Whether to load images to local docker engine' + default: "true" + runs: using: node20 main: dist/main/index.js diff --git a/dist/main/index.js b/dist/main/index.js index f7aa252..9546f3b 100644 --- a/dist/main/index.js +++ b/dist/main/index.js @@ -4365,14 +4365,15 @@ function prepareBuildx() { if (!exists) { yield core.group("Proxy Buildkit from Namespace Cloud", () => __awaiter(this, void 0, void 0, function* () { yield ensureNscloudToken(); + const loadToDockerFlag = parseInputLoadToDocker() ? "--default_load" : ""; const nscRunner = yield isNscRunner(); if (nscRunner) { core.debug("Environment is Namespace Runner"); - yield exec.exec(`nsc docker buildx setup --name=${nscRemoteBuilderName} --background --use --default_load --background_debug_dir=${nscDebugFolder}`); + yield exec.exec(`nsc docker buildx setup --name=${nscRemoteBuilderName} --background --use ${loadToDockerFlag} --background_debug_dir=${nscDebugFolder}`); } else { core.debug("Environment is not Namespace Runner"); - yield exec.exec(`nsc docker buildx setup --name=${nscRemoteBuilderName} --background --use --default_load`); + yield exec.exec(`nsc docker buildx setup --name=${nscRemoteBuilderName} --background --use ${loadToDockerFlag}`); } })); } @@ -4388,6 +4389,14 @@ Configured buildx to use remote Namespace Cloud build cluster.`); } }); } +function parseInputLoadToDocker() { + const loadToDockerString = (core.getInput('load-to-docker') || '').toUpperCase(); + core.debug(`load-to-docker = ${loadToDockerString}`); + if (loadToDockerString === 'TRUE') { + return true; + } + return false; +} function ensureNscloudToken() { return __awaiter(this, void 0, void 0, function* () { const tokenFile = "/var/run/nsc/token.json"; diff --git a/main.ts b/main.ts index 170afbe..7104c97 100644 --- a/main.ts +++ b/main.ts @@ -38,16 +38,17 @@ async function prepareBuildx(): Promise { await core.group("Proxy Buildkit from Namespace Cloud", async () => { await ensureNscloudToken(); + const loadToDockerFlag = parseInputLoadToDocker() ? "--default_load" : ""; const nscRunner = await isNscRunner(); if (nscRunner) { core.debug("Environment is Namespace Runner"); await exec.exec( - `nsc docker buildx setup --name=${nscRemoteBuilderName} --background --use --default_load --background_debug_dir=${nscDebugFolder}` + `nsc docker buildx setup --name=${nscRemoteBuilderName} --background --use ${loadToDockerFlag} --background_debug_dir=${nscDebugFolder}` ); } else { core.debug("Environment is not Namespace Runner"); await exec.exec( - `nsc docker buildx setup --name=${nscRemoteBuilderName} --background --use --default_load` + `nsc docker buildx setup --name=${nscRemoteBuilderName} --background --use ${loadToDockerFlag}` ); } }); @@ -65,6 +66,19 @@ Configured buildx to use remote Namespace Cloud build cluster.`); } } +function parseInputLoadToDocker(): boolean { + const loadToDockerString = ( + core.getInput('load-to-docker') || '' + ).toUpperCase() + + core.debug(`load-to-docker = ${loadToDockerString}`) + + if (loadToDockerString === 'TRUE') { + return true + } + return false +} + async function ensureNscloudToken() { const tokenFile = "/var/run/nsc/token.json"; if (fs.existsSync(tokenFile)) {