Skip to content

Commit

Permalink
Adding support for pushing image in registry
Browse files Browse the repository at this point in the history
  • Loading branch information
prebansa authored and leantk committed Dec 23, 2019
1 parent c276488 commit 0877074
Show file tree
Hide file tree
Showing 13 changed files with 692 additions and 125 deletions.
8 changes: 7 additions & 1 deletion Tasks/Common/docker-common-v2/containerconnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ export default class ContainerConnection {
private oldDockerConfigContent: string;

constructor() {
this.dockerPath = tl.which("docker", true);
if(process.env["RUNNING_ON"] == "KUBERNETES") {
this.dockerPath = tl.which("img", true);
}
else {
this.dockerPath = tl.which("docker", true);
}

}

public createCommand(): tr.ToolRunner {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"loc.friendlyName": "Container Build",
"loc.helpMarkDown": "[Learn more about this task](https://go.microsoft.com/fwlink/?linkid=851275) or [see the Kubernetes documentation](https://kubernetes.io/docs/home/)",
"loc.helpMarkDown": "[Learn more about this task](https://go.microsoft.com/fwlink/?linkid=2107300)",
"loc.description": "Build Task",
"loc.instanceNameFormat": "Container Build Task",
"loc.group.displayName.containerRepository": "Container Repository",
"loc.group.displayName.commands": "Commands",
"loc.input.label.dockerRegistryServiceConnection": "Docker registry service connection",
"loc.input.help.dockerRegistryServiceConnection": "Select a Docker registry service connection. Required for commands that need to authenticate with a registry.",
"loc.input.help.dockerRegistryServiceConnection": "Select a Docker registry service connection.",
"loc.input.label.repository": "Container repository",
"loc.input.help.repository": "Name of the repository.",
"loc.input.help.repository": "Name of the repository within the container registry.",
"loc.input.label.Dockerfile": "Dockerfile",
"loc.input.help.Dockerfile": "Path to the Dockerfile.",
"loc.input.help.Dockerfile": "Path to Dockerfile.",
"loc.input.label.buildContext": "Build context",
"loc.input.help.buildContext": "Path to the Build context.",
"loc.input.help.buildContext": "Path to Build context.",
"loc.input.label.tags": "Tags",
"loc.input.help.tags": "A list of tags in separate lines. These tags are used in build, push and buildAndPush commands. Ex:<br><br>beta1.1<br>latest",
"loc.input.help.tags": "A list of tags in separate lines. Tags are used while building and pushing the image to container registry.",
"loc.input.label.arguments": "Arguments",
"loc.input.help.arguments": "Docker command options. Ex:<br> For build command,<br>--build-arg HTTP_PROXY=http://10.20.30.2:1234 --quiet",
"loc.input.label.addPipelineData": "Add Pipeline metadata to image(s)",
"loc.input.help.addPipelineData": "By default pipeline data like source branch name, build id are added which helps with traceability. For example you can inspect an image to find out which pipeline built the image. You can opt out of this default behavior by using this input.",
"loc.messages.NotAValidSemverVersion": "Version not specified in correct format. E.g: 1.8.2, v1.8.2, 2.8.2, v2.8.2.",
"loc.messages.VerifyBuildctlInstallation": "Verifying Buildctl installation...",
"loc.input.help.arguments": "Arguments used while building the image.",
"loc.input.label.addPipelineMetadata": "Add Pipeline metadata to image(s)",
"loc.input.help.addPipelineMetadata": "By default pipeline data like source branch name, build id are added which helps with traceability. For example you can inspect an image to find out which pipeline built the image. You can opt out of this default behavior by using this input.",
"loc.messages.ContainerPatternNotFound": "No pattern found in Docker filepath parameter",
"loc.messages.BuildctlLatestNotKnown": "Cannot get the latest Buildctl info from %s. Error %s. Using default Buildctl version %s.",
"loc.messages.BuildctlDownloadFailed": "Failed to download Buildctl from location %s. Error %s",
"loc.messages.BuildctlNotFoundInFolder": "Buildctl executable not found in path %s"
"loc.messages.BuildctlNotFoundInFolder": "Buildctl executable not found in path %s",
"loc.messages.FileContentSynced": "Synced the file content to the disk. The content is %s.",
"loc.messages.VerifyBuildctlInstallation": "Verifying Buildctl installation...",
"loc.messages.WritingDockerConfigToTempFile": "Writing Docker config to temp file. File path: %s, Docker config: %s"
}
9 changes: 8 additions & 1 deletion Tasks/ContainerBuildV0/make.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"common": [
{
"module": "../Common/docker-common-v2",
"type": "node",
"dest" : "./",
"compile" : true
},
{
"module": "../Common/azure-arm-rest-v2",
"type": "node",
Expand All @@ -11,7 +17,8 @@
{
"items": [
"node_modules/azure-arm-rest/node_modules/vsts-task-lib",
"node_modules/buildctl-common/node_modules/azure-pipelines-task-lib"
"node_modules/buildctl-common/node_modules/azure-pipelines-task-lib",
"node_modules/docker-common-v2/node_modules/azure-pipelines-task-lib"
],
"options": "-Rf"
}
Expand Down
192 changes: 192 additions & 0 deletions Tasks/ContainerBuildV0/package-lock.json

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

3 changes: 2 additions & 1 deletion Tasks/ContainerBuildV0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"dependencies": {
"azure-arm-rest-v2": "file:../../_build/Tasks/Common/azure-arm-rest-v2-2.0.0.tgz",
"azure-pipelines-task-lib": "2.8.0",
"azure-pipelines-tool-lib": "0.11.0"
"azure-pipelines-tool-lib": "0.11.0",
"docker-common-v2": "file:../../_build/Tasks/Common/docker-common-v2-1.0.0.tgz"
}
}
26 changes: 26 additions & 0 deletions Tasks/ContainerBuildV0/src/buildcontainer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";

import tl = require('azure-pipelines-task-lib/task');
import path = require('path');
import docker = require("./docker");
import buildctl = require("./buildctl");

tl.setResourcePath(path.join(__dirname, '..', 'task.json'));

async function buildContainer() {
if(process.env["RUNNING_ON"] == "KUBERNETES") {
tl.debug("Building image using buildctl");
buildctl.buildctlBuildAndPush();
}
else {
tl.debug("Building image using docker");
docker.dockerBuildAndPush();
}
}

buildContainer()
.then(() => {
tl.setResult(tl.TaskResult.Succeeded, "");
}).catch((error) => {
tl.setResult(tl.TaskResult.Failed, error)
});
Loading

0 comments on commit 0877074

Please sign in to comment.