Skip to content

Commit

Permalink
[KubernetesManifest] ACR based DockerRegistry endpoint (#10039)
Browse files Browse the repository at this point in the history
* [KubernetesManifest] Adding support for ACR based Docker Registry service connection

* Refactoring dockerregistry logic to common

* Fixing it in dockerCompose task
  • Loading branch information
thesattiraju committed Apr 22, 2019
1 parent ffa6c49 commit 1a674fa
Show file tree
Hide file tree
Showing 24 changed files with 227 additions and 202 deletions.
84 changes: 42 additions & 42 deletions Tasks/Common/docker-common/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class GenericAuthenticationTokenProvider extends AuthenticationTo
super();

if(endpointName) {
this.registryAuth = tl.getEndpointAuthorization(endpointName, true).parameters;
this.registryAuth = tl.getEndpointAuthorization(endpointName, false).parameters;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import * as tl from "vsts-task-lib/task";
const util = require('util');
import ACRAuthenticationTokenProvider from "./acrauthenticationtokenprovider"
import GenericAuthenticationTokenProvider from "./genericauthenticationtokenprovider";

export default class RegistryServerAuthenticationToken {

Expand All @@ -12,21 +14,21 @@ export default class RegistryServerAuthenticationToken {
private username: string;
private password: string;
private email: string;
private xMetaSourceClient: string;
private xMetaSourceClient: string;

constructor(username: string, authenticationPassword: string, registry: string, email: string, xMetaSourceClient: string) {

// Replace it with setvariable once vsts-task-lib is updated
console.log("##vso[task.setvariable variable=CONTAINER_USERNAME;issecret=true;]" + username);
console.log("##vso[task.setvariable variable=CONTAINER_PASSWORD;issecret=true;]" + authenticationPassword);

this.registry = registry;
this.password = authenticationPassword;
this.username = username;
this.email = email;
this.xMetaSourceClient = xMetaSourceClient;
}

public getUsername(): string {
return this.username;
}
Expand All @@ -38,22 +40,37 @@ export default class RegistryServerAuthenticationToken {
public getLoginServerUrl(): string {
return this.registry;
}

public getEmail(): string {
return this.email;
}

public getDockerConfig(): string {
var authenticationToken = new Buffer(this.username+":"+this.password).toString('base64')
var authenticationToken = new Buffer(this.username + ":" + this.password).toString('base64')
console.log("##vso[task.setvariable variable=CONTAINER_AUTHENTICATIONTOKEN;issecret=true;]" + authenticationToken);
var auths = util.format('{"auths": { "%s": {"auth": "%s", "email": "%s" } }, "HttpHeaders":{"X-Meta-Source-Client":"%s"} }', this.registry, authenticationToken,this.email, this.xMetaSourceClient);
var auths = util.format('{"auths": { "%s": {"auth": "%s", "email": "%s" } }, "HttpHeaders":{"X-Meta-Source-Client":"%s"} }', this.registry, authenticationToken, this.email, this.xMetaSourceClient);
return auths;
}

public getDockerAuth(): string {
var authenticationToken = new Buffer(this.username+":"+this.password).toString('base64')
var authenticationToken = new Buffer(this.username + ":" + this.password).toString('base64')
console.log("##vso[task.setvariable variable=CONTAINER_AUTHENTICATIONTOKEN;issecret=true;]" + authenticationToken);
let auth = util.format('{ "%s": {"auth": "%s", "email": "%s" } }', this.registry, authenticationToken, this.email );
let auth = util.format('{ "%s": {"auth": "%s", "email": "%s" } }', this.registry, authenticationToken, this.email);
return auth;
}
}

export function getDockerRegistryEndpointAuthenticationToken(endpointId: string): RegistryServerAuthenticationToken {
var registryType = tl.getEndpointDataParameter(endpointId, "registrytype", true);
let authToken: RegistryServerAuthenticationToken;

if (registryType === "ACR") {
const loginServer = tl.getEndpointAuthorizationParameter(endpointId, "loginServer", false);
authToken = new ACRAuthenticationTokenProvider(endpointId, loginServer).getAuthenticationToken();
}
else {
authToken = new GenericAuthenticationTokenProvider(endpointId).getAuthenticationToken();
}

return authToken;
}
11 changes: 4 additions & 7 deletions Tasks/DockerComposeV0/dockercompose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import * as path from "path";
import * as tl from "vsts-task-lib/task";
import * as DockerComposeUtils from "./dockercomposeutils";

import AuthenticationTokenProvider from "docker-common/registryauthenticationprovider/authenticationtokenprovider"
import ACRAuthenticationTokenProvider from "docker-common/registryauthenticationprovider/acrauthenticationtokenprovider"
import DockerComposeConnection from "./dockercomposeconnection";
import GenericAuthenticationTokenProvider from "docker-common/registryauthenticationprovider/genericauthenticationtokenprovider"
import { getDockerRegistryEndpointAuthenticationToken } from "docker-common/registryauthenticationprovider/registryauthenticationtoken";

import Q = require('q');

Expand All @@ -18,17 +17,15 @@ tl.cd(tl.getInput("cwd"));

// get the registry server authentication provider
var registryType = tl.getInput("containerregistrytype", true);
var authenticationProvider: AuthenticationTokenProvider;
var registryAuthenticationToken;

if (registryType == "Azure Container Registry") {
authenticationProvider = new ACRAuthenticationTokenProvider(tl.getInput("azureSubscriptionEndpoint"), tl.getInput("azureContainerRegistry"));
registryAuthenticationToken = new ACRAuthenticationTokenProvider(tl.getInput("azureSubscriptionEndpoint"), tl.getInput("azureContainerRegistry")).getAuthenticationToken();
}
else {
authenticationProvider = new GenericAuthenticationTokenProvider(tl.getInput("dockerRegistryEndpoint"));
registryAuthenticationToken = getDockerRegistryEndpointAuthenticationToken(tl.getInput("dockerRegistryEndpoint"))
}

var registryAuthenticationToken = authenticationProvider.getAuthenticationToken();

var dockerComposeFile = tl.getInput("dockerComposeFile", true);
var nopIfNoDockerComposeFile = tl.getBoolInput("nopIfNoDockerComposeFile");
var dockerFile = DockerComposeUtils.findDockerFile(dockerComposeFile);
Expand Down
Loading

0 comments on commit 1a674fa

Please sign in to comment.