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
|
|
|
|
}
|
|
|
|
|
|
|
|
buildd, err := gb.BuildExe(gobuild.BuildOpt{
|
|
|
|
Source: src,
|
|
|
|
MountPath: "/go/src/github.com/moby/buildkit",
|
|
|
|
Pkg: "github.com/moby/buildkit/cmd/buildd",
|
|
|
|
BuildTags: []string{"standalone"},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_ = buildd
|
|
|
|
|
|
|
|
containerd, err := gb.BuildExe(gobuild.BuildOpt{
|
|
|
|
Source: llb.Git("github.com/containerd/containerd", "master"),
|
|
|
|
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, "/")).
|
|
|
|
// With(copyAll(*buildd, "/")).
|
|
|
|
With(copyAll(*runc, "/"))
|
2017-09-14 20:49:48 +00:00
|
|
|
|
|
|
|
dt, err := sc.Marshal()
|
|
|
|
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)
|
|
|
|
}
|