From e9d9885aa879a6d9c4432011e3620dbe44ae4b8f Mon Sep 17 00:00:00 2001 From: Ajinkya Date: Thu, 30 May 2019 12:49:01 +0530 Subject: [PATCH] Use NA as baseImageName in case of only push command. Minor change in debug logs. --- Tasks/Common/docker-common/fileutils.ts | 6 +- .../resources.resjson/en-US/resources.resjson | 1 - Tasks/DockerComposeV0/task.json | 1 - Tasks/DockerComposeV0/task.loc.json | 1 - .../resources.resjson/en-US/resources.resjson | 1 - Tasks/DockerV0/task.json | 1 - Tasks/DockerV0/task.loc.json | 1 - .../resources.resjson/en-US/resources.resjson | 1 - Tasks/DockerV1/task.json | 1 - Tasks/DockerV1/task.loc.json | 1 - .../resources.resjson/en-US/resources.resjson | 1 - Tasks/DockerV2/dockerpush.ts | 61 ++++++++----------- Tasks/DockerV2/task.json | 1 - Tasks/DockerV2/task.loc.json | 1 - Tasks/KubernetesManifestV0/task.json | 2 +- Tasks/KubernetesManifestV0/task.loc.json | 2 +- Tasks/KubernetesV0/task.json | 2 +- Tasks/KubernetesV0/task.loc.json | 2 +- Tasks/KubernetesV1/task.json | 2 +- Tasks/KubernetesV1/task.loc.json | 2 +- 20 files changed, 33 insertions(+), 58 deletions(-) diff --git a/Tasks/Common/docker-common/fileutils.ts b/Tasks/Common/docker-common/fileutils.ts index e5f7ae03abda..f9d66c92c5a6 100644 --- a/Tasks/Common/docker-common/fileutils.ts +++ b/Tasks/Common/docker-common/fileutils.ts @@ -24,7 +24,7 @@ export function writeFileSync(filePath: string, data: string): number { } } -export function findDockerFile(dockerfilepath: string, ensureUnique?: boolean) : string { +export function findDockerFile(dockerfilepath: string) : string { if (dockerfilepath.indexOf('*') >= 0 || dockerfilepath.indexOf('?') >= 0) { tl.debug(tl.loc('ContainerPatternFound')); let workingDirectory = tl.getVariable('System.DefaultWorkingDirectory'); @@ -35,10 +35,6 @@ export function findDockerFile(dockerfilepath: string, ensureUnique?: boolean) : throw new Error(tl.loc('ContainerDockerFileNotFound', dockerfilepath)); } - if (ensureUnique && !(matchingResultsFiles.length == 1)) { - throw new Error(tl.loc('FoundMultipleDockerFiles', dockerfilepath)); - } - return matchingResultsFiles[0]; } else diff --git a/Tasks/DockerComposeV0/Strings/resources.resjson/en-US/resources.resjson b/Tasks/DockerComposeV0/Strings/resources.resjson/en-US/resources.resjson index 0ce8e1d1f8fc..1022b4751fb9 100644 --- a/Tasks/DockerComposeV0/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/DockerComposeV0/Strings/resources.resjson/en-US/resources.resjson @@ -75,7 +75,6 @@ "loc.messages.DockerHostVariableWarning": "DOCKER_HOST variable is set. Please ensure that the Docker daemon is running on: %s", "loc.messages.NoDataWrittenOnFile": "No data was written into the file %s", "loc.messages.FileContentSynced": "Synced the file content to the disk. The content is %s.", - "loc.messages.FoundMultipleDockerFiles": "Found multiple Dockerfiles in the repo, while expected only one.", "loc.messages.ImageNameWithoutTag": "Image name not specified with tag, pushing all tags of the image specified.", "loc.messages.WritingDockerConfigToTempFile": "Writing Docker config to temp file. File path: %s, Docker config: %s" } \ No newline at end of file diff --git a/Tasks/DockerComposeV0/task.json b/Tasks/DockerComposeV0/task.json index 5b12dce1d784..bdd46c73fbf3 100644 --- a/Tasks/DockerComposeV0/task.json +++ b/Tasks/DockerComposeV0/task.json @@ -328,7 +328,6 @@ "DockerHostVariableWarning": "DOCKER_HOST variable is set. Please ensure that the Docker daemon is running on: %s", "NoDataWrittenOnFile": "No data was written into the file %s", "FileContentSynced": "Synced the file content to the disk. The content is %s.", - "FoundMultipleDockerFiles": "Found multiple Dockerfiles in the repo, while expected only one.", "ImageNameWithoutTag": "Image name not specified with tag, pushing all tags of the image specified.", "WritingDockerConfigToTempFile": "Writing Docker config to temp file. File path: %s, Docker config: %s" } diff --git a/Tasks/DockerComposeV0/task.loc.json b/Tasks/DockerComposeV0/task.loc.json index 48985dd1fae5..c9916b04dd6d 100644 --- a/Tasks/DockerComposeV0/task.loc.json +++ b/Tasks/DockerComposeV0/task.loc.json @@ -328,7 +328,6 @@ "DockerHostVariableWarning": "ms-resource:loc.messages.DockerHostVariableWarning", "NoDataWrittenOnFile": "ms-resource:loc.messages.NoDataWrittenOnFile", "FileContentSynced": "ms-resource:loc.messages.FileContentSynced", - "FoundMultipleDockerFiles": "ms-resource:loc.messages.FoundMultipleDockerFiles", "ImageNameWithoutTag": "ms-resource:loc.messages.ImageNameWithoutTag", "WritingDockerConfigToTempFile": "ms-resource:loc.messages.WritingDockerConfigToTempFile" } diff --git a/Tasks/DockerV0/Strings/resources.resjson/en-US/resources.resjson b/Tasks/DockerV0/Strings/resources.resjson/en-US/resources.resjson index a15763d1d34f..16508ecf1920 100644 --- a/Tasks/DockerV0/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/DockerV0/Strings/resources.resjson/en-US/resources.resjson @@ -75,7 +75,6 @@ "loc.messages.CantWriteDataToFile": "Can not write data to the file %s. Error: %s", "loc.messages.NoDataWrittenOnFile": "No data was written into the file %s", "loc.messages.FileContentSynced": "Synced the file content to the disk. The content is %s.", - "loc.messages.FoundMultipleDockerFiles": "Found multiple Dockerfiles in the repo, while expected only one.", "loc.messages.OutputVariableDataSizeExceeded": "Output variable not set as Docker command output exceeded the maximum supported length. Output length: %s, Maximum supported length: %s", "loc.messages.WritingDockerConfigToTempFile": "Writing Docker config to temp file. File path: %s, Docker config: %s" } \ No newline at end of file diff --git a/Tasks/DockerV0/task.json b/Tasks/DockerV0/task.json index 1fc4703957b0..d6c7cef5dd74 100644 --- a/Tasks/DockerV0/task.json +++ b/Tasks/DockerV0/task.json @@ -343,7 +343,6 @@ "CantWriteDataToFile": "Can not write data to the file %s. Error: %s", "NoDataWrittenOnFile": "No data was written into the file %s", "FileContentSynced": "Synced the file content to the disk. The content is %s.", - "FoundMultipleDockerFiles": "Found multiple Dockerfiles in the repo, while expected only one.", "OutputVariableDataSizeExceeded": "Output variable not set as Docker command output exceeded the maximum supported length. Output length: %s, Maximum supported length: %s", "WritingDockerConfigToTempFile": "Writing Docker config to temp file. File path: %s, Docker config: %s" } diff --git a/Tasks/DockerV0/task.loc.json b/Tasks/DockerV0/task.loc.json index 03468c7ab53e..81abc4a47329 100644 --- a/Tasks/DockerV0/task.loc.json +++ b/Tasks/DockerV0/task.loc.json @@ -343,7 +343,6 @@ "CantWriteDataToFile": "ms-resource:loc.messages.CantWriteDataToFile", "NoDataWrittenOnFile": "ms-resource:loc.messages.NoDataWrittenOnFile", "FileContentSynced": "ms-resource:loc.messages.FileContentSynced", - "FoundMultipleDockerFiles": "ms-resource:loc.messages.FoundMultipleDockerFiles", "OutputVariableDataSizeExceeded": "ms-resource:loc.messages.OutputVariableDataSizeExceeded", "WritingDockerConfigToTempFile": "ms-resource:loc.messages.WritingDockerConfigToTempFile" } diff --git a/Tasks/DockerV1/Strings/resources.resjson/en-US/resources.resjson b/Tasks/DockerV1/Strings/resources.resjson/en-US/resources.resjson index 3a96bfb6697f..5066e4ffb945 100644 --- a/Tasks/DockerV1/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/DockerV1/Strings/resources.resjson/en-US/resources.resjson @@ -78,7 +78,6 @@ "loc.messages.CantWriteDataToFile": "Can not write data to the file %s. Error: %s", "loc.messages.NoDataWrittenOnFile": "No data was written into the file %s", "loc.messages.FileContentSynced": "Synced the file content to the disk. The content is %s.", - "loc.messages.FoundMultipleDockerFiles": "Found multiple Dockerfiles in the repo, while expected only one.", "loc.messages.DockerRegistryNotFound": "Docker registry service connection not specified.", "loc.messages.OutputVariableDataSizeExceeded": "Output variable not set as Docker command output exceeded the maximum supported length. Output length: %s, Maximum supported length: %s", "loc.messages.WritingDockerConfigToTempFile": "Writing Docker config to temp file. File path: %s, Docker config: %s" diff --git a/Tasks/DockerV1/task.json b/Tasks/DockerV1/task.json index 30fac98a98e0..bb1553a7eb0b 100644 --- a/Tasks/DockerV1/task.json +++ b/Tasks/DockerV1/task.json @@ -375,7 +375,6 @@ "CantWriteDataToFile": "Can not write data to the file %s. Error: %s", "NoDataWrittenOnFile": "No data was written into the file %s", "FileContentSynced": "Synced the file content to the disk. The content is %s.", - "FoundMultipleDockerFiles": "Found multiple Dockerfiles in the repo, while expected only one.", "DockerRegistryNotFound": "Docker registry service connection not specified.", "OutputVariableDataSizeExceeded": "Output variable not set as Docker command output exceeded the maximum supported length. Output length: %s, Maximum supported length: %s", "WritingDockerConfigToTempFile": "Writing Docker config to temp file. File path: %s, Docker config: %s" diff --git a/Tasks/DockerV1/task.loc.json b/Tasks/DockerV1/task.loc.json index cae4bb347ee9..7370e529684c 100644 --- a/Tasks/DockerV1/task.loc.json +++ b/Tasks/DockerV1/task.loc.json @@ -375,7 +375,6 @@ "CantWriteDataToFile": "ms-resource:loc.messages.CantWriteDataToFile", "NoDataWrittenOnFile": "ms-resource:loc.messages.NoDataWrittenOnFile", "FileContentSynced": "ms-resource:loc.messages.FileContentSynced", - "FoundMultipleDockerFiles": "ms-resource:loc.messages.FoundMultipleDockerFiles", "DockerRegistryNotFound": "ms-resource:loc.messages.DockerRegistryNotFound", "OutputVariableDataSizeExceeded": "ms-resource:loc.messages.OutputVariableDataSizeExceeded", "WritingDockerConfigToTempFile": "ms-resource:loc.messages.WritingDockerConfigToTempFile" diff --git a/Tasks/DockerV2/Strings/resources.resjson/en-US/resources.resjson b/Tasks/DockerV2/Strings/resources.resjson/en-US/resources.resjson index 35030e22d74b..7a55888a799b 100644 --- a/Tasks/DockerV2/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/DockerV2/Strings/resources.resjson/en-US/resources.resjson @@ -35,7 +35,6 @@ "loc.messages.FileContentSynced": "Synced the file content to the disk. The content is %s.", "loc.messages.FoundDockerConfigStoredInTempPath": "Found the Docker Config stored in the temp path. Docker config path: %s, Docker config: %s", "loc.messages.FoundLoginsForOtherRegistries": "Found login info for other registry(s). Trying to remove auth from the Docker config for the registry: %s", - "loc.messages.FoundMultipleDockerFiles": "Found multiple Dockerfiles in the repo, while expected only one.", "loc.messages.IgnoringArgumentsInput": "The arguments input is not supported when the command is buildAndPush. Ignoring the input.", "loc.messages.LoggingOutFromRegistry": "Trying to logout from registry: %s", "loc.messages.LoggingOutWithNoRegistrySpecified": "Logging out. Removing all auth data from temp docker config, since no registry is specified.", diff --git a/Tasks/DockerV2/dockerpush.ts b/Tasks/DockerV2/dockerpush.ts index 24e9da53e8c7..2f4ea4eabfb9 100644 --- a/Tasks/DockerV2/dockerpush.ts +++ b/Tasks/DockerV2/dockerpush.ts @@ -78,21 +78,15 @@ export function run(connection: ContainerConnection, outputUpdate: (data: string const dockerfilepath = tl.getInput("dockerFile", true); let dockerFile = ""; - try { - // If it is only push command, we will use the Dockerfile to get the base image name, - // only if it is inambiguous, i.e., there is only one Dockerfile in the repo. - // For buildAndPush command, we can use the Dockerfile returned by findDockerfile as - // we are sure that this is the one used for building as well. - const ensureUniqueDockerfile = !isBuildAndPushCommand; - dockerFile = findDockerFile(dockerfilepath, ensureUniqueDockerfile); + if (isBuildAndPushCommand) { + // For buildAndPush command, to find out the base image name, we can use the + // Dockerfile returned by findDockerfile as we are sure that this is used + // for building. + dockerFile = findDockerFile(dockerfilepath); if (!tl.exist(dockerFile)) { throw new Error(tl.loc('ContainerDockerFileNotFound', dockerfilepath)); } } - catch (error) { - dockerFile = ""; - tl.debug("Ignoring the error in finding the Dockerfile, as it is not mandatory for push command. Error: " + error); - } // push all tags let output = ""; @@ -105,7 +99,7 @@ export function run(connection: ContainerConnection, outputUpdate: (data: string let digest = extractDigestFromOutput(commandOutput, matchPatternForDigestAndSize); tl.debug("outputImageName: " + outputImageName + "\n" + "commandOutput: " + commandOutput + "\n" + "digest:" + digest + "imageSize:" + imageSize); publishToImageMetadataStore(connection, outputImageName, tags, digest, dockerFile).then((result) => { - tl.debug("ImageDetailsApiResponse: " + result); + tl.debug("ImageDetailsApiResponse: " + JSON.stringify(result)); }, (error) => { tl.warning("publishToImageMetadataStore failed with error: " + error); }); @@ -128,7 +122,7 @@ export function run(connection: ContainerConnection, outputUpdate: (data: string async function publishToImageMetadataStore(connection: ContainerConnection, imageName: string, tags: string[], digest: string, dockerFilePath: string): Promise { // Getting imageDetails const imageUri = getResourceName(imageName, digest); - const baseImageName = dockerFilePath ? getBaseImageNameFromDockerFile(dockerFilePath) : ""; + const baseImageName = dockerFilePath ? getBaseImageNameFromDockerFile(dockerFilePath) : "NA"; const layers = await dockerCommandUtils.getLayers(connection, imageName); const imageSize = dockerCommandUtils.getImageSize(layers); @@ -142,28 +136,25 @@ async function publishToImageMetadataStore(connection: ContainerConnection, imag const jobName = tl.getVariable("System.PhaseDisplayName"); const requestUrl = tl.getVariable("System.TeamFoundationCollectionUri") + tl.getVariable("System.TeamProject") + "/_apis/deployment/imagedetails?api-version=5.0-preview.1"; - let requestBodyJson: any = { - "imageName": imageUri, - "imageUri": imageUri, - "hash": digest, - "distance": 0, - "imageType": "", - "mediaType": "", - "tags": tags, - "layerInfo": layers, - "runId": runId, - "pipelineVersion": pipelineVersion, - "pipelineName": pipelineName, - "pipelineId": pipelineId, - "jobName": jobName, - "imageSize": imageSize - }; - - if (baseImageName) { - requestBodyJson["baseImageName"] = baseImageName; - } - - const requestBody: string = JSON.stringify(requestBodyJson); + const requestBody: string = JSON.stringify( + { + "imageName": imageUri, + "imageUri": imageUri, + "hash": digest, + "baseImageName": baseImageName, + "distance": 0, + "imageType": "", + "mediaType": "", + "tags": tags, + "layerInfo": layers, + "runId": runId, + "pipelineVersion": pipelineVersion, + "pipelineName": pipelineName, + "pipelineId": pipelineId, + "jobName": jobName, + "imageSize": imageSize + } + ); return sendRequestToImageStore(requestBody, requestUrl); } diff --git a/Tasks/DockerV2/task.json b/Tasks/DockerV2/task.json index 4d9e3dad5ed5..f2128480f9c7 100644 --- a/Tasks/DockerV2/task.json +++ b/Tasks/DockerV2/task.json @@ -140,7 +140,6 @@ "FileContentSynced": "Synced the file content to the disk. The content is %s.", "FoundDockerConfigStoredInTempPath": "Found the Docker Config stored in the temp path. Docker config path: %s, Docker config: %s", "FoundLoginsForOtherRegistries": "Found login info for other registry(s). Trying to remove auth from the Docker config for the registry: %s", - "FoundMultipleDockerFiles": "Found multiple Dockerfiles in the repo, while expected only one.", "IgnoringArgumentsInput": "The arguments input is not supported when the command is buildAndPush. Ignoring the input.", "LoggingOutFromRegistry": "Trying to logout from registry: %s", "LoggingOutWithNoRegistrySpecified": "Logging out. Removing all auth data from temp docker config, since no registry is specified.", diff --git a/Tasks/DockerV2/task.loc.json b/Tasks/DockerV2/task.loc.json index f9f0122771e6..bc4456783da2 100644 --- a/Tasks/DockerV2/task.loc.json +++ b/Tasks/DockerV2/task.loc.json @@ -140,7 +140,6 @@ "FileContentSynced": "ms-resource:loc.messages.FileContentSynced", "FoundDockerConfigStoredInTempPath": "ms-resource:loc.messages.FoundDockerConfigStoredInTempPath", "FoundLoginsForOtherRegistries": "ms-resource:loc.messages.FoundLoginsForOtherRegistries", - "FoundMultipleDockerFiles": "ms-resource:loc.messages.FoundMultipleDockerFiles", "IgnoringArgumentsInput": "ms-resource:loc.messages.IgnoringArgumentsInput", "LoggingOutFromRegistry": "ms-resource:loc.messages.LoggingOutFromRegistry", "LoggingOutWithNoRegistrySpecified": "ms-resource:loc.messages.LoggingOutWithNoRegistrySpecified", diff --git a/Tasks/KubernetesManifestV0/task.json b/Tasks/KubernetesManifestV0/task.json index ec04baab4d02..19772b39ee3c 100644 --- a/Tasks/KubernetesManifestV0/task.json +++ b/Tasks/KubernetesManifestV0/task.json @@ -15,7 +15,7 @@ "version": { "Major": 0, "Minor": 153, - "Patch": 0 + "Patch": 1 }, "demands": [], "groups": [], diff --git a/Tasks/KubernetesManifestV0/task.loc.json b/Tasks/KubernetesManifestV0/task.loc.json index d96240378c7d..b5286be7956c 100644 --- a/Tasks/KubernetesManifestV0/task.loc.json +++ b/Tasks/KubernetesManifestV0/task.loc.json @@ -15,7 +15,7 @@ "version": { "Major": 0, "Minor": 153, - "Patch": 0 + "Patch": 1 }, "demands": [], "groups": [], diff --git a/Tasks/KubernetesV0/task.json b/Tasks/KubernetesV0/task.json index 00ae45b99dba..17117e73af2d 100644 --- a/Tasks/KubernetesV0/task.json +++ b/Tasks/KubernetesV0/task.json @@ -14,7 +14,7 @@ "version": { "Major": 0, "Minor": 153, - "Patch": 0 + "Patch": 1 }, "demands": [], "preview": "false", diff --git a/Tasks/KubernetesV0/task.loc.json b/Tasks/KubernetesV0/task.loc.json index 54d92c146483..cbffb26daf09 100644 --- a/Tasks/KubernetesV0/task.loc.json +++ b/Tasks/KubernetesV0/task.loc.json @@ -14,7 +14,7 @@ "version": { "Major": 0, "Minor": 153, - "Patch": 0 + "Patch": 1 }, "demands": [], "preview": "false", diff --git a/Tasks/KubernetesV1/task.json b/Tasks/KubernetesV1/task.json index 4b687eb3737f..5665d0bab97c 100644 --- a/Tasks/KubernetesV1/task.json +++ b/Tasks/KubernetesV1/task.json @@ -14,7 +14,7 @@ "version": { "Major": 1, "Minor": 153, - "Patch": 0 + "Patch": 1 }, "demands": [], "releaseNotes": "What's new in Version 1.0:
 Added new service connection type input for easy selection of Azure AKS cluster.
 Replaced output variable input with output variables section that we had added in all tasks.", diff --git a/Tasks/KubernetesV1/task.loc.json b/Tasks/KubernetesV1/task.loc.json index 7a9d06169557..fe7dce8b8480 100644 --- a/Tasks/KubernetesV1/task.loc.json +++ b/Tasks/KubernetesV1/task.loc.json @@ -14,7 +14,7 @@ "version": { "Major": 1, "Minor": 153, - "Patch": 0 + "Patch": 1 }, "demands": [], "releaseNotes": "ms-resource:loc.releaseNotes",