-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add back older versions of buildkit
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
- Loading branch information
1 parent
c8dd472
commit 2782d40
Showing
4 changed files
with
199 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
|
||
"github.com/moby/buildkit/client/llb" | ||
"github.com/moby/buildkit/util/system" | ||
) | ||
|
||
type buildOpt struct { | ||
target string | ||
containerd string | ||
runc string | ||
} | ||
|
||
func main() { | ||
var opt buildOpt | ||
flag.StringVar(&opt.target, "target", "containerd", "target (standalone, containerd)") | ||
flag.StringVar(&opt.containerd, "containerd", "master", "containerd version") | ||
flag.StringVar(&opt.runc, "runc", "v1.0.0-rc3", "runc version") | ||
flag.Parse() | ||
|
||
bk := buildkit(opt) | ||
out := bk.Run(llb.Shlex("ls -l /bin")) // debug output | ||
|
||
dt, err := out.Marshal() | ||
if err != nil { | ||
panic(err) | ||
} | ||
llb.WriteTo(dt, os.Stdout) | ||
} | ||
|
||
func goBuildBase() *llb.State { | ||
goAlpine := llb.Image("docker.io/library/golang:1.8-alpine") | ||
return goAlpine. | ||
AddEnv("PATH", "/usr/local/go/bin:"+system.DefaultPathEnv). | ||
AddEnv("GOPATH", "/go"). | ||
Run(llb.Shlex("apk add --no-cache g++ linux-headers")). | ||
Run(llb.Shlex("apk add --no-cache git make")).Root() | ||
} | ||
|
||
func runc(version string) *llb.State { | ||
return goBuildBase(). | ||
Run(llb.Shlex("git clone https://github.com/opencontainers/runc.git /go/src/github.com/opencontainers/runc")). | ||
Dir("/go/src/github.com/opencontainers/runc"). | ||
Run(llb.Shlexf("git checkout -q %s", version)). | ||
Run(llb.Shlex("go build -o /usr/bin/runc ./")).Root() | ||
} | ||
|
||
func containerd(version string) *llb.State { | ||
return goBuildBase(). | ||
Run(llb.Shlex("apk add --no-cache btrfs-progs-dev")). | ||
Run(llb.Shlex("git clone https://github.com/containerd/containerd.git /go/src/github.com/containerd/containerd")). | ||
Dir("/go/src/github.com/containerd/containerd"). | ||
Run(llb.Shlexf("git checkout -q %s", version)). | ||
Run(llb.Shlex("make bin/containerd")).Root() | ||
} | ||
|
||
func buildkit(opt buildOpt) *llb.State { | ||
src := goBuildBase(). | ||
Run(llb.Shlex("git clone https://github.com/moby/buildkit.git /go/src/github.com/moby/buildkit")). | ||
Dir("/go/src/github.com/moby/buildkit") | ||
|
||
builddStandalone := src. | ||
Run(llb.Shlex("go build -o /bin/buildd-standalone -tags standalone ./cmd/buildd")) | ||
|
||
builddContainerd := src. | ||
Run(llb.Shlex("go build -o /bin/buildd-containerd -tags containerd ./cmd/buildd")) | ||
|
||
buildctl := src. | ||
Run(llb.Shlex("go build -o /bin/buildctl ./cmd/buildctl")) | ||
|
||
r := llb.Image("docker.io/library/alpine:latest") | ||
r = copy(buildctl.Root(), "/bin/buildctl", r, "/bin/") | ||
r = copy(runc(opt.runc), "/usr/bin/runc", r, "/bin/") | ||
if opt.target == "containerd" { | ||
r = copy(containerd(opt.containerd), "/go/src/github.com/containerd/containerd/bin/containerd", r, "/bin/") | ||
r = copy(builddContainerd.Root(), "/bin/buildd-containerd", r, "/bin/") | ||
} else { | ||
r = copy(builddStandalone.Root(), "/bin/buildd-standalone", r, "/bin/") | ||
} | ||
return r | ||
} | ||
|
||
func copy(src *llb.State, srcPath string, dest *llb.State, destPath string) *llb.State { | ||
cpImage := llb.Image("docker.io/library/alpine:latest") | ||
cp := cpImage.Run(llb.Shlexf("cp -a /src%s /dest%s", srcPath, destPath)) | ||
cp.AddMount("/src", src) | ||
return cp.AddMount("/dest", dest) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
|
||
"github.com/moby/buildkit/client/llb" | ||
"github.com/moby/buildkit/util/system" | ||
) | ||
|
||
type buildOpt struct { | ||
target string | ||
containerd string | ||
runc string | ||
} | ||
|
||
func main() { | ||
var opt buildOpt | ||
flag.StringVar(&opt.target, "target", "containerd", "target (standalone, containerd)") | ||
flag.StringVar(&opt.containerd, "containerd", "master", "containerd version") | ||
flag.StringVar(&opt.runc, "runc", "v1.0.0-rc3", "runc version") | ||
flag.Parse() | ||
|
||
bk := buildkit(opt) | ||
out := bk.Run(llb.Shlex("ls -l /bin")) // debug output | ||
|
||
dt, err := out.Marshal() | ||
if err != nil { | ||
panic(err) | ||
} | ||
llb.WriteTo(dt, os.Stdout) | ||
} | ||
|
||
func goBuildBase() *llb.State { | ||
goAlpine := llb.Image("docker.io/library/golang:1.8-alpine") | ||
return goAlpine. | ||
AddEnv("PATH", "/usr/local/go/bin:"+system.DefaultPathEnv). | ||
AddEnv("GOPATH", "/go"). | ||
Run(llb.Shlex("apk add --no-cache g++ linux-headers")). | ||
Run(llb.Shlex("apk add --no-cache git make")).Root() | ||
} | ||
|
||
func runc(version string) *llb.State { | ||
return goBuildBase(). | ||
With(goFromGit("github.com/opencontainers/runc", version)). | ||
Run(llb.Shlex("go build -o /usr/bin/runc ./")). | ||
Root() | ||
} | ||
|
||
func containerd(version string) *llb.State { | ||
return goBuildBase(). | ||
Run(llb.Shlex("apk add --no-cache btrfs-progs-dev")). | ||
With(goFromGit("github.com/containerd/containerd", version)). | ||
Run(llb.Shlex("make bin/containerd")).Root() | ||
} | ||
|
||
func buildkit(opt buildOpt) *llb.State { | ||
src := goBuildBase().With(goFromGit("github.com/moby/buildkit", "master")) | ||
|
||
builddStandalone := src. | ||
Run(llb.Shlex("go build -o /bin/buildd-standalone -tags standalone ./cmd/buildd")).Root() | ||
|
||
builddContainerd := src. | ||
Run(llb.Shlex("go build -o /bin/buildd-containerd -tags containerd ./cmd/buildd")).Root() | ||
|
||
buildctl := src. | ||
Run(llb.Shlex("go build -o /bin/buildctl ./cmd/buildctl")).Root() | ||
|
||
r := llb.Image("docker.io/library/alpine:latest").With( | ||
copyFrom(buildctl, "/bin/buildctl", "/bin/"), | ||
copyFrom(runc(opt.runc), "/usr/bin/runc", "/bin/"), | ||
) | ||
|
||
if opt.target == "containerd" { | ||
return r.With( | ||
copyFrom(containerd(opt.containerd), "/go/src/github.com/containerd/containerd/bin/containerd", "/bin/"), | ||
copyFrom(builddContainerd, "/bin/buildd-containerd", "/bin/")) | ||
} | ||
return r.With(copyFrom(builddStandalone, "/bin/buildd-standalone", "/bin/")) | ||
} | ||
|
||
// goFromGit is a helper for cloning a git repo, checking out a tag and copying | ||
// source directory into | ||
func goFromGit(repo, tag string) llb.StateOption { | ||
src := llb.Image("docker.io/library/alpine:latest"). | ||
Run(llb.Shlex("apk add --no-cache git")). | ||
Run(llb.Shlexf("git clone https://%[1]s.git /go/src/%[1]s", repo)). | ||
Dirf("/go/src/%s", repo). | ||
Run(llb.Shlexf("git checkout -q %s", tag)).Root() | ||
return func(s *llb.State) *llb.State { | ||
return s.With(copyFrom(src, "/go", "/")).Reset(s).Dir(src.GetDir()) | ||
} | ||
} | ||
|
||
// 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:latest") | ||
cp := cpImage.Run(llb.Shlexf("cp -a /src%s /dest%s", srcPath, destPath)) | ||
cp.AddMount("/src", src) | ||
return cp.AddMount("/dest", dest) | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.