concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
 
 
 
Go to file
Akihiro Suda fac138e742 Merge pull request #144 from tonistiigi/cache-export
Add support for build cache import/export
2017-10-17 18:57:22 +02:00
api/services/control cache: allow pushing exported cache 2017-10-13 15:37:55 -07:00
cache report imported cache lookup progress 2017-10-15 20:41:47 +02:00
client cache: allow pushing exported cache 2017-10-13 15:37:55 -07:00
cmd cache: allow pushing exported cache 2017-10-13 15:37:55 -07:00
control cache: allow pushing exported cache 2017-10-13 15:37:55 -07:00
examples Update runc to rc4 in examples 👼 2017-10-07 22:05:46 +02:00
exporter exporter: revert to distribution/schema2, add push support 2017-10-13 10:08:47 -07:00
frontend cache: allow pushing exported cache 2017-10-13 15:37:55 -07:00
hack solver: make nested build use solverequest 2017-10-05 17:51:04 -07:00
identity identity: add pkg for random id generation 2017-06-19 14:32:50 -07:00
session session: expose map to file send 2017-09-21 22:14:11 -07:00
snapshot blobmap: fix diffid storing on pull 2017-10-13 15:38:08 -07:00
solver report imported cache lookup progress 2017-10-15 20:41:47 +02:00
source blobmap: fix diffid storing on pull 2017-10-13 15:38:08 -07:00
util cache: allow pushing exported cache 2017-10-13 15:37:55 -07:00
vendor exporter: revert to distribution/schema2, add push support 2017-10-13 10:08:47 -07:00
worker Merge pull request #134 from tonistiigi/gateway-frontend 2017-10-04 14:38:51 +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 .travis.yml: build Windows binaries 2017-08-04 06:09:41 +00:00
LICENSE Add license 2017-06-01 09:58:33 -07:00
Makefile support building on windows (no functional worker yet) 2017-07-12 06:43:30 +00:00
README.md document use of containerized buildctl 2017-10-12 14:04:43 -04:00
gometalinter.json exporter: add image exporter 2017-07-10 23:29:14 -07:00
vendor.conf vendor: update vendored deps 2017-10-06 16:28:22 -07: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

BuildKit daemon can be built in two different versions: one that uses containerd for execution and distribution, and a standalone version that doesn't have other dependencies apart from runc. We are open for adding more backends. buildd is a CLI utility for serving the gRPC API.

# buildd daemon (choose one)
go build -o buildd-containerd -tags containerd ./cmd/buildd
go build -o buildd-standalone -tags standalone ./cmd/buildd

# buildctl utility
go build -o buildctl ./cmd/buildctl

You can also use make binaries that prepares all binaries into the bin/ directory.

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 and standalone configurations. In standalone mode BuildKit binaries are built together with runc. In containerd 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 buildd daemon:
buildd-standalone --debug --root /var/lib/buildkit
Building a Dockerfile:
buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=.

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

Exporting resulting image to containerd

Containerd version of buildd needs to be used

buildctl build ... --exporter=image --exporter-opt name=docker.io/username/image
ctr --namespace=buildkit images ls
Exporting build result back to client
buildctl build ... --exporter=local --exporter-opt output=path/to/output-dir

View build cache

buildctl du -v

Running containerized buildkit

buildkit daemon supports communicating with clients over TCP. This is supports some use cases like:

  • Docker for Mac or Windows users which cannot yet run natively buildkit daemon on their platform,
  • Centralized daemon for remote build scripts execution in a team settings
  • ...

To run daemon in a container:

$ docker run --rm --privileged -p 12345:12345 --tmpfs /tmp  buildkit:buildd-standalone buildd-standalone --addr tcp://0.0.0.0:12345 --root /tmp/buildkit

Notes:

  • --privileged is needed to grant enough rights to buildkit
  • You need to make sure the --root directory exists on a filesystem that is supported by overlay filesystem. e.g. tmpfs, ext4, xfs.

Build a script:

$ go build examples/buildkit0

Run build script:

On MacOS:

$ ./buildkit0 | ./bin/buildctl-darwin --addr tcp://localhost:12345 build

On Windows:

$ ./buildkit0 | ./bin/buildctl.exe --addr tcp://localhost:12345 build

On Linux:

$ ./buildkit0 | ./bin/buildctl --addr tcp://localhost:12345 build

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

Updating vendored dependencies:

# update vendor.conf
make vendor

Validating your updates before submission:

make validate-all