moving hub login/logout to dockerCommand.execSync() so that no action need to call it explicitly
This commit is contained in:
Родитель
6307b2d126
Коммит
6580793bc3
|
@ -8,21 +8,11 @@ export function runCommand(): void {
|
|||
tl.cd(cwd);
|
||||
|
||||
var dockerConnectionString = tl.getInput("dockerServiceEndpoint", true);
|
||||
var registryEndpoint = tl.getInput("dockerRegistryServiceEndpoint", true);
|
||||
var registryConnectionString = tl.getInput("dockerRegistryServiceEndpoint", true);
|
||||
var commandLine = tl.getInput("customCommand", true);
|
||||
|
||||
var registryConnetionDetails = tl.getEndpointAuthorization(registryEndpoint, true);
|
||||
|
||||
var loginCmd = new docker.DockerCommand("login");
|
||||
loginCmd.dockerConnectionString = dockerConnectionString;
|
||||
loginCmd.registryConnetionDetails = registryConnetionDetails;
|
||||
loginCmd.execSync();
|
||||
|
||||
var cmd = new docker.DockerCommand(commandLine);
|
||||
cmd.dockerConnectionString = dockerConnectionString;
|
||||
cmd.registryConnectionString = registryConnectionString;
|
||||
cmd.execSync();
|
||||
|
||||
var logoutCmd = new docker.DockerCommand("logout");
|
||||
logoutCmd.dockerConnectionString = dockerConnectionString;
|
||||
logoutCmd.execSync();
|
||||
}
|
|
@ -10,33 +10,23 @@ export function dockerBuild(): void {
|
|||
tl.cd(cwd);
|
||||
|
||||
var dockerConnectionString = tl.getInput("dockerServiceEndpoint", true);
|
||||
var registryEndpoint = tl.getInput("dockerRegistryServiceEndpoint", true);
|
||||
var registryConnectionString = tl.getInput("dockerRegistryServiceEndpoint", true);
|
||||
var dockerFilePattern = tl.getInput("dockerFile", true);
|
||||
var context = tl.getInput("context", true);
|
||||
var imageName = tl.getInput("imageName", true);
|
||||
var additionalArgs = tl.getInput("additionalArgs", false);
|
||||
|
||||
var registryConnetionDetails = tl.getEndpointAuthorization(registryEndpoint, true);
|
||||
|
||||
var loginCmd = new docker.DockerCommand("login");
|
||||
loginCmd.dockerConnectionString = dockerConnectionString;
|
||||
loginCmd.registryConnetionDetails = registryConnetionDetails;
|
||||
loginCmd.execSync();
|
||||
|
||||
var dockerFile = getDockerFile(dockerFilePattern);
|
||||
dockerFile = copyDockerFileToContextFolder(dockerFile, context);
|
||||
|
||||
var cmd = new docker.DockerCommand("build");
|
||||
cmd.dockerConnectionString = dockerConnectionString;
|
||||
cmd.registryConnectionString = registryConnectionString;
|
||||
cmd.dockerFile = dockerFile;
|
||||
cmd.context = context;
|
||||
cmd.imageName = imageName;
|
||||
cmd.additionalArguments = additionalArgs;
|
||||
cmd.execSync();
|
||||
|
||||
var logoutCmd = new docker.DockerCommand("logout");
|
||||
logoutCmd.dockerConnectionString = dockerConnectionString;
|
||||
logoutCmd.execSync();
|
||||
}
|
||||
|
||||
function copyDockerFileToContextFolder(dockerFile: string, context: string): string {
|
||||
|
|
|
@ -16,18 +16,40 @@ export class DockerCommand {
|
|||
public envVars: string[];
|
||||
public additionalArguments: string;
|
||||
public dockerConnectionString: string;
|
||||
public registryConnetionDetails: tl.EndpointAuthorization;
|
||||
public registryConnectionString: string;
|
||||
public connectToHub: boolean;
|
||||
|
||||
constructor(commandName: string) {
|
||||
this.commandName = commandName;
|
||||
this.connectToHub = true;
|
||||
}
|
||||
|
||||
public execSync(): tr.IExecResult {
|
||||
var command = this.getBasicCommand();
|
||||
this.writeCerts();
|
||||
|
||||
if (this.connectToHub) {
|
||||
var loginCmd = this.getCommand("login");
|
||||
loginCmd.execSync();
|
||||
}
|
||||
|
||||
var command = this.getCommand(this.commandName);
|
||||
var result = command.execSync();
|
||||
|
||||
if (this.connectToHub) {
|
||||
var logoutCmd = this.getCommand("logout");
|
||||
logoutCmd.execSync();
|
||||
}
|
||||
|
||||
this.clearCerts();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private getCommand(commandName: string): tr.ToolRunner {
|
||||
var command = this.getBasicCommand();
|
||||
|
||||
this.appendAuthArgs(command);
|
||||
switch (this.commandName) {
|
||||
switch (commandName) {
|
||||
case "run":
|
||||
this.appendRunCmdArgs(command);
|
||||
break;
|
||||
|
@ -50,18 +72,14 @@ export class DockerCommand {
|
|||
this.appendRemoveContainerByNameCmdArgs(command);
|
||||
break;
|
||||
default:
|
||||
command.arg(this.commandName);
|
||||
command.arg(commandName);
|
||||
}
|
||||
|
||||
if (this.additionalArguments) {
|
||||
command.arg(this.additionalArguments);
|
||||
}
|
||||
|
||||
var result = command.execSync();
|
||||
|
||||
this.clearCerts();
|
||||
|
||||
return result;
|
||||
return command;
|
||||
}
|
||||
|
||||
private getBasicCommand(): tr.ToolRunner {
|
||||
|
@ -143,10 +161,11 @@ export class DockerCommand {
|
|||
}
|
||||
|
||||
private appendLoginCmdArgs(command: tr.ToolRunner) {
|
||||
var registryConnetionDetails = tl.getEndpointAuthorization(this.registryConnectionString, true);
|
||||
command.arg("login");
|
||||
command.arg("-e " + this.registryConnetionDetails.parameters["email"]);
|
||||
command.arg("-u " + this.registryConnetionDetails.parameters["username"]);
|
||||
command.arg("-p " + this.registryConnetionDetails.parameters["password"]);
|
||||
command.arg("-e " + registryConnetionDetails.parameters["email"]);
|
||||
command.arg("-u " + registryConnetionDetails.parameters["username"]);
|
||||
command.arg("-p " + registryConnetionDetails.parameters["password"]);
|
||||
}
|
||||
|
||||
private appendLogoutCmdArgs(command: tr.ToolRunner) {
|
||||
|
|
|
@ -8,20 +8,14 @@ export function dockerPublish(): void {
|
|||
tl.cd(cwd);
|
||||
|
||||
var dockerConnectionString = tl.getInput("dockerServiceEndpoint", true);
|
||||
var registryEndpoint = tl.getInput("dockerRegistryServiceEndpoint", true);
|
||||
var registryConnectionString = tl.getInput("dockerRegistryServiceEndpoint", true);
|
||||
var imageName = tl.getInput("imageName", true);
|
||||
var removeImageAfterPublish = tl.getBoolInput("removeImageAfterPublish", true);
|
||||
var additionalArgs = tl.getInput("additionalArgs", false);
|
||||
|
||||
var registryConnetionDetails = tl.getEndpointAuthorization(registryEndpoint, true);
|
||||
|
||||
var loginCmd = new docker.DockerCommand("login");
|
||||
loginCmd.dockerConnectionString = dockerConnectionString;
|
||||
loginCmd.registryConnetionDetails = registryConnetionDetails;
|
||||
loginCmd.execSync();
|
||||
|
||||
var publishCmd = new docker.DockerCommand("publish");
|
||||
publishCmd.dockerConnectionString = dockerConnectionString;
|
||||
publishCmd.registryConnectionString = registryConnectionString;
|
||||
publishCmd.imageName = imageName;
|
||||
publishCmd.additionalArguments = additionalArgs;
|
||||
publishCmd.execSync();
|
||||
|
@ -30,10 +24,7 @@ export function dockerPublish(): void {
|
|||
var rmiCmd = new docker.DockerCommand("removeImage");
|
||||
rmiCmd.dockerConnectionString = dockerConnectionString;
|
||||
rmiCmd.imageName = imageName;
|
||||
rmiCmd.connectToHub = false;
|
||||
rmiCmd.execSync();
|
||||
}
|
||||
|
||||
var logoutCmd = new docker.DockerCommand("logout");
|
||||
logoutCmd.dockerConnectionString = dockerConnectionString;
|
||||
logoutCmd.execSync();
|
||||
}
|
|
@ -8,20 +8,13 @@ export function dockerRun(): void {
|
|||
tl.cd(cwd);
|
||||
|
||||
var dockerConnectionString = tl.getInput("dockerServiceEndpoint", true);
|
||||
var registryEndpoint = tl.getInput("dockerRegistryServiceEndpoint", true);
|
||||
var registryConnectionString = tl.getInput("dockerRegistryServiceEndpoint", true);
|
||||
var imageName = tl.getInput("imageName", true);
|
||||
var containerName = tl.getInput("containerName", false);
|
||||
var envVars = tl.getDelimitedInput("envVars", "\n", false);
|
||||
var ports = tl.getDelimitedInput("ports", "\n", false);
|
||||
var additionalArgs = tl.getInput("additionalArgs", false);
|
||||
|
||||
var registryConnetionDetails = tl.getEndpointAuthorization(registryEndpoint, true);
|
||||
|
||||
var loginCmd = new docker.DockerCommand("login");
|
||||
loginCmd.dockerConnectionString = dockerConnectionString;
|
||||
loginCmd.registryConnetionDetails = registryConnetionDetails;
|
||||
loginCmd.execSync();
|
||||
|
||||
if (containerName) {
|
||||
removeConflictingContainersByName(containerName, dockerConnectionString);
|
||||
}
|
||||
|
@ -32,22 +25,20 @@ export function dockerRun(): void {
|
|||
|
||||
var cmd = new docker.DockerCommand("run");
|
||||
cmd.dockerConnectionString = dockerConnectionString;
|
||||
cmd.registryConnectionString = registryConnectionString;
|
||||
cmd.imageName = imageName;
|
||||
cmd.containerName = containerName;
|
||||
cmd.ports = ports;
|
||||
cmd.envVars = envVars;
|
||||
cmd.additionalArguments = additionalArgs;
|
||||
cmd.execSync();
|
||||
|
||||
var logoutCmd = new docker.DockerCommand("logout");
|
||||
logoutCmd.dockerConnectionString = dockerConnectionString;
|
||||
logoutCmd.execSync();
|
||||
}
|
||||
|
||||
function removeConflictingContainersByName(containerName: string, dockerConnectionString: string): void {
|
||||
var cmd = new docker.DockerCommand("removeContainerByName");
|
||||
cmd.dockerConnectionString = dockerConnectionString;
|
||||
cmd.containerName = containerName;
|
||||
cmd.connectToHub = false;
|
||||
cmd.execSync();
|
||||
}
|
||||
|
||||
|
@ -56,11 +47,13 @@ function removeConflictingContainersByPort(ports: string[], dockerConnectionStri
|
|||
// For now, we are removing all
|
||||
var cmd = new docker.DockerCommand("ps -a -q");
|
||||
cmd.dockerConnectionString = dockerConnectionString;
|
||||
cmd.connectToHub = false;
|
||||
var containerIdList = cmd.execSync().stdout.toString();
|
||||
|
||||
if ( (containerIdList) && (containerIdList.trim() != "")) {
|
||||
var containerIds = containerIdList.split("\n").join(" ").trim();
|
||||
var cmd = new docker.DockerCommand("rm -f " + containerIds);
|
||||
cmd.connectToHub = false;
|
||||
cmd.dockerConnectionString = dockerConnectionString;
|
||||
cmd.execSync();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче