Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make image loading optional #5

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading