concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
 
 
 
Go to file
Tino Rusch 98a836592e
[transport] make tls client and server commandline parameters for consistency with docker + guess tls-server-name from target address in client if not specified explicitly;
2017-12-21 06:18:54 +01:00
api/services/control worker: add labels 2017-12-20 16:28:47 +09:00
cache replace FollowSymlink with fs.RootPath 2017-12-17 20:54:49 -08:00
client transport: add possibility to use TLS secured transport layer on server- and clientside; 2017-12-20 13:30:46 +01:00
cmd [transport] make tls client and server commandline parameters for consistency with docker + guess tls-server-name from target address in client if not specified explicitly; 2017-12-21 06:18:54 +01:00
control worker: add labels 2017-12-20 16:28:47 +09:00
examples Merge pull request #229 from AkihiroSuda/buildkitd 2017-12-19 10:03:17 +01:00
executor replace FollowSymlink with fs.RootPath 2017-12-17 20:54:49 -08:00
exporter exporter: add Docker compatible exporter 2017-12-18 12:19:17 -08:00
frontend dockerfile: add copy —-chown support 2017-12-19 20:54:26 -08:00
hack *: buildd -> buildkitd 2017-12-19 13:23:27 +09:00
identity identity: add pkg for random id generation 2017-06-19 14:32:50 -07:00
session dockerfile: add dockerignore support 2017-12-15 15:03:35 -08:00
snapshot vendor: update containerd to 1.0.0 2017-12-04 23:34:25 -08:00
solver worker: add labels 2017-12-20 16:28:47 +09:00
source dockerfile: add test for building from git repo 2017-12-17 21:09:20 -08:00
util *: buildd -> buildkitd 2017-12-19 13:23:27 +09:00
vendor replace FollowSymlink with fs.RootPath 2017-12-17 20:54:49 -08:00
worker worker: add labels 2017-12-20 16:28:47 +09:00
.dockerignore .gitignore and .dockerignore: add .buildstate 2017-06-30 06:24:19 +00:00
.gitignore .gitignore and .dockerignore: add .buildstate 2017-06-30 06:24:19 +00:00
.travis.yml Makefile: add `install` and `clean` 2017-12-13 16:03:02 +09:00
LICENSE Add license 2017-06-01 09:58:33 -07:00
Makefile *: buildd -> buildkitd 2017-12-19 13:23:27 +09:00
README.md *: buildd -> buildkitd 2017-12-19 13:23:27 +09:00
doc.go Add a go file on buildkit root folder 2017-10-26 11:36:09 +02:00
gometalinter.json exporter: add image exporter 2017-07-10 23:29:14 -07:00
vendor.conf worker: setup own resolvconf and hosts 2017-12-10 18:23:24 -08:00

README.md

Important: This repository is in an early development phase

asciicinema example

BuildKit

GoDoc Build Status Go Report Card

BuildKit is a toolkit for converting source code to build artifacts in an efficient, expressive and repeatable manner.

Key features:

  • Automatic garbage collection
  • Extendable frontend formats
  • Concurrent dependency resolution
  • Efficient instruction caching
  • Build cache import/export
  • Nested build job invocations
  • Distributable workers
  • Multiple output formats
  • Pluggable architecture

Read the proposal from https://github.com/moby/moby/issues/32925

Quick start

Dependencies:

The following command installs buildkitd and buildctl to /usr/local/bin:

$ make && sudo make install

You can also use make binaries-all to prepare buildkitd.containerd_only and buildkitd.oci_only.

examples/buildkit* directory contains scripts that define how to build different configurations of BuildKit and its dependencies using the client package. Running one of these script generates a protobuf definition of a build graph. Note that the script itself does not execute any steps of the build.

You can use buildctl debug dump-llb to see what data is in this definition. Add --dot to generate dot layout.

go run examples/buildkit0/buildkit.go | buildctl debug dump-llb | jq .

To start building use buildctl build command. The example script accepts --target flag to choose between containerd-worker-only and oci-worker-only configurations. In OCI worker mode BuildKit binaries are built together with runc. In containerd worker mode, the containerd binary is built as well from the upstream repo.

go run examples/buildkit0/buildkit.go | buildctl build

buildctl build will show interactive progress bar by default while the build job is running. It will also show you the path to the trace file that contains all information about the timing of the individual steps and logs.

Different versions of the example scripts show different ways of describing the build definition for this project to show the capabilities of the library. New versions have been added when new features have become available.

  • ./examples/buildkit0 - uses only exec operations, defines a full stage per component.
  • ./examples/buildkit1 - cloning git repositories has been separated for extra concurrency.
  • ./examples/buildkit2 - uses git sources directly instead of running git clone, allowing better performance and much safer caching.
  • ./examples/buildkit3 - allows using local source files for separate components eg. ./buildkit3 --runc=local | buildctl build --local runc-src=some/local/path
  • ./examples/dockerfile2llb - can be used to convert a Dockerfile to LLB for debugging purposes
  • ./examples/gobuild - shows how to use nested invocation to generate LLB for Go package internal dependencies

Examples

Starting the buildkitd daemon:
buildkitd --debug --root /var/lib/buildkit

The buildkitd daemon suppports two worker backends: OCI (runc) and containerd.

By default, the OCI (runc) worker is used. You can set --oci-worker=false --containerd-worker=true to use the containerd worker.

We are open to add more backends.

Building a Dockerfile:
buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=.
buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=. --frontend-opt target=foo --frontend-opt build-arg:foo=bar

context and dockerfile should point to local directories for build context and Dockerfile location.

Building a Dockerfile using external frontend:
buildctl build --frontend=gateway.v0 --frontend-opt=source=tonistiigi/dockerfile:v0 --local context=. --local dockerfile=.
buildctl build --frontend gateway.v0 --frontend-opt=source=tonistiigi/dockerfile:v0 --frontend-opt=context=git://github.com/moby/moby --frontend-opt build-arg:APT_MIRROR=cdn-fastly.deb.debian.org
Exporting resulting image to containerd

The containerd worker needs to be used

buildctl build ... --exporter=image --exporter-opt name=docker.io/username/image
ctr --namespace=buildkit images ls
Push resulting image to registry
buildctl build ... --exporter=image --exporter-opt name=docker.io/username/image --exporter-opt push=true

If credentials are required, buildctl will attempt to read Docker configuration file.

Exporting build result back to client
buildctl build ... --exporter=local --exporter-opt output=path/to/output-dir
Exporting build result to Docker
# exported tarball is also compatible with OCI spec
buildctl build ... --exporter=docker --exporter-opt name=myimage | docker load
Exporting OCI Image Format tarball to client
buildctl build ... --exporter=oci --exporter-opt output=path/to/output.tar
buildctl build ... --exporter=oci > output.tar

View build cache

buildctl du -v

Running containerized buildkit

buildkit can be also used by running the buildkitd daemon inside a Docker container and accessing it remotely. The client tool buildctl is also available for Mac and Windows.

To run daemon in a container:

docker run -d --privileged -p 1234:1234 tonistiigi/buildkit --addr tcp://0.0.0.0:1234 --oci-worker=true --containerd-worker=false
export BUILDKIT_HOST=tcp://0.0.0.0:1234
buildctl build --help

The tonistiigi/buildkit image can be built locally using the Dockerfile in ./hack/dockerfiles/test.Dockerfile.

Supported runc version

During development buildkit is tested with the version of runc that is being used by the containerd repository. Please refer to runc.md for more information.

Contributing

Running tests:

make test

This runs all unit and integration tests in a containerized environment. Locally, every package can be tested separately with standard Go tools but integration tests are skipped if local user doesn't have enough permissions or worker binaries are not installed.

# test a specific package only
make test TESTPKGS=./client

# run a specific test with all worker combinations
make test TESTPKGS=./client TESTFLAGS="--run /TestCallDiskUsage -v" 

# run all integration tests with a specific worker
# supported workers are oci and containerd
make test TESTPKGS=./client TESTFLAGS="--run //worker=containerd -v" 

Updating vendored dependencies:

# update vendor.conf
make vendor

Validating your updates before submission:

make validate-all