From 2fee5c5e7644262333a2bebb7a34d5e7d9c1f002 Mon Sep 17 00:00:00 2001 From: Juan Fiorenzano Date: Wed, 12 May 2021 10:01:23 -0700 Subject: [PATCH] change where we add the base image labels --- Tasks/DockerV1/Tests/L0.ts | 20 ++++++++++---------- Tasks/DockerV1/Tests/TestSetup.ts | 20 ++++++++++---------- Tasks/DockerV1/containerbuild.ts | 14 +++++++------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Tasks/DockerV1/Tests/L0.ts b/Tasks/DockerV1/Tests/L0.ts index e79589bfcba4..4cc23af6e7a4 100644 --- a/Tasks/DockerV1/Tests/L0.ts +++ b/Tasks/DockerV1/Tests/L0.ts @@ -39,7 +39,7 @@ describe('Docker Suite', function() { assert(tr.invokedToolCount == 1, 'should have invoked tool one times. 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(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} -t test/test:2`) != -1, "docker build should run"); + assert(tr.stdout.indexOf(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} ${shared.DockerCommandArgs.BuildLabels} -t test/test:2`) != -1, "docker build should run"); console.log(tr.stderr); done(); }); @@ -55,7 +55,7 @@ describe('Docker Suite', function() { assert(tr.invokedToolCount == 1, 'should have invoked tool one times. 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(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} -t test/test:2 -m 2GB`) != -1, "docker build should run"); + assert(tr.stdout.indexOf(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} ${shared.DockerCommandArgs.BuildLabels} -t test/test:2 -m 2GB`) != -1, "docker build should run"); console.log(tr.stderr); done(); }); @@ -72,7 +72,7 @@ describe('Docker Suite', function() { assert(tr.invokedToolCount == 1, 'should have invoked tool one times. 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(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} -t test/test:2`) != -1, "docker build should run"); + assert(tr.stdout.indexOf(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} ${shared.DockerCommandArgs.BuildLabels} -t test/test:2`) != -1, "docker build should run"); console.log(tr.stderr); done(); }); @@ -106,7 +106,7 @@ describe('Docker Suite', function() { assert(tr.invokedToolCount == 1, 'should have invoked tool one times. 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(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} -t test/test:2`) != -1, "docker build should run"); + assert(tr.stdout.indexOf(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} ${shared.DockerCommandArgs.BuildLabels} -t test/test:2`) != -1, "docker build should run"); console.log(tr.stderr); done(); }); @@ -123,7 +123,7 @@ describe('Docker Suite', function() { assert(tr.invokedToolCount == 1, 'should have invoked tool one times. 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(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} -t test/test:2 -t test/test`) != -1, "docker build should run"); + assert(tr.stdout.indexOf(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} ${shared.DockerCommandArgs.BuildLabels} -t test/test:2 -t test/test`) != -1, "docker build should run"); console.log(tr.stderr); done(); }); @@ -139,7 +139,7 @@ describe('Docker Suite', function() { assert(tr.invokedToolCount == 1, 'should have invoked tool one times. 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(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} -t test:testtag -t test/test:2`) != -1, "docker build should run"); + assert(tr.stdout.indexOf(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} ${shared.DockerCommandArgs.BuildLabels} -t test:testtag -t test/test:2`) != -1, "docker build should run"); console.log(tr.stderr); done(); }); @@ -155,7 +155,7 @@ describe('Docker Suite', function() { assert(tr.invokedToolCount == 1, 'should have invoked tool one times. 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(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} -t test:tag1 -t test:tag2 -t test:tag3 -t test/test:2`) != -1, "docker build should run with correct arguments"); + assert(tr.stdout.indexOf(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} ${shared.DockerCommandArgs.BuildLabels} -t test:tag1 -t test:tag2 -t test:tag3 -t test/test:2`) != -1, "docker build should run with correct arguments"); console.log(tr.stderr); done(); }); @@ -370,7 +370,7 @@ describe('Docker Suite', function() { assert(tr.invokedToolCount == 1, 'should have invoked tool one times. 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(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} -t test/test:2`) != -1, "docker build should run"); + assert(tr.stdout.indexOf(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} ${shared.DockerCommandArgs.BuildLabels} -t test/test:2`) != -1, "docker build should run"); console.log(tr.stderr); done(); }); @@ -389,7 +389,7 @@ describe('Docker Suite', function() { assert(tr.invokedToolCount == 1, 'should have invoked tool one times. 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(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} -t ajgtestacr1.azurecr.io/test/test:2`) != -1, "docker build should run"); + assert(tr.stdout.indexOf(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} ${shared.DockerCommandArgs.BuildLabels} -t ajgtestacr1.azurecr.io/test/test:2`) != -1, "docker build should run"); console.log(tr.stderr); done(); }); @@ -417,7 +417,7 @@ describe('Docker Suite', function() { assert(tr.invokedToolCount == 3, 'should have invoked tool three 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(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} -t testuser/imagewithannotations:11 ${shared.DockerCommandArgs.BuildLabels} --label ${shared.BaseImageLabels.name} --label ${shared.BaseImageLabels.digest}`) != -1, "docker build should run"); + assert(tr.stdout.indexOf(`[command]docker build -f ${shared.formatPath("dir1/DockerFile")} ${shared.DockerCommandArgs.BuildLabels} --label ${shared.BaseImageLabels.name} --label ${shared.BaseImageLabels.digest} -t testuser/imagewithannotations:11`) != -1, "docker build should run"); console.log(tr.stderr); done(); }); diff --git a/Tasks/DockerV1/Tests/TestSetup.ts b/Tasks/DockerV1/Tests/TestSetup.ts index 3ac450d63afa..224838b1c1b3 100644 --- a/Tasks/DockerV1/Tests/TestSetup.ts +++ b/Tasks/DockerV1/Tests/TestSetup.ts @@ -81,27 +81,27 @@ let a = { // Add extra answer definitions that need to be dynamically generated a.exist[DockerFilePath] = true; -a.exec[`docker build -f ${DockerFilePath} -t test/test:2 ${shared.DockerCommandArgs.BuildLabels}`] = { +a.exec[`docker build -f ${DockerFilePath} ${shared.DockerCommandArgs.BuildLabels} -t test/test:2`] = { "code": 0, "stdout": "successfully build test/test:2 image" }; -a.exec[`docker build -f ${DockerFilePath} -t test/test:2 -m 2GB ${shared.DockerCommandArgs.BuildLabels}`] = { +a.exec[`docker build -f ${DockerFilePath} ${shared.DockerCommandArgs.BuildLabels} -t test/test:2 -m 2GB`] = { "code": 0, "stdout": "successfully build test/test:2 image" }; -a.exec[`docker build -f ${DockerFilePath} -t test/Te st:2 ${shared.DockerCommandArgs.BuildLabels}`] = { +a.exec[`docker build -f ${DockerFilePath} ${shared.DockerCommandArgs.BuildLabels} -t test/Te st:2`] = { "code": 1, "stdout": "test/Te st:2 not valid imagename" }; -a.exec[`docker build -f ${DockerFilePath} -t test/test:2 -t test/test ${shared.DockerCommandArgs.BuildLabels}`] = { +a.exec[`docker build -f ${DockerFilePath} ${shared.DockerCommandArgs.BuildLabels} -t test/test:2 -t test/test`] = { "code": 0, "stdout": "successfully build test/test image with latest tag" }; -a.exec[`docker build -f ${DockerFilePath} -t ajgtestacr1.azurecr.io/test/test:2 ${shared.DockerCommandArgs.BuildLabels}`] = { +a.exec[`docker build -f ${DockerFilePath} ${shared.DockerCommandArgs.BuildLabels} -t ajgtestacr1.azurecr.io/test/test:2`] = { "code": 0, "stdout": "successfully build ajgtestacr1.azurecr.io/test/test image with latest tag" }; -a.exec[`docker build -f ${DockerFilePath} -t ${shared.ImageNamesFileImageName} ${shared.DockerCommandArgs.BuildLabels}`] = { +a.exec[`docker build -f ${DockerFilePath} ${shared.DockerCommandArgs.BuildLabels} -t ${shared.ImageNamesFileImageName}`] = { "code": 0 }; a.exec[`docker tag test/test:2 ajgtestacr1.azurecr.io/test/test:2`] = { @@ -125,15 +125,15 @@ a.exec[`docker run --rm ${shared.ImageNamesFileImageName}`] = { a.exec[`docker push ${shared.ImageNamesFileImageName}`] = { "code": 0 }; -a.exec[`docker build -f ${DockerFilePath} -t test/test:2 -t test/test:6 ${shared.DockerCommandArgs.BuildLabels}`] = { +a.exec[`docker build -f ${DockerFilePath} ${shared.DockerCommandArgs.BuildLabels} -t test/test:2 -t test/test:6`] = { "code": 0, "stdout": "successfully build test/test:2 and test/test:6 image" }; -a.exec[`docker build -f ${DockerFilePath} -t test:testtag -t test/test:2 ${shared.DockerCommandArgs.BuildLabels}`] = { +a.exec[`docker build -f ${DockerFilePath} ${shared.DockerCommandArgs.BuildLabels} -t test:testtag -t test/test:2`] = { "code": 0, "stdout": "successfully build test/test:2 and -t test:testtag image" }; -a.exec[`docker build -f ${DockerFilePath} -t test:tag1 -t test:tag2 -t test:tag3 -t test/test:2 ${shared.DockerCommandArgs.BuildLabels}`] = { +a.exec[`docker build -f ${DockerFilePath} ${shared.DockerCommandArgs.BuildLabels} -t test:tag1 -t test:tag2 -t test:tag3 -t test/test:2`] = { "code": 0, "stdout": "successfully built and tagged test/test:2, test:tag1, test:tag2 and test:tag3" }; @@ -156,7 +156,7 @@ a.exec[`docker images`] = { "code": 0, "stdout": "Listed images successfully." }; -a.exec[`docker build -f ${DockerFilePath} -t testuser/imagewithannotations:11 ${shared.DockerCommandArgs.BuildLabels} --label ${shared.BaseImageLabels.name} --label ${shared.BaseImageLabels.digest}`] = { +a.exec[`docker build -f ${DockerFilePath} ${shared.DockerCommandArgs.BuildLabels} --label ${shared.BaseImageLabels.name} --label ${shared.BaseImageLabels.digest} -t testuser/imagewithannotations:11`] = { "code": 0, "stdout": "successfully built image and tagged testuser/imagewithannotations:11." }; diff --git a/Tasks/DockerV1/containerbuild.ts b/Tasks/DockerV1/containerbuild.ts index f75582a76504..d6d0ee2afb59 100644 --- a/Tasks/DockerV1/containerbuild.ts +++ b/Tasks/DockerV1/containerbuild.ts @@ -29,6 +29,13 @@ export function run(connection: ContainerConnection): any { pipelineUtils.addDefaultLabelArgs(command); } + const addBaseImageInfo = tl.getBoolInput("addBaseImageData"); + const labelsArgument = pipelineUtils.getDefaultLabels(false, addBaseImageInfo, dockerFile, connection); + + labelsArgument.forEach(label => { + command.arg(["--label", label]); + }); + var commandArguments = dockerCommandUtils.getCommandArguments(tl.getInput("arguments", false)); command.line(commandArguments); @@ -59,13 +66,6 @@ export function run(connection: ContainerConnection): any { command.arg(["-m", memoryLimit]); } - const addBaseImageInfo = tl.getBoolInput("addBaseImageData"); - const labelsArgument = pipelineUtils.getDefaultLabels(false, addBaseImageInfo, dockerFile, connection); - - labelsArgument.forEach(label => { - command.arg(["--label", label]); - }); - var context: string; var useDefaultContext = tl.getBoolInput("useDefaultContext"); if (useDefaultContext) {