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

Docker V0 and V1 store build output in temp file #14773

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions Tasks/DockerV0/containerbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,11 @@ export function run(connection: ContainerConnection): any {
context = tl.getPathInput("context");
}
command.arg(context);

command.on("stdout", data => {
let taskOutputPath = utils.writeTaskOutput("build", data);
jcfiorenzano marked this conversation as resolved.
Show resolved Hide resolved
tl.setVariable("DockerOutputPath", taskOutputPath);
});

return connection.execCommand(command);
}
6 changes: 5 additions & 1 deletion Tasks/DockerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 181,
"Minor": 183,
"Patch": 0
},
"demands": [],
Expand Down Expand Up @@ -325,6 +325,10 @@
{
"name": "DockerOutput",
"description": "Stores the output of the docker command"
},
{
"name": "DockerOutputPath",
"description": "The path of the file(s) which contains the output of the build command."
jcfiorenzano marked this conversation as resolved.
Show resolved Hide resolved
}
],
"instanceNameFormat": "$(action)",
Expand Down
6 changes: 5 additions & 1 deletion Tasks/DockerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 181,
"Minor": 183,
"Patch": 0
},
"demands": [],
Expand Down Expand Up @@ -325,6 +325,10 @@
{
"name": "DockerOutput",
"description": "Stores the output of the docker command"
},
{
"name": "DockerOutputPath",
"description": "The path of the file(s) which contains the output of the build command."
}
],
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down
25 changes: 25 additions & 0 deletions Tasks/DockerV0/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import * as fs from "fs";
import ContainerConnection from "azure-pipelines-tasks-docker-common-v2/containerconnection";
import * as sourceUtils from "azure-pipelines-tasks-docker-common-v2/sourceutils";
import * as imageUtils from "azure-pipelines-tasks-docker-common-v2/containerimageutils";
import * as fileutils from "azure-pipelines-tasks-docker-common-v2/fileutils";
import * as path from "path";
import * as os from "os";

export function getImageNames(): string[] {
let imageNamesFilePath = tl.getPathInput("imageNamesPath", /* required */ true, /* check exists */ true);
Expand Down Expand Up @@ -82,6 +85,28 @@ export function getImageMappings(connection: ContainerConnection, imageNames: st
return sourceToTargetMapping;
}


function getTaskOutputDir(command: string): string {
jcfiorenzano marked this conversation as resolved.
Show resolved Hide resolved
let tempDirectory = tl.getVariable('agent.tempDirectory') || os.tmpdir();
let taskOutputDir = path.join(tempDirectory, "task_outputs");
return taskOutputDir;
}

export function writeTaskOutput(commandName: string, output: string): string {
let taskOutputDir = getTaskOutputDir(commandName);
if (!fs.existsSync(taskOutputDir)) {
fs.mkdirSync(taskOutputDir);
}

let outputFileName = commandName + "_" + Date.now() + ".txt";
let taskOutputPath = path.join(taskOutputDir, outputFileName);
if (fileutils.writeFileSync(taskOutputPath, output) == 0) {
tl.warning(tl.loc('NoDataWrittenOnFile', taskOutputPath));
}

return taskOutputPath;
}

interface ImageInfo {
/**
* The original, unmodified, image name provided as input to the task
Expand Down
6 changes: 6 additions & 0 deletions Tasks/DockerV1/containerbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,11 @@ export function run(connection: ContainerConnection): any {
context = tl.getPathInput("buildContext");
}
command.arg(context);

command.on("stdout", data => {
jcfiorenzano marked this conversation as resolved.
Show resolved Hide resolved
let taskOutputPath = utils.writeTaskOutput("build", data);
tl.setVariable("DockerOutputPath", taskOutputPath);
jcfiorenzano marked this conversation as resolved.
Show resolved Hide resolved
});

return connection.execCommand(command);
}
6 changes: 5 additions & 1 deletion Tasks/DockerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 181,
"Minor": 183,
"Patch": 0
},
"demands": [],
Expand Down Expand Up @@ -365,6 +365,10 @@
{
"name": "DockerOutput",
"description": "Stores the output of the docker command"
},
{
"name": "DockerOutputPath",
"description": "The path of the file(s) which contains the output of the build command."
jcfiorenzano marked this conversation as resolved.
Show resolved Hide resolved
}
],
"instanceNameFormat": "$(command)",
Expand Down
6 changes: 5 additions & 1 deletion Tasks/DockerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 181,
"Minor": 183,
"Patch": 0
},
"demands": [],
Expand Down Expand Up @@ -365,6 +365,10 @@
{
"name": "DockerOutput",
"description": "Stores the output of the docker command"
},
{
"name": "DockerOutputPath",
"description": "The path of the file(s) which contains the output of the build command."
}
],
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down
26 changes: 26 additions & 0 deletions Tasks/DockerV1/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import * as fs from "fs";
import ContainerConnection from "azure-pipelines-tasks-docker-common-v2/containerconnection";
import * as sourceUtils from "azure-pipelines-tasks-docker-common-v2/sourceutils";
import * as imageUtils from "azure-pipelines-tasks-docker-common-v2/containerimageutils";
import * as fileutils from "azure-pipelines-tasks-docker-common-v2/fileutils";
import * as path from "path";
import * as os from "os";

export function getImageNames(): string[] {
let imageNamesFilePath = tl.getPathInput("imageNamesPath", /* required */ true, /* check exists */ true);
Expand Down Expand Up @@ -72,6 +75,29 @@ export function getImageMappings(connection: ContainerConnection, imageNames: st
return sourceToTargetMapping;
}


function getTaskOutputDir(command: string): string {
let tempDirectory = tl.getVariable('agent.tempDirectory') || os.tmpdir();
let taskOutputDir = path.join(tempDirectory, "task_outputs");
return taskOutputDir;
}

export function writeTaskOutput(commandName: string, output: string): string {
let taskOutputDir = getTaskOutputDir(commandName);
if (!fs.existsSync(taskOutputDir)) {
fs.mkdirSync(taskOutputDir);
}

let outputFileName = commandName + "_" + Date.now() + ".txt";
let taskOutputPath = path.join(taskOutputDir, outputFileName);
if (fileutils.writeFileSync(taskOutputPath, output) == 0) {
tl.warning(tl.loc('NoDataWrittenOnFile', taskOutputPath));
}

return taskOutputPath;
}


interface ImageInfo {
/**
* The original, unmodified, image name provided as input to the task
Expand Down