2017-09-14 20:49:48 +00:00
|
|
|
// +build ignore
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/moby/buildkit/client/llb"
|
2017-09-20 21:18:19 +00:00
|
|
|
gobuild "github.com/tonistiigi/llb-gobuild"
|
2017-09-14 20:49:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := run(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func run() error {
|
|
|
|
src := llb.Local("src")
|
|
|
|
|
2017-09-20 21:18:19 +00:00
|
|
|
gb := gobuild.New(nil)
|
|
|
|
// gb := gobuild.New(&gobuild.Opt{DevMode: true})
|
|
|
|
|
|
|
|
buildctl, err := gb.BuildExe(gobuild.BuildOpt{
|
|
|
|
Source: src,
|
|
|
|
MountPath: "/go/src/github.com/moby/buildkit",
|
|
|
|
Pkg: "github.com/moby/buildkit/cmd/buildctl",
|
|
|
|
BuildTags: []string{},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:33:02 +00:00
|
|
|
buildkitd, err := gb.BuildExe(gobuild.BuildOpt{
|
2017-09-20 21:18:19 +00:00
|
|
|
Source: src,
|
|
|
|
MountPath: "/go/src/github.com/moby/buildkit",
|
2017-12-18 07:33:02 +00:00
|
|
|
Pkg: "github.com/moby/buildkit/cmd/buildkitd",
|
2017-12-15 07:00:13 +00:00
|
|
|
BuildTags: []string{"no_containerd_worker"},
|
2017-09-20 21:18:19 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-12-18 07:33:02 +00:00
|
|
|
_ = buildkitd
|
2017-09-20 21:18:19 +00:00
|
|
|
|
|
|
|
containerd, err := gb.BuildExe(gobuild.BuildOpt{
|
2018-12-26 10:48:01 +00:00
|
|
|
Source: llb.Git("github.com/containerd/containerd", "v1.2.1"),
|
2017-09-20 21:18:19 +00:00
|
|
|
MountPath: "/go/src/github.com/containerd/containerd",
|
|
|
|
Pkg: "github.com/containerd/containerd/cmd/containerd",
|
|
|
|
BuildTags: []string{"no_btrfs"},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
runc, err := gb.BuildExe(gobuild.BuildOpt{
|
|
|
|
CgoEnabled: true,
|
|
|
|
Source: llb.Git("github.com/opencontainers/runc", "master"),
|
|
|
|
MountPath: "/go/src/github.com/opencontainers/runc",
|
|
|
|
Pkg: "github.com/opencontainers/runc",
|
|
|
|
BuildTags: []string{},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-09-14 20:49:48 +00:00
|
|
|
|
|
|
|
sc := llb.Scratch().
|
2017-09-20 21:18:19 +00:00
|
|
|
With(copyAll(*buildctl, "/")).
|
|
|
|
With(copyAll(*containerd, "/")).
|
2017-12-18 07:33:02 +00:00
|
|
|
// With(copyAll(*buildkitd, "/")).
|
2017-09-20 21:18:19 +00:00
|
|
|
With(copyAll(*runc, "/"))
|
2017-09-14 20:49:48 +00:00
|
|
|
|
2018-06-23 00:31:55 +00:00
|
|
|
dt, err := sc.Marshal(llb.LinuxAmd64)
|
2017-09-14 20:49:48 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
llb.WriteTo(dt, os.Stdout)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func copyAll(src llb.State, destPath string) llb.StateOption {
|
|
|
|
return copyFrom(src, "/.", destPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
// copyFrom has similar semantics as `COPY --from`
|
|
|
|
func copyFrom(src llb.State, srcPath, destPath string) llb.StateOption {
|
|
|
|
return func(s llb.State) llb.State {
|
|
|
|
return copy(src, srcPath, s, destPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy copies files between 2 states using cp until there is no copyOp
|
|
|
|
func copy(src llb.State, srcPath string, dest llb.State, destPath string) llb.State {
|
|
|
|
cpImage := llb.Image("docker.io/library/alpine@sha256:1072e499f3f655a032e88542330cf75b02e7bdf673278f701d7ba61629ee3ebe")
|
|
|
|
cp := cpImage.Run(llb.Shlexf("cp -a /src%s /dest%s", srcPath, destPath))
|
|
|
|
cp.AddMount("/src", src, llb.Readonly)
|
|
|
|
return cp.AddMount("/dest", dest)
|
|
|
|
}
|