Skip to content

Commit

Permalink
Opt in to qualify source image name optionally (#11055) (#11058)
Browse files Browse the repository at this point in the history
* Revert "[DockerV1] Honoring qualifyImageName value in tag (#10736)"

This reverts commit 975f59b.

* opt in qualify source image name optionally
  • Loading branch information
thesattiraju authored Aug 2, 2019
1 parent 046e0c0 commit fcc922f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"loc.input.help.imageNamesPath": "Path to a text file that contains the names of the Docker images to tag or push. Each image name is contained on its own line.",
"loc.input.label.qualifyImageName": "Qualify image name",
"loc.input.help.qualifyImageName": "Qualify the image name with the Docker registry service connection's hostname if not otherwise specified.",
"loc.input.label.qualifySourceImageName": "Qualify source image name",
"loc.input.help.qualifySourceImageName": "Qualify the source image name with the Docker registry service connection's hostname if not otherwise specified.",
"loc.input.label.includeSourceTags": "Include source tags",
"loc.input.help.includeSourceTags": "Include Git tags when building or pushing the Docker image.",
"loc.input.label.includeLatestTag": "Include latest tag",
Expand Down
24 changes: 21 additions & 3 deletions Tasks/DockerV1/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('Docker Suite', function() {
delete process.env[shared.TestEnvVars.pushMultipleImages];
delete process.env[shared.TestEnvVars.tagMultipleImages];
delete process.env[shared.TestEnvVars.arguments];
delete process.env[shared.TestEnvVars.qualifySourceImageName];
});
after(function () {
});
Expand Down Expand Up @@ -205,7 +206,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 tag ajgtestacr1.azurecr.io/${shared.ImageNamesFileImageName} ajgtestacr1.azurecr.io/${shared.ImageNamesFileImageName}`) != -1, "docker tag should run");
assert(tr.stdout.indexOf(`[command]docker tag ${shared.ImageNamesFileImageName} ajgtestacr1.azurecr.io/${shared.ImageNamesFileImageName}`) != -1, "docker tag should run");
console.log(tr.stderr);
done();
});
Expand All @@ -215,13 +216,30 @@ describe('Docker Suite', function() {
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
process.env[shared.TestEnvVars.command] = shared.CommandTypes.tagImages;
process.env[shared.TestEnvVars.containerType] = shared.ContainerTypes.AzureContainerRegistry;
process.env[shared.TestEnvVars.qualifyImageName] = "false";
process.env[shared.TestEnvVars.qualifyImageName] = "true";
tr.run();

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 tag test/test:2 ajgtestacr1.azurecr.io/test/test:2`) != -1, "docker tag should run");
console.log(tr.stderr);
done();
});

