Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WIF suport to DockerV0 and DockerV1 #18605

Merged
merged 2 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Tasks/DockerV0/Tests/TestSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ process.env["RELEASE_RELEASENAME"] = "Release-1";
process.env["SYSTEM_DEFAULTWORKINGDIRECTORY"] = DefaultWorkingDirectory;
process.env["SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"] = shared.teamFoundationCollectionURI;
process.env["SYSTEM_SERVERTYPE"] = "hosted";
process.env['AGENT_TEMPDIRECTORY'] = '.';
process.env["ENDPOINT_AUTH_dockerhubendpoint"] = "{\"parameters\":{\"username\":\"test\", \"password\":\"regpassword\", \"email\":\"test@microsoft.com\",\"registry\":\"https://index.docker.io/v1/\"},\"scheme\":\"UsernamePassword\"}";
process.env["ENDPOINT_AUTH_SCHEME_AzureRMSpn"] = "ServicePrincipal";
process.env["ENDPOINT_AUTH_PARAMETER_AzureRMSpn_SERVICEPRINCIPALID"] = "spId";
Expand Down
65 changes: 34 additions & 31 deletions Tasks/DockerV0/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@ tl.setResourcePath(path.join(__dirname, 'task.json'));
// Change to any specified working directory
tl.cd(tl.getInput("cwd"));

// get the registry server authentication provider
// get the registry server authentication provider
var containerRegistryType = tl.getInput("containerregistrytype", true);
const environmentVariableMaximumSize = 32766;

var registryAuthenticationToken;
if (containerRegistryType == "Azure Container Registry") {
registryAuthenticationToken = new ACRAuthenticationTokenProvider(tl.getInput("azureSubscriptionEndpoint"), tl.getInput("azureContainerRegistry")).getAuthenticationToken();
const tokenProvider = new ACRAuthenticationTokenProvider(tl.getInput("azureSubscriptionEndpoint"), tl.getInput("azureContainerRegistry"));
registryAuthenticationToken = tokenProvider.getToken();
}
else {
let endpointId = tl.getInput("dockerRegistryEndpoint");
registryAuthenticationToken = getDockerRegistryEndpointAuthenticationToken(endpointId);
}

// Connect to any specified container host and/or registry
var connection = new ContainerConnection();
connection.open(tl.getInput("dockerHostEndpoint"), registryAuthenticationToken);

// Run the specified action
var action = tl.getInput("action", true).toLowerCase();
let command = "";
Expand Down Expand Up @@ -70,29 +67,35 @@ console.log("##vso[telemetry.publish area=%s;feature=%s]%s",
"DockerV0",
JSON.stringify(telemetry));

/* tslint:disable:no-var-requires */
require({
"build an image": "./containerbuild",
"tag images": "./containertag",
"push an image": "./containerpush",
"push images": "./containerpush",
"run an image": "./containerrun",
"run a docker command": "./containercommand"
}[action]).run(connection, (data) => result += data)
/* tslint:enable:no-var-requires */
.fin(function cleanup() {
connection.close();
})
.then(function success() {
var commandOutputLength = result.length;
if (commandOutputLength > environmentVariableMaximumSize) {
tl.warning(tl.loc('OutputVariableDataSizeExceeded', commandOutputLength, environmentVariableMaximumSize));
} else {
tl.setVariable("DockerOutput", result);
}
registryAuthenticationToken
.then(function success(authToken) {
// Connect to any specified container host and/or registry
var connection = new ContainerConnection();
connection.open(tl.getInput("dockerHostEndpoint"), authToken);
/* tslint:disable:no-var-requires */
require({
"build an image": "./containerbuild",
"tag images": "./containertag",
"push an image": "./containerpush",
"push images": "./containerpush",
"run an image": "./containerrun",
"run a docker command": "./containercommand"
}[action]).run(connection, (data) => result += data)
/* tslint:enable:no-var-requires */
.fin(function cleanup() {
connection.close();
})
.then(function success() {
var commandOutputLength = result.length;
if (commandOutputLength > environmentVariableMaximumSize) {
tl.warning(tl.loc('OutputVariableDataSizeExceeded', commandOutputLength, environmentVariableMaximumSize));
} else {
tl.setVariable("DockerOutput", result);
}

tl.setResult(tl.TaskResult.Succeeded, "");
}, function failure(err) {
tl.setResult(tl.TaskResult.Failed, err.message);
})
.done();
tl.setResult(tl.TaskResult.Succeeded, "");
}, function failure(err) {
tl.setResult(tl.TaskResult.Failed, err.message);
})
.done();
});
6 changes: 6 additions & 0 deletions Tasks/DockerV0/make.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"node_modules/azure-pipelines-tasks-docker-common/node_modules/azure-pipelines-task-lib"
],
"options": "-Rf"
},
{
"items": [
"node_modules/azure-pipelines-tasks-azure-arm-rest-v2/node_modules/azure-pipelines-task-lib"
starkmsu marked this conversation as resolved.
Show resolved Hide resolved
],
"options": "-Rf"
}
]
}
Loading