Skip to content

Commit 4347267

Browse files
authored
feat: add option to set custom helper image (#1544)
1 parent 530c186 commit 4347267

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/argv.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ export class Argv {
318318
return this.map.get("defaultImage") ?? "docker.io/ruby:3.1";
319319
}
320320

321+
get helperImage (): string {
322+
return this.map.get("helperImage") ?? "docker.io/firecow/gitlab-ci-local-util:latest";
323+
}
324+
321325
get defaultImageExplicitlySet (): boolean {
322326
return this.map.get("defaultImage") ?? false;
323327
}

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ process.on("SIGUSR2", async () => await cleanupJobResources(jobs));
187187
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.",
188188
requiresArg: false,
189189
})
190+
.option("helper-image", {
191+
type: "string",
192+
description: "When using --shell-executor-no-image=false which image to be used for the utils container. Defaults to docker.io/firecow/gitlab-ci-local-util:latest if not set.",
193+
requiresArg: false,
194+
})
190195
.option("mount-cache", {
191196
type: "boolean",
192197
description: "Enable docker mount based caching",

src/job.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ export class Job {
575575
this._dotenvVariables = await this.initProducerReportsDotenvVariables(writeStreams, Utils.expandVariables(this._variables));
576576
const expanded = Utils.unscape$$Variables(Utils.expandVariables({...this._variables, ...this._dotenvVariables}));
577577
const imageName = this.imageName(expanded);
578+
const helperImageName = argv.helperImage;
578579
const safeJobName = this.safeJobName;
579580

580581
const outputLogFilePath = `${argv.cwd}/${argv.stateDir}/output/${safeJobName}.log`;
@@ -611,8 +612,11 @@ export class Job {
611612
chmodOpt = "g-w";
612613
}
613614
}
615+
if (helperImageName) {
616+
await this.pullImage(writeStreams, helperImageName);
617+
}
614618
const {stdout: containerId} = await Utils.spawn([
615-
this.argv.containerExecutable, "create", "--user=0:0", `--volume=${buildVolumeName}:${this.ciProjectDir}`, `--volume=${tmpVolumeName}:${this.fileVariablesDir}`, "docker.io/firecow/gitlab-ci-local-util",
619+
this.argv.containerExecutable, "create", "--user=0:0", `--volume=${buildVolumeName}:${this.ciProjectDir}`, `--volume=${tmpVolumeName}:${this.fileVariablesDir}`, `${helperImageName}`,
616620
...["sh", "-c", `chown ${chownOpt} -R ${this.ciProjectDir} && chmod ${chmodOpt} -R ${this.ciProjectDir} && chown ${chownOpt} -R /tmp/ && chmod ${chmodOpt} -R /tmp/`],
617621
], argv.cwd);
618622
this._containersToClean.push(containerId);
@@ -1278,11 +1282,12 @@ export class Job {
12781282
const safeJobName = this.safeJobName;
12791283
const buildVolumeName = this.buildVolumeName;
12801284
const cwd = this.argv.cwd;
1285+
const helperImageName = this.argv.helperImage;
12811286

12821287
await fs.mkdirp(`${cwd}/${stateDir}/${type}`);
12831288

12841289
if (this.imageName(this._variables)) {
1285-
const {stdout: containerId} = await Utils.bash(`${this.argv.containerExecutable} create -i ${dockerCmdExtras.join(" ")} -v ${buildVolumeName}:${this.ciProjectDir} -w ${this.ciProjectDir} docker.io/firecow/gitlab-ci-local-util bash -c "${cmd}"`, cwd);
1290+
const {stdout: containerId} = await Utils.bash(`${this.argv.containerExecutable} create -i ${dockerCmdExtras.join(" ")} -v ${buildVolumeName}:${this.ciProjectDir} -w ${this.ciProjectDir} ${helperImageName} bash -c "${cmd}"`, cwd);
12861291
this._containersToClean.push(containerId);
12871292
await Utils.spawn([this.argv.containerExecutable, "start", containerId, "--attach"]);
12881293
await Utils.spawn([this.argv.containerExecutable, "cp", `${containerId}:/${type}/.`, `${stateDir}/${type}/.`], cwd);

0 commit comments

Comments
 (0)