From c6690523eb7ec7809dc9ce4d120e4b07b11b4dd4 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Wed, 13 Dec 2017 13:34:55 +0900 Subject: [PATCH] Makefile: add `install` and `clean` Signed-off-by: Akihiro Suda --- .travis.yml | 2 +- Makefile | 15 +++++++++--- README.md | 27 +++++++++++++-------- hack/dockerfiles/test.Dockerfile | 41 ++++++++++++++++++-------------- 4 files changed, 53 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index a004d38f..6107b260 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,4 @@ install: - curl -fsSL https://get.docker.com/ | sh script: - - make binaries validate-all + - make binaries-all validate-all diff --git a/Makefile b/Makefile index 453f32ee..daf12af8 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ - -BINARIES=bin/buildd bin/buildd-standalone bin/buildd-containerd bin/buildctl bin/buildctl-darwin bin/buildd.exe bin/buildctl.exe +BINARIES=bin/buildd bin/buildctl +BINARIES_EXTRA=bin/buildd-standalone bin/buildd-containerd bin/buildctl-darwin bin/buildd.exe bin/buildctl.exe +DESTDIR=/usr/local binaries: $(BINARIES) +binaries-all: $(BINARIES) $(BINARIES_EXTRA) bin/buildctl-darwin: FORCE mkdir -p bin @@ -27,6 +29,13 @@ bin/%: FORCE docker rm $$containerID ) chmod +x $@ +install: FORCE + mkdir -p $(DESTDIR)/bin + install $(BINARIES) $(DESTDIR)/bin + +clean: FORCE + rm -rf ./bin + test: ./hack/test @@ -41,5 +50,5 @@ validate-all: test lint validate-vendor vendor: ./hack/update-vendor -.PHONY: vendor test binaries lint validate-all validate-vendor +.PHONY: vendor test binaries binaries-all install clean lint validate-all validate-vendor FORCE: diff --git a/README.md b/README.md index e3a5e830..f944eb0e 100644 --- a/README.md +++ b/README.md @@ -29,18 +29,18 @@ 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](https://github.com/containerd/containerd) for execution and distribution, and a standalone version that doesn't have other dependencies apart from [runc](https://github.com/opencontainers/runc). We are open for adding more backends. `buildd` is a CLI utility for serving the gRPC API. +Dependencies: +- [runc](https://github.com/opencontainers/runc) +- [containerd](https://github.com/containerd/containerd) (if you want to use containerd worker) + + +The following command installs `buildd` and `buildctl` to `/usr/local/bin`: ```bash -# 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 +$ make && sudo make install ``` -You can also use `make binaries` that prepares all binaries into the `bin/` directory. +You can also use `make binaries-all` to prepare `buildd-containerd` (containerd worker only) and `buildd-standalone` (OCI worker 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. @@ -73,9 +73,16 @@ Different versions of the example scripts show different ways of describing the ##### Starting the buildd daemon: ``` -buildd-standalone --debug --root /var/lib/buildkit +buildd --debug --root /var/lib/buildkit ``` +The buildd 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: ``` @@ -94,7 +101,7 @@ buildctl build --frontend gateway.v0 --frontend-opt=source=tonistiigi/dockerfile ##### Exporting resulting image to containerd -Containerd version of buildd needs to be used +The containerd worker needs to be used ``` buildctl build ... --exporter=image --exporter-opt name=docker.io/username/image diff --git a/hack/dockerfiles/test.Dockerfile b/hack/dockerfiles/test.Dockerfile index 73b64456..006c3b2e 100644 --- a/hack/dockerfiles/test.Dockerfile +++ b/hack/dockerfiles/test.Dockerfile @@ -4,10 +4,27 @@ ARG CONTAINERD_VERSION=v1.0.0 ARG BUILDKIT_TARGET=buildd ARG REGISTRY_VERSION=2.6 +# The `buildd` stage and the `buildctl` stage are placed here +# so that they can be built quickly with legacy DAG-unaware `docker build --target=...` + FROM golang:1.9-alpine AS gobuild-base RUN apk add --no-cache g++ linux-headers RUN apk add --no-cache git make +FROM gobuild-base AS buildkit-base +WORKDIR /go/src/github.com/moby/buildkit +COPY . . + +FROM buildkit-base AS buildctl +ENV CGO_ENABLED=0 +ARG GOOS=linux +RUN go build -ldflags '-d' -o /usr/bin/buildctl ./cmd/buildctl + +FROM buildkit-base AS buildd +ENV CGO_ENABLED=0 +RUN go build -ldflags '-d' -o /usr/bin/buildd -tags "standalone containerd" ./cmd/buildd + +# test dependencies begin here FROM gobuild-base AS runc ARG RUNC_VERSION RUN git clone https://github.com/opencontainers/runc.git "$GOPATH/src/github.com/opencontainers/runc" \ @@ -25,18 +42,10 @@ RUN git clone https://github.com/containerd/containerd.git "$GOPATH/src/github.c && make bin/containerd-shim \ && make bin/ctr -FROM gobuild-base AS buildkit-base -WORKDIR /go/src/github.com/moby/buildkit -COPY . . - FROM buildkit-base AS unit-tests COPY --from=runc /usr/bin/runc /usr/bin/runc COPY --from=containerd /go/src/github.com/containerd/containerd/bin/containerd* /usr/bin/ -FROM buildkit-base AS buildctl -ENV CGO_ENABLED=0 -ARG GOOS=linux -RUN go build -ldflags '-d' -o /usr/bin/buildctl ./cmd/buildctl FROM buildkit-base AS buildd-standalone ENV CGO_ENABLED=0 @@ -48,10 +57,6 @@ RUN go build -ldflags '-d' -o /usr/bin/buildd-containerd -tags containerd ./cmd FROM registry:$REGISTRY_VERSION AS registry -FROM buildkit-base AS buildd -ENV CGO_ENABLED=0 -RUN go build -ldflags '-d' -o /usr/bin/buildd -tags "standalone containerd" ./cmd/buildd - FROM unit-tests AS integration-tests COPY --from=buildctl /usr/bin/buildctl /usr/bin/ COPY --from=buildd-containerd /usr/bin/buildd-containerd /usr/bin @@ -73,6 +78,12 @@ FROM alpine AS buildkit-export RUN apk add --no-cache git VOLUME /var/lib/buildkit +# Copy together all binaries for standalone+containerd mode +FROM buildkit-export AS buildkit-buildd +COPY --from=runc /usr/bin/runc /usr/bin/ +COPY --from=buildd /usr/bin/buildd /usr/bin/ +COPY --from=buildctl /usr/bin/buildctl /usr/bin/ + # Copy together all binaries needed for standalone mode FROM buildkit-export AS buildkit-buildd-standalone COPY --from=buildd-standalone /usr/bin/buildd-standalone /usr/bin/ @@ -86,12 +97,6 @@ COPY --from=buildd-containerd /usr/bin/buildd-containerd /usr/bin/ COPY --from=buildctl /usr/bin/buildctl /usr/bin/ ENTRYPOINT ["buildd-containerd"] -# Copy together all binaries for standalone+containerd mode -FROM buildkit-export AS buildkit-buildd -COPY --from=runc /usr/bin/runc /usr/bin/ -COPY --from=buildd /usr/bin/buildd /usr/bin/ -COPY --from=buildctl /usr/bin/buildctl /usr/bin/ - FROM alpine AS containerd-runtime COPY --from=runc /usr/bin/runc /usr/bin/ COPY --from=containerd /go/src/github.com/containerd/containerd/bin/containerd* /usr/bin/