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

share the image id that was built V1 #14834

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
30 changes: 30 additions & 0 deletions Tasks/DockerV1/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,34 @@ describe('Docker Suite', function() {
console.log(tr.stderr);
done();
});

it('Docker build should store the id of the image that was built.', (done:Mocha.Done) => {
let tp = path.join(__dirname, 'TestSetup.js');
process.env[shared.TestEnvVars.imageName] = "testuser/standardbuild:11";
process.env[shared.TestEnvVars.command] = shared.CommandTypes.buildImage;
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();

assert(tr.invokedToolCount == 1, 'should have invoked tool one time. actual: ' + tr.invokedToolCount);
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
assert(tr.succeeded, 'task should have succeeded');
assert(tr.stdout.indexOf("set DOCKER_TASK_BUILT_IMAGES=c834e0094587") != -1, "docker build should have stored the image id.")
console.log(tr.stderr);
done();
});

it('Docker build should store the id of the image that was built with builkit.', (done:Mocha.Done) => {
let tp = path.join(__dirname, 'TestSetup.js');
process.env[shared.TestEnvVars.imageName] = "testuser/buildkit:11";
process.env[shared.TestEnvVars.command] = shared.CommandTypes.buildImage;
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();

assert(tr.invokedToolCount == 1, 'should have invoked tool one time. actual: ' + tr.invokedToolCount);
assert(tr.stderr.length == 0 || tr.errorIssues.length, 'should not have written to stderr');
assert(tr.succeeded, 'task should have succeeded');
assert(tr.stdout.indexOf("set DOCKER_TASK_BUILT_IMAGES=6c3ada3eb420") != -1, "docker build should have stored the image id.")
console.log(tr.stderr);
done();
});
});
9 changes: 8 additions & 1 deletion Tasks/DockerV1/Tests/TestSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,14 @@ a.exec[`docker images`] = {
"code": 0,
"stdout": "Listed images successfully."
};

a.exec[`docker build -f ${DockerFilePath} -t testuser/standardbuild:11`] = {
"code": 0,
"stdout": "Successfully built c834e0094587\n Successfully tagged testuser/testrepo:11."
};
a.exec[`docker build -f ${DockerFilePath} -t testuser/buildkit:11`] = {
"code": 0,
"stdout": " => => writing image sha256:6c3ada3eb42094510e0083bba6ae805540e36c96871d7be0c926b2f8cbeea68c\n => => naming to docker.io/library/testuser/buildkit:11"
};
tr.setAnswers(<any>a);

// Create mock for fs module
Expand Down
15 changes: 10 additions & 5 deletions Tasks/DockerV1/containerbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ export function run(connection: ContainerConnection): any {

var dockerfilepath = tl.getInput("dockerFile", true);
let dockerFile = fileUtils.findDockerFile(dockerfilepath);
if(!tl.exist(dockerFile)) {

if (!tl.exist(dockerFile)) {
throw new Error(tl.loc('ContainerDockerFileNotFound', dockerfilepath));
}

command.arg(["-f", dockerFile]);

var addDefaultLabels = tl.getBoolInput("addDefaultLabels");
if (addDefaultLabels) {
if (addDefaultLabels) {
pipelineUtils.addDefaultLabelArgs(command);
}

var commandArguments = dockerCommandUtils.getCommandArguments(tl.getInput("arguments", false));

command.line(commandArguments);
var imageName = utils.getImageName();

var imageName = utils.getImageName();
var qualifyImageName = tl.getBoolInput("qualifyImageName");
if (qualifyImageName) {
imageName = connection.getQualifiedImageNameIfRequired(imageName);
Expand Down Expand Up @@ -75,5 +75,10 @@ export function run(connection: ContainerConnection): any {
return connection.execCommand(command).then(() => {
let taskOutputPath = utils.writeTaskOutput("build", output);
tl.setVariable("DockerOutputPath", taskOutputPath);

const builtImageId = imageUtils.getImageIdFromBuildOutput(output);
if (builtImageId) {
imageUtils.shareBuiltImageId(builtImageId);
}
});
}
29 changes: 25 additions & 4 deletions Tasks/DockerV1/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Tasks/DockerV1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"@types/q": "^1.5.0",
"del": "2.2.0",
"azure-pipelines-task-lib": "^3.0.6-preview.0",
"azure-pipelines-tasks-docker-common-v2": "2.0.1-preview.0",
"azure-pipelines-tasks-docker-common-v2": "2.0.4",
"esprima": "2.7.1",
"js-yaml": "3.6.1"
},
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DockerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 187,
"Patch": 0
"Patch": 1
},
"demands": [],
"releaseNotes": "Simplified the task by:<br/>&nbsp;- Providing an option to simply select or type a command.<br/>&nbsp;- Retaining the useful input fields and providing an option to pass the rest as an argument to the command.",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DockerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 187,
"Patch": 0
"Patch": 1
},
"demands": [],
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down