Skip to content

Commit

Permalink
Merge pull request #5 from namespacelabs/make-load-optional
Browse files Browse the repository at this point in the history
make image loading optional
  • Loading branch information
gmichelo authored Sep 10, 2024
2 parents 534cf4d + b80dcd6 commit 84ca8c5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 11 additions & 2 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}));
}
Expand All @@ -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";
Expand Down
18 changes: 16 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ async function prepareBuildx(): Promise<void> {
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}`
);
}
});
Expand All @@ -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)) {
Expand Down

0 comments on commit 84ca8c5

Please sign in to comment.