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

feat: add --shell-executor option. (#1447). #1481

Merged
merged 1 commit into from
Jan 30, 2025
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
8 changes: 8 additions & 0 deletions src/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export class Argv {
writeStreams?.stderr(chalk`{black.bgYellowBright WARN } --default-image does not work with --shell-executor-no-image=true\n`);
}

if (argv.defaultImageExplicitlySet && argv.forceShellExecutor) {
writeStreams?.stderr(chalk`{black.bgYellowBright WARN } --default-image does not work with --force-shell-executor=true\n`);
}

return argv;
}

Expand Down Expand Up @@ -287,6 +291,10 @@ export class Argv {
return this.map.get("shellExecutorNoImage") ?? true;
}

get forceShellExecutor (): boolean {
return this.map.get("forceShellExecutor") ?? false;
}

get defaultImage (): string {
return this.map.get("defaultImage") ?? "docker.io/ruby:3.1";
}
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ process.on("SIGUSR2", async () => await cleanupJobResources(jobs));
description: "Enable artifact isolation for shell-executor jobs",
requiresArg: false,
})
.option("force-shell-executor", {
type: "boolean",
description: "Forces all jobs to be executed using the shell executor. (Only use this option for trusted job)",
requiresArg: false,
})
.option("shell-executor-no-image", {
type: "boolean",
description: "Whether to use shell executor when no image is specified.",
Expand Down
3 changes: 3 additions & 0 deletions src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,9 @@ export class Job {
}

private imageName (vars: {[key: string]: string} = {}): string | null {
if (this.argv.forceShellExecutor) {
return null;
}
const image = this.jobData["image"];
if (!image) {
if (this.argv.shellExecutorNoImage) {
Expand Down
6 changes: 6 additions & 0 deletions tests/test-cases/force-shell-executor/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
test-job:
image: alpine:latest
stage: test
script:
- echo "Heya from default-image"
45 changes: 45 additions & 0 deletions tests/test-cases/force-shell-executor/integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {WriteStreamsMock} from "../../../src/write-streams.js";
import {handler} from "../../../src/handler.js";

test("force-shell-executor false default-image alpine", async () => {
const writeStreams = new WriteStreamsMock();
await handler({
pullPolicy: "if-not-present",
cwd: "tests/test-cases/force-shell-executor/",
forceShellExecutor: false,
defaultImage: "alpine:latest",
job: ["test-job"],
noColor: true,
}, writeStreams);

expect(writeStreams.stdoutLines.join("\n")).toMatch(/test-job starting alpine:latest \(test\)/);
});

test("force-shell-executor false default-image null but job image alpine", async () => {
const writeStreams = new WriteStreamsMock();
await handler({
pullPolicy: "if-not-present",
cwd: "tests/test-cases/force-shell-executor/",
forceShellExecutor: false,
defaultImage: null,
job: ["test-job"],
noColor: true,
}, writeStreams);

expect(writeStreams.stdoutLines.join("\n")).toMatch(/test-job starting alpine:latest \(test\)/);
});

test("force-shell-executor true default-image doesnt-matter", async () => {
const writeStreams = new WriteStreamsMock();
await handler({
pullPolicy: "if-not-present",
cwd: "tests/test-cases/force-shell-executor/",
forceShellExecutor: true,
defaultImage: "doesnt-matter",
job: ["test-job"],
noColor: true,
}, writeStreams);

expect(writeStreams.stdoutLines.join("\n")).toMatch(/test-job starting shell \(test\)/);
expect(writeStreams.stderrLines.join("\n")).toMatch(/WARN\s\s--default-image does not work with --force-shell-executor=true/);
});
Loading