Skip to content

Commit

Permalink
Use NA as baseImageName in case of only push command. Minor change in…
Browse files Browse the repository at this point in the history
… debug logs.
  • Loading branch information
ajinkya599 committed May 30, 2019
1 parent 38e6d81 commit e9d9885
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 58 deletions.
6 changes: 1 addition & 5 deletions Tasks/Common/docker-common/fileutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
1 change: 0 additions & 1 deletion Tasks/DockerComposeV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
1 change: 0 additions & 1 deletion Tasks/DockerComposeV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
1 change: 0 additions & 1 deletion Tasks/DockerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
1 change: 0 additions & 1 deletion Tasks/DockerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion Tasks/DockerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion Tasks/DockerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
61 changes: 26 additions & 35 deletions Tasks/DockerV2/dockerpush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand All @@ -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);
});
Expand All @@ -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<any> {
// 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);

Expand All @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion Tasks/DockerV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 0 additions & 1 deletion Tasks/DockerV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/KubernetesManifestV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 0,
"Minor": 153,
"Patch": 0
"Patch": 1
},
"demands": [],
"groups": [],
Expand Down
2 changes: 1 addition & 1 deletion Tasks/KubernetesManifestV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 0,
"Minor": 153,
"Patch": 0
"Patch": 1
},
"demands": [],
"groups": [],
Expand Down
2 changes: 1 addition & 1 deletion Tasks/KubernetesV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 153,
"Patch": 0
"Patch": 1
},
"demands": [],
"preview": "false",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/KubernetesV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 0,
"Minor": 153,
"Patch": 0
"Patch": 1
},
"demands": [],
"preview": "false",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/KubernetesV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 153,
"Patch": 0
"Patch": 1
},
"demands": [],
"releaseNotes": "What's new in Version 1.0:<br/>&nbsp;Added new service connection type input for easy selection of Azure AKS cluster.<br/>&nbsp;Replaced output variable input with output variables section that we had added in all tasks.",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/KubernetesV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 153,
"Patch": 0
"Patch": 1
},
"demands": [],
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down

0 comments on commit e9d9885

Please sign in to comment.