Skip to content

Commit

Permalink
Adding support for RUNNING_AS_K8 flag
Browse files Browse the repository at this point in the history
  • Loading branch information
prebansa authored and leantk committed Dec 23, 2019
1 parent b1c8fe8 commit 3f8beba
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions Tasks/BuildctlV0/src/buildctl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) => {
Expand Down

0 comments on commit 3f8beba

Please sign in to comment.