diff --git a/Tasks/Common/docker-common/containerconnection.ts b/Tasks/Common/docker-common/containerconnection.ts index 552370afd3c2..8314b92d19f7 100644 --- a/Tasks/Common/docker-common/containerconnection.ts +++ b/Tasks/Common/docker-common/containerconnection.ts @@ -71,22 +71,26 @@ export default class ContainerConnection { return imageName; } - public getQualifiedImageName(repository: string): string { + public getQualifiedImageName(repository: string, enforceDockerNamingConvention?: boolean): string { let imageName = repository ? repository : ""; if (repository && this.registryAuth) { imageName = this.prefixRegistryIfRequired(this.registryAuth["registry"], repository); } - return imageName; + return enforceDockerNamingConvention ? imageUtils.generateValidImageName(imageName) : imageName; } - public getQualifiedImageNamesFromConfig(repository: string) { + public getQualifiedImageNamesFromConfig(repository: string, enforceDockerNamingConvention?: boolean) { let imageNames: string[] = []; if (repository) { let regUrls = this.getRegistryUrlsFromDockerConfig(); if (regUrls && regUrls.length > 0) { regUrls.forEach(regUrl => { let imageName = this.prefixRegistryIfRequired(regUrl, repository); + if (enforceDockerNamingConvention) { + imageName = imageUtils.generateValidImageName(imageName); + } + imageNames.push(imageName); }); } diff --git a/Tasks/Common/docker-common/fileutils.ts b/Tasks/Common/docker-common/fileutils.ts index 8416f17ef075..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) : 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'); diff --git a/Tasks/DockerComposeV0/task.json b/Tasks/DockerComposeV0/task.json index 3e31202dd8e5..a88cbc27164e 100644 --- a/Tasks/DockerComposeV0/task.json +++ b/Tasks/DockerComposeV0/task.json @@ -14,7 +14,7 @@ "version": { "Major": 0, "Minor": 153, - "Patch": 4 + "Patch": 5 }, "demands": [], "preview": "false", diff --git a/Tasks/DockerComposeV0/task.loc.json b/Tasks/DockerComposeV0/task.loc.json index fb4ebe489d48..5daee7436523 100644 --- a/Tasks/DockerComposeV0/task.loc.json +++ b/Tasks/DockerComposeV0/task.loc.json @@ -14,7 +14,7 @@ "version": { "Major": 0, "Minor": 153, - "Patch": 4 + "Patch": 5 }, "demands": [], "preview": "false", diff --git a/Tasks/DockerV0/task.json b/Tasks/DockerV0/task.json index e578dae9f940..3feedb86455c 100644 --- a/Tasks/DockerV0/task.json +++ b/Tasks/DockerV0/task.json @@ -14,7 +14,7 @@ "version": { "Major": 0, "Minor": 153, - "Patch": 4 + "Patch": 5 }, "demands": [], "preview": "false", diff --git a/Tasks/DockerV0/task.loc.json b/Tasks/DockerV0/task.loc.json index 18ba485b7b73..7ace303c53d3 100644 --- a/Tasks/DockerV0/task.loc.json +++ b/Tasks/DockerV0/task.loc.json @@ -14,7 +14,7 @@ "version": { "Major": 0, "Minor": 153, - "Patch": 4 + "Patch": 5 }, "demands": [], "preview": "false", diff --git a/Tasks/DockerV1/task.json b/Tasks/DockerV1/task.json index 437ac5e440b2..2e840d9960ce 100644 --- a/Tasks/DockerV1/task.json +++ b/Tasks/DockerV1/task.json @@ -14,7 +14,7 @@ "version": { "Major": 1, "Minor": 153, - "Patch": 4 + "Patch": 5 }, "demands": [], "releaseNotes": "Simplified the task by:
 - Providing an option to simply select or type a command.
 - Retaining the useful input fields and providing an option to pass the rest as an argument to the command.", diff --git a/Tasks/DockerV1/task.loc.json b/Tasks/DockerV1/task.loc.json index 1406218be326..1dacfeb113b3 100644 --- a/Tasks/DockerV1/task.loc.json +++ b/Tasks/DockerV1/task.loc.json @@ -14,7 +14,7 @@ "version": { "Major": 1, "Minor": 153, - "Patch": 4 + "Patch": 5 }, "demands": [], "releaseNotes": "ms-resource:loc.releaseNotes", diff --git a/Tasks/DockerV2/dockerbuild.ts b/Tasks/DockerV2/dockerbuild.ts index 38316cd31441..adff5064330c 100644 --- a/Tasks/DockerV2/dockerbuild.ts +++ b/Tasks/DockerV2/dockerbuild.ts @@ -15,7 +15,7 @@ function useDefaultBuildContext(buildContext: string): boolean { return buildContext === defaultPath; } -export function run(connection: ContainerConnection, outputUpdate: (data: string) => any, ignoreArguments?: boolean): any { +export function run(connection: ContainerConnection, outputUpdate: (data: string) => any, isBuildAndPushCommand?: boolean): any { // find dockerfile path let dockerfilepath = tl.getInput("Dockerfile", true); let dockerFile = fileUtils.findDockerFile(dockerfilepath); @@ -25,7 +25,8 @@ export function run(connection: ContainerConnection, outputUpdate: (data: string } // get command arguments - let commandArguments = ignoreArguments ? "" : dockerCommandUtils.getCommandArguments(tl.getInput("arguments", false)); + // ignore the arguments input if the command is buildAndPush, as it is ambiguous + let commandArguments = isBuildAndPushCommand ? "" : dockerCommandUtils.getCommandArguments(tl.getInput("arguments", false)); // get qualified image names by combining container registry(s) and repository let repositoryName = tl.getInput("repository"); @@ -33,13 +34,13 @@ export function run(connection: ContainerConnection, outputUpdate: (data: string // if container registry is provided, use that // else, use the currently logged in registries if (tl.getInput("containerRegistry")) { - let imageName = connection.getQualifiedImageName(repositoryName); + let imageName = connection.getQualifiedImageName(repositoryName, true); if (imageName) { imageNames.push(imageName); } } else { - imageNames = connection.getQualifiedImageNamesFromConfig(repositoryName); + imageNames = connection.getQualifiedImageNamesFromConfig(repositoryName, true); } // get label arguments diff --git a/Tasks/DockerV2/dockerpush.ts b/Tasks/DockerV2/dockerpush.ts index b50c43bbea5e..ea87f9f02b90 100644 --- a/Tasks/DockerV2/dockerpush.ts +++ b/Tasks/DockerV2/dockerpush.ts @@ -50,13 +50,14 @@ function pushMultipleImages(connection: ContainerConnection, imageNames: string[ return promise; } -export function run(connection: ContainerConnection, outputUpdate: (data: string) => any, ignoreArguments?: boolean): any { - let commandArguments = ignoreArguments ? "" : dockerCommandUtils.getCommandArguments(tl.getInput("arguments", false)); +export function run(connection: ContainerConnection, outputUpdate: (data: string) => any, isBuildAndPushCommand?: boolean): any { + // ignore the arguments input if the command is buildAndPush, as it is ambiguous + let commandArguments = isBuildAndPushCommand ? "" : dockerCommandUtils.getCommandArguments(tl.getInput("arguments", false)); // get tags input let tags = tl.getDelimitedInput("tags", "\n"); - // get qualified image name from the containerRegistry input + // get repository input let repositoryName = tl.getInput("repository"); if (!repositoryName) { tl.warning("No repository is specified. Nothing will be pushed."); @@ -66,19 +67,25 @@ export function run(connection: ContainerConnection, outputUpdate: (data: string // if container registry is provided, use that // else, use the currently logged in registries if (tl.getInput("containerRegistry")) { - let imageName = connection.getQualifiedImageName(repositoryName); + let imageName = connection.getQualifiedImageName(repositoryName, true); if (imageName) { imageNames.push(imageName); } } else { - imageNames = connection.getQualifiedImageNamesFromConfig(repositoryName); + imageNames = connection.getQualifiedImageNamesFromConfig(repositoryName, true); } const dockerfilepath = tl.getInput("dockerFile", true); - const dockerFile = findDockerFile(dockerfilepath); - if (!tl.exist(dockerFile)) { - throw new Error(tl.loc('ContainerDockerFileNotFound', dockerfilepath)); + let dockerFile = ""; + 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)); + } } // push all tags @@ -92,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); }); @@ -115,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 = getBaseImageNameFromDockerFile(dockerFilePath); + const baseImageName = dockerFilePath ? getBaseImageNameFromDockerFile(dockerFilePath) : "NA"; const layers = await dockerCommandUtils.getLayers(connection, imageName); if (!layers) { return null; diff --git a/Tasks/DockerV2/task.json b/Tasks/DockerV2/task.json index 381a8c622283..71c9a3e655f9 100644 --- a/Tasks/DockerV2/task.json +++ b/Tasks/DockerV2/task.json @@ -14,7 +14,7 @@ "version": { "Major": 2, "Minor": 153, - "Patch": 4 + "Patch": 5 }, "demands": [], "releaseNotes": "Simplified the task YAML by:
 - Removing the Container registry type input
 - Removing complex inputs as they can be passed as arguments to the command.", diff --git a/Tasks/DockerV2/task.loc.json b/Tasks/DockerV2/task.loc.json index 63f7be369556..7c8e3b90102f 100644 --- a/Tasks/DockerV2/task.loc.json +++ b/Tasks/DockerV2/task.loc.json @@ -14,7 +14,7 @@ "version": { "Major": 2, "Minor": 153, - "Patch": 4 + "Patch": 5 }, "demands": [], "releaseNotes": "ms-resource:loc.releaseNotes", diff --git a/Tasks/KubernetesManifestV0/task.json b/Tasks/KubernetesManifestV0/task.json index 8394b8d213d9..10b2e0614810 100644 --- a/Tasks/KubernetesManifestV0/task.json +++ b/Tasks/KubernetesManifestV0/task.json @@ -14,7 +14,7 @@ "version": { "Major": 0, "Minor": 153, - "Patch": 5 + "Patch": 6 }, "demands": [], "groups": [], diff --git a/Tasks/KubernetesManifestV0/task.loc.json b/Tasks/KubernetesManifestV0/task.loc.json index af0edc0f63f6..18db40df5125 100644 --- a/Tasks/KubernetesManifestV0/task.loc.json +++ b/Tasks/KubernetesManifestV0/task.loc.json @@ -14,7 +14,7 @@ "version": { "Major": 0, "Minor": 153, - "Patch": 5 + "Patch": 6 }, "demands": [], "groups": [], diff --git a/Tasks/KubernetesV0/task.json b/Tasks/KubernetesV0/task.json index 8af62386d571..6d028cec32d8 100644 --- a/Tasks/KubernetesV0/task.json +++ b/Tasks/KubernetesV0/task.json @@ -14,7 +14,7 @@ "version": { "Major": 0, "Minor": 153, - "Patch": 5 + "Patch": 6 }, "demands": [], "preview": "false", diff --git a/Tasks/KubernetesV0/task.loc.json b/Tasks/KubernetesV0/task.loc.json index f89596028d22..333d938b844a 100644 --- a/Tasks/KubernetesV0/task.loc.json +++ b/Tasks/KubernetesV0/task.loc.json @@ -14,7 +14,7 @@ "version": { "Major": 0, "Minor": 153, - "Patch": 5 + "Patch": 6 }, "demands": [], "preview": "false", diff --git a/Tasks/KubernetesV1/task.json b/Tasks/KubernetesV1/task.json index e6d76073e0c1..076813477100 100644 --- a/Tasks/KubernetesV1/task.json +++ b/Tasks/KubernetesV1/task.json @@ -14,7 +14,7 @@ "version": { "Major": 1, "Minor": 153, - "Patch": 5 + "Patch": 6 }, "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 febbe9bebdca..72a221db16c8 100644 --- a/Tasks/KubernetesV1/task.loc.json +++ b/Tasks/KubernetesV1/task.loc.json @@ -14,7 +14,7 @@ "version": { "Major": 1, "Minor": 153, - "Patch": 5 + "Patch": 6 }, "demands": [], "releaseNotes": "ms-resource:loc.releaseNotes",