Skip to content

Commit d80d1c6

Browse files
committed
fix artifact file ownership inside container builds
1 parent f67605f commit d80d1c6

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/job.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,12 @@ If you know what you're doing and would like to suppress this warning, use one o
694694
const time = process.hrtime();
695695
this.refreshLongRunningSilentTimeout(writeStreams);
696696

697-
let chownOpt = "0:0";
697+
let this.chownOpt = "0:0";
698698
let chmodOpt = "a+rw";
699699
if (!this.argv.umask) {
700700
const {stdout} = await Utils.spawn([this.argv.containerExecutable, "run", "--rm", "--entrypoint", "sh", imageName, "-c", "echo \"$(id -u):$(id -g)\""]);
701-
chownOpt = stdout;
702-
if (chownOpt == "0:0") {
701+
this.chownOpt = stdout;
702+
if (this.chownOpt == "0:0") {
703703
chmodOpt = "g-w";
704704
}
705705
}
@@ -720,7 +720,7 @@ If you know what you're doing and would like to suppress this warning, use one o
720720
}
721721
}
722722

723-
helperContainerArgs.push(`${helperImageName}`, "sh", "-c", `chown ${chownOpt} -R ${this.ciProjectDir} && chmod ${chmodOpt} -R ${this.ciProjectDir} && chown ${chownOpt} -R /tmp/ && chmod ${chmodOpt} -R /tmp/`);
723+
helperContainerArgs.push(`${helperImageName}`, "sh", "-c", `chown ${this.chownOpt} -R ${this.ciProjectDir} && chmod ${chmodOpt} -R ${this.ciProjectDir} && chown ${this.chownOpt} -R /tmp/ && chmod ${chmodOpt} -R /tmp/`);
724724

725725
const {stdout: containerId} = await Utils.spawn(helperContainerArgs, argv.cwd);
726726
this._containersToClean.push(containerId);
@@ -1336,7 +1336,7 @@ If you know what you're doing and would like to suppress this warning, use one o
13361336
if (!this.imageName(this._variables) && this.argv.shellIsolation) {
13371337
return Utils.spawn(["rsync", "-a", `${source}/.`, `${this.argv.cwd}/${this.argv.stateDir}/builds/${safeJobName}`]);
13381338
}
1339-
return Utils.spawn([this.argv.containerExecutable, "cp", `${source}/.`, `${this._containerId}:${this.ciProjectDir}`]);
1339+
return Utils.spawn(["sh","-c" , `cd ${source}; tar -cf - . --owner ${this.chownOpt.split(":")[0]} --group ${this.chownOpt.split(":")[1]} | ${this.argv.containerExecutable} cp - ${this._containerId}:${this.ciProjectDir}`]);
13401340
}
13411341

13421342
private async copyCacheOut (writeStreams: WriteStreams, expanded: {[key: string]: string}) {

0 commit comments

Comments
 (0)