implementing build image action
This commit is contained in:
Родитель
cce345c017
Коммит
2ea5f23c82
|
@ -1,12 +1,34 @@
|
|||
/// <reference path="../../../typings/vsts-task-lib/vsts-task-lib.d.ts" />
|
||||
|
||||
import fs = require("fs");
|
||||
import path = require("path");
|
||||
import tl = require("vsts-task-lib/task");
|
||||
import * as docker from "./dockerCommand";
|
||||
|
||||
export function dockerBuild(): void {
|
||||
var dockerFile = tl.getInput("dockerFile", true);
|
||||
var context = tl.getInput("context", true);
|
||||
var imageName = tl.getInput("imageName", true);
|
||||
var additionalArgs = tl.getInput("additionalArgs", false);
|
||||
|
||||
|
||||
|
||||
dockerFile = copyDockerFileToContextFolder(dockerFile, context);
|
||||
|
||||
var cmd = new docker.DockerCommand("build");
|
||||
cmd.dockerFile = dockerFile;
|
||||
cmd.context = context;
|
||||
cmd.imageName = imageName;
|
||||
cmd.additionalArguments = additionalArgs;
|
||||
cmd.execSync();
|
||||
}
|
||||
|
||||
function copyDockerFileToContextFolder(dockerFile: string, context: string): string {
|
||||
var target = path.join(context, path.basename(dockerFile));
|
||||
|
||||
if (dockerFile == target) {
|
||||
return target;
|
||||
}
|
||||
|
||||
fs.createReadStream(dockerFile).pipe(<any>fs.createWriteStream(target));
|
||||
return target;
|
||||
// TODO: handle errors
|
||||
}
|
|
@ -5,6 +5,8 @@ import tr = require("vsts-task-lib/toolrunner");
|
|||
|
||||
export class DockerCommand {
|
||||
public commandName: string;
|
||||
public dockerFile: string;
|
||||
public context: string;
|
||||
public imageName: string;
|
||||
public additionalArguments: string;
|
||||
|
||||
|
@ -19,8 +21,11 @@ export class DockerCommand {
|
|||
case "run":
|
||||
this.appendRunCmdArgs(command);
|
||||
break;
|
||||
case "build":
|
||||
this.appendBuildCmdArgs(command);
|
||||
break;
|
||||
default:
|
||||
command.arg(this.imageName);
|
||||
command.arg(this.commandName);
|
||||
}
|
||||
|
||||
if (this.additionalArguments) {
|
||||
|
@ -45,4 +50,11 @@ export class DockerCommand {
|
|||
command.arg(this.imageName);
|
||||
// TODO: hanle imageName not set
|
||||
}
|
||||
|
||||
private appendBuildCmdArgs(command: tr.ToolRunner) {
|
||||
command.arg("build");
|
||||
command.arg("-t " + this.imageName);
|
||||
command.arg("-f " + this.dockerFile);
|
||||
command.arg(this.context);
|
||||
}
|
||||
}
|
|
@ -32,12 +32,21 @@
|
|||
},
|
||||
{
|
||||
"name": "dockerFile",
|
||||
"type": "",
|
||||
"type": "filePath",
|
||||
"label": "Docker File",
|
||||
"defaultValue": "",
|
||||
"required": true,
|
||||
"visibleRule": "action = build an image",
|
||||
"helpMarkDown": "docker file to be built"
|
||||
"helpMarkDown": "Path to Dockerfile to use"
|
||||
},
|
||||
{
|
||||
"name": "context",
|
||||
"type": "filePath",
|
||||
"label": "Context",
|
||||
"defaultValue": "$(Build.StagingDirectory)/drop",
|
||||
"required": true,
|
||||
"visibleRule": "action = build an image",
|
||||
"helpMarkDown": "The path to the folder to build from."
|
||||
},
|
||||
{
|
||||
"name": "imageName",
|
||||
|
|
Загрузка…
Ссылка в новой задаче