it('Runs successfully for docker tag image with sourcequalify set to true', (done:MochaDone) => {
let tp = path.join(__dirname, 'TestSetup.js');
let tr : ttm.MockTestRunner = new ttm.MockTestRunner(tp);
process.env[shared.TestEnvVars.command] = shared.CommandTypes.tagImages;
process.env[shared.TestEnvVars.containerType] = shared.ContainerTypes.AzureContainerRegistry;
process.env[shared.TestEnvVars.qualifyImageName] = "true";
process.env[shared.TestEnvVars.qualifySourceImageName] = "true";
tr.run();

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 tag test/test:2 test/test:2`) != -1, "docker tag should run");
assert(tr.stdout.indexOf(`[command]docker tag ajgtestacr1.azurecr.io/test/test:2 ajgtestacr1.azurecr.io/test/test:2`) != -1, "docker tag should run");
console.log(tr.stderr);
done();
});
Expand Down
7 changes: 4 additions & 3 deletions Tasks/DockerV1/Tests/TestSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tr.setInput('dockerRegistryEndpoint', 'dockerhubendpoint');
tr.setInput('dockerFile', DockerFilePath);
tr.setInput('includeLatestTag', process.env[shared.TestEnvVars.includeLatestTag] || "false");
tr.setInput('qualifyImageName', process.env[shared.TestEnvVars.qualifyImageName] || "false");
tr.setInput('qualifySourceImageName', process.env[shared.TestEnvVars.qualifySourceImageName] || "false");
tr.setInput('azureSubscriptionEndpoint', 'AzureRMSpn');
tr.setInput('azureContainerRegistry', '{"loginServer":"ajgtestacr1.azurecr.io", "id" : "/subscriptions/c00d16c7-6c1f-4c03-9be1-6934a4c49682/resourcegroups/ajgtestacr1rg/providers/Microsoft.ContainerRegistry/registries/ajgtestacr1"}')
tr.setInput('enforceDockerNamingConvention', process.env[shared.TestEnvVars.enforceDockerNamingConvention]);
Expand Down Expand Up @@ -100,7 +101,7 @@ a.exec[`docker build -f ${DockerFilePath} -t ajgtestacr1.azurecr.io/test/test:2`
a.exec[`docker build -f ${DockerFilePath} -t ${shared.ImageNamesFileImageName}`] = {
"code": 0
};
a.exec[`docker tag test/test:2 test/test:2`] = {
a.exec[`docker tag test/test:2 ajgtestacr1.azurecr.io/test/test:2`] = {
"code": 0
};
a.exec[`docker tag test/test:latest test/test:latest`] = {
Expand All @@ -109,10 +110,10 @@ a.exec[`docker tag test/test:latest test/test:latest`] = {
a.exec[`docker tag test/test:latest test/test:v1`] = {
"code": 0
};
a.exec[`docker tag ajgtestacr1.azurecr.io/${shared.ImageNamesFileImageName} ajgtestacr1.azurecr.io/${shared.ImageNamesFileImageName}`] = {
a.exec[`docker tag ${shared.ImageNamesFileImageName} ajgtestacr1.azurecr.io/${shared.ImageNamesFileImageName}`] = {
"code": 0
};
a.exec[`docker tag ${shared.ImageNamesFileImageName} ${shared.ImageNamesFileImageName}`] = {
a.exec[`docker tag ajgtestacr1.azurecr.io/test/test:2 ajgtestacr1.azurecr.io/test/test:2`] = {
"code": 0
};
a.exec[`docker run --rm ${shared.ImageNamesFileImageName}`] = {
Expand Down
3 changes: 2 additions & 1 deletion Tasks/DockerV1/Tests/TestShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export let TestEnvVars = {
memoryLimit: "__memoryLimit__",
pushMultipleImages: "__pushMultipleImages__",
tagMultipleImages: "__tagMultipleImages__",
arguments: "__arguments__"
arguments: "__arguments__",
qualifySourceImageName: "__qualifySourceImageName__"
};

export let OperatingSystems = {
Expand Down
11 changes: 7 additions & 4 deletions Tasks/DockerV1/containertag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import * as imageUtils from "docker-common/containerimageutils";
import * as utils from "./utils";
import * as Q from 'q';

function dockerTag(connection: ContainerConnection, sourceImage: string, targetImage: string, qualifyImageName: boolean): Q.Promise<void> {
function dockerTag(connection: ContainerConnection, sourceImage: string, targetImage: string, qualifyImageName: boolean, qualifySourceImageName: boolean): Q.Promise<void> {
let command = connection.createCommand();
command.arg("tag");
if (qualifyImageName) {
sourceImage = connection.getQualifiedImageNameIfRequired(sourceImage);
targetImage = connection.getQualifiedImageNameIfRequired(targetImage);
}
if (qualifySourceImageName) {
sourceImage = connection.getQualifiedImageNameIfRequired(sourceImage);
}
command.arg(sourceImage);
command.arg(targetImage);

Expand All @@ -31,13 +33,14 @@ export function run(connection: ContainerConnection): Q.Promise<void> {
imageNames = [utils.getImageName()];
}
var qualifyImageName = tl.getBoolInput("qualifyImageName");
const qualifySourceImageName = tl.getBoolInput("qualifySourceImageName");
let additionalImageTags = tl.getDelimitedInput("arguments", "\n");
let imageMappings = utils.getImageMappings(connection, imageNames, additionalImageTags);

let firstMapping = imageMappings.shift();
let promise = dockerTag(connection, firstMapping.sourceImageName, firstMapping.targetImageName, qualifyImageName);
let promise = dockerTag(connection, firstMapping.sourceImageName, firstMapping.targetImageName, qualifyImageName, qualifySourceImageName);
imageMappings.forEach(mapping => {
promise = promise.then(() => dockerTag(connection, mapping.sourceImageName, mapping.targetImageName, qualifyImageName));
promise = promise.then(() => dockerTag(connection, mapping.sourceImageName, mapping.targetImageName, qualifyImageName, qualifySourceImageName));
});

return promise;
Expand Down
11 changes: 10 additions & 1 deletion Tasks/DockerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 154,
"Minor": 155,
"Patch": 3
},
"demands": [],
Expand Down Expand Up @@ -167,6 +167,15 @@
"groupName": "commands",
"helpMarkDown": "Qualify the image name with the Docker registry service connection's hostname if not otherwise specified."
},
{
"name": "qualifySourceImageName",
"type": "boolean",
"label": "Qualify source image name",
"defaultValue": "false",
"visibleRule": "command = Tag image || command = tag",
"groupName": "commands",
"helpMarkDown": "Qualify the source image name with the Docker registry service connection's hostname if not otherwise specified."
},
{
"name": "includeSourceTags",
"type": "boolean",
Expand Down
11 changes: 10 additions & 1 deletion Tasks/DockerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 154,
"Minor": 155,
"Patch": 3
},
"demands": [],
Expand Down Expand Up @@ -167,6 +167,15 @@
"groupName": "commands",
"helpMarkDown": "ms-resource:loc.input.help.qualifyImageName"
},
{
"name": "qualifySourceImageName",
"type": "boolean",
"label": "ms-resource:loc.input.label.qualifySourceImageName",
"defaultValue": "false",
"visibleRule": "command = Tag image || command = tag",
"groupName": "commands",
"helpMarkDown": "ms-resource:loc.input.help.qualifySourceImageName"
},
{
"name": "includeSourceTags",
"type": "boolean",
Expand Down

0 comments on commit fcc922f

Please sign in to comment.