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

Added --default-image option to be used with --shell-executor-no-image=false #1397

Merged
merged 3 commits into from
Nov 14, 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
17 changes: 17 additions & 0 deletions src/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ export class Argv {
if (!argv.shellExecutorNoImage && argv.shellIsolation) {
writeStreams?.stderr(chalk`{black.bgYellowBright WARN } --shell-isolation does not work with --no-shell-executor-no-image\n`);
}

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

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

return argv;
}

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

get defaultImage (): string {
return this.map.get("defaultImage") ?? "docker.io/ruby:3.1";
}

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

get maximumIncludes (): number {
return this.map.get("maximumIncludes") ?? 150; // https://docs.gitlab.com/ee/administration/settings/continuous_integration.html#maximum-includes
}
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: "Whether to use shell executor when no image is specified.",
requiresArg: false,
})
.option("default-image", {
type: "string",
description: "When using --shell-executor-no-image=false which image to be used for the container. Defaults to docker.io/ruby:3.1 if not set.",
requiresArg: false,
})
.option("mount-cache", {
type: "boolean",
description: "Enable docker mount based caching",
Expand Down
2 changes: 1 addition & 1 deletion src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ export class Job {
return null;
} else {
// https://docs.gitlab.com/ee/ci/runners/hosted_runners/linux.html#container-images
return "docker.io/ruby:3.1";
return this.argv.defaultImage;
}
}
const expanded = Utils.expandVariables(vars);
Expand Down
5 changes: 5 additions & 0 deletions tests/test-cases/shell-executor-no-image/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
test-job:
stage: test
script:
- echo "Heya from default-image"
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("shell-executor-no-image false default-image alpine", async () => {
const writeStreams = new WriteStreamsMock();
await handler({
pullPolicy: "if-not-present",
cwd: "tests/test-cases/shell-executor-no-image/",
shellExecutorNoImage: false,
defaultImage: "alpine:latest",
job: ["test-job"],
noColor: true,
}, writeStreams);

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

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

expect(writeStreams.stdoutLines.join("\n")).toMatch(/test-job starting docker.io\/ruby:3.1 \(test\)/);
});

test("shell-executor-no-image true default-image doesnt-matter", async () => {
const writeStreams = new WriteStreamsMock();
await handler({
pullPolicy: "if-not-present",
cwd: "tests/test-cases/shell-executor-no-image/",
shellExecutorNoImage: 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 --shell-executor-no-image=true/);
});