From 3f8bebab370c6682f6d1f070c0afaa9acd598fdb Mon Sep 17 00:00:00 2001 From: PREETI BANSAL Date: Fri, 11 Oct 2019 11:43:29 +0530 Subject: [PATCH] Adding support for RUNNING_AS_K8 flag --- Tasks/BuildctlV0/src/buildctl.ts | 40 ++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/Tasks/BuildctlV0/src/buildctl.ts b/Tasks/BuildctlV0/src/buildctl.ts index b3a3e970507a..79e54f0b7f5f 100644 --- a/Tasks/BuildctlV0/src/buildctl.ts +++ b/Tasks/BuildctlV0/src/buildctl.ts @@ -26,8 +26,21 @@ async function verifyBuildctl() { buildctlTool.exec(); } +async function buildContainer() { + if(process.env["RUNNING_AS_K8_POOLPROVIDER"] == "1") { + tl.debug("Container building using buildctl"); + return buildUsingBuildctl(); + } + else { + tl.debug("Container building using docker frontend"); + return buildUsingDocker(); + } + +} + async function buildUsingBuildctl() { + await verifyBuildctl(); const dockerfilepath = tl.getInput("dockerFile", true); const contextpath = tl.getInput("localContext", true); var podname = await utils.getBuildKitPod(); @@ -45,9 +58,32 @@ async function buildUsingBuildctl() { return buildctlTool.exec(); } +async function buildUsingDocker() { + + const dockerfilepath = tl.getInput("dockerFile", true); + const contextpath = tl.getInput("localContext", true); + var dockerToolPath = tl.which("docker", true); + var command = tl.tool(dockerToolPath); + command.arg("build"); + command.arg(["-f", dockerfilepath]); + + command.arg(contextpath); + + // setup variable to store the command output + let output = ""; + command.on("stdout", data => { + output += data; + }); + + let dockerHostVar = tl.getVariable("DOCKER_HOST"); + if (dockerHostVar) { + tl.debug(tl.loc('ConnectingToDockerHost', dockerHostVar)); + } + return command.exec(); +} + configureBuildctl() - .then(() => verifyBuildctl()) - .then(() => buildUsingBuildctl()) + .then(() => buildContainer()) .then(() => { tl.setResult(tl.TaskResult.Succeeded, ""); }).catch((error) => {