Skip to content

Commit

Permalink
Respect RUNNER_TEMP environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenvdSchoot authored and svdschoot-wefabricate committed Oct 27, 2023
1 parent 4021c05 commit a3a0940
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion azdo-task/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ In the example above, the devcontainer-build-run will perform the following step
| subFolder | false | Use this to specify the repo-relative path to the folder containing the dev container (i.e. the folder that contains the `.devcontainer` folder). Defaults to repo root |
| runCmd | true | The command to run after building the dev container image |
| env | false | Specify environment variables to pass to the dev container when run |
| push | false | One of: `never`, `filter`, `always`. When set to `filter`, the image is pushed if the `sourceBranchFilterForPush`, `buildReasonsForPush`, and `pushOnFailedBuild` conditions are met. Defaults to `filter` if `imageName` is set, `never` otherwise. |
| push | false | One of: `never`, `filter`, `always`. When set to `filter`, the image if pushed if the `sourceBranchFilterForPush`, `buildReasonsForPush`, and `pushOnFailedBuild` conditions are met. Defaults to `filter` if `imageName` is set, `never` otherwise. |
| pushOnFailedBuild | false | If `false` (default), only push if the build is successful. Set to true to push on failed builds |
| sourceBranchFilterForPush | false | Allows you to limit which branch's builds are pushed to the registry (only specified branches are allowed to push). If empty, all branches are allowed |
| buildReasonsForPush | false | Allows you to limit the Build.Reason values that are allowed to push to the registry. Defaults to Manual, IndividualCI, BatchedCI. See https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&viewFallbackFrom=vsts&tabs=yaml |
Expand Down
12 changes: 8 additions & 4 deletions common/src/dev-container-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ function parseCliOutput<T>(value: string): T | DevContainerCliError {
}
}

function injectTmpdir(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
return {...env, ...{TMPDIR: process.env.RUNNER_TEMP}};
}

async function runSpecCliJsonCommand<T>(options: {
args: string[];
log: (data: string) => void;
Expand All @@ -119,10 +123,10 @@ async function runSpecCliJsonCommand<T>(options: {
const spawnOptions: SpawnOptions = {
log: data => (stdout += data),
err: data => options.log(data),
env: options.env ? {...process.env, ...options.env} : process.env,
env: injectTmpdir(options.env ? {...process.env, ...options.env} : process.env),
};
const command = getSpecCliInfo().command;
console.log(`About to run ${command} ${options.args.join(' ')}`); // TODO - take an output arg to allow GH to use core.info
console.log(`About to run ${command} ${options.args.join(' ')} <with env: ${JSON.stringify(spawnOptions.env)}>`); // TODO - take an output arg to allow GH to use core.info
await spawn(command, options.args, spawnOptions);

return parseCliOutput<T>(stdout);
Expand All @@ -136,10 +140,10 @@ async function runSpecCliNonJsonCommand(options: {
const spawnOptions: SpawnOptions = {
log: data => options.log(data),
err: data => options.log(data),
env: options.env ? {...process.env, ...options.env} : process.env,
env: injectTmpdir(options.env ? {...process.env, ...options.env} : process.env),
};
const command = getSpecCliInfo().command;
console.log(`About to run ${command} ${options.args.join(' ')}`); // TODO - take an output arg to allow GH to use core.info
console.log(`About to run ${command} ${options.args.join(' ')} <with env: ${JSON.stringify(spawnOptions.env)}>`); // TODO - take an output arg to allow GH to use core.info
const result = await spawn(command, options.args, spawnOptions);
return result.code
}
Expand Down
18 changes: 15 additions & 3 deletions common/src/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,21 @@ RUN sudo chown -R ${hostUser.uid}:${hostUser.gid} /home/${containerUserName} \
hostUser.gid
}/
`;
const tempDir = fs.mkdtempSync(
path.join(os.tmpdir(), 'tmp-devcontainer-build-run'),
);
const tempDirBase = (() => {
if(process.env.RUNNER_TEMP !== undefined) {
console.log("RUNNER_TEMP:" + process.env.RUNNER_TEMP);
const r = fs.mkdirSync(process.env.RUNNER_TEMP, {recursive: true})
console.log("mkdir result:" + r);
if(r === process.env.RUNNER_TEMP) {
console.log("Using " + process.env.RUNNER_TEMP + " as tmp dir!");
return process.env.RUNNER_TEMP;
}
} else {
console.warn("RUNNER_TEMP is undefined");
}
return os.tmpdir()
})();
const tempDir = fs.mkdtempSync(path.join(tempDirBase, 'tmp-devcontainer-build-run'));
const derivedDockerfilePath = path.join(tempDir, 'Dockerfile');
fs.writeFileSync(derivedDockerfilePath, dockerfileContent);

Expand Down

0 comments on commit a3a0940

Please sign in to comment.