2017-09-02 00:17:09 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/moby/buildkit/client/llb"
|
|
|
|
"github.com/moby/buildkit/frontend/dockerfile/dockerfile2llb"
|
|
|
|
"github.com/moby/buildkit/util/appcontext"
|
|
|
|
)
|
|
|
|
|
|
|
|
type buildOpt struct {
|
|
|
|
target string
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var opt buildOpt
|
|
|
|
flag.StringVar(&opt.target, "target", "", "target stage")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
df, err := ioutil.ReadAll(os.Stdin)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2017-09-11 05:35:07 +00:00
|
|
|
state, img, err := dockerfile2llb.Dockerfile2LLB(appcontext.Context(), df, dockerfile2llb.ConvertOpt{
|
2017-09-02 00:17:09 +00:00
|
|
|
MetaResolver: llb.DefaultImageMetaResolver(),
|
|
|
|
Target: opt.target,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("err: %+v", err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2017-09-11 05:35:07 +00:00
|
|
|
_ = img
|
|
|
|
|
2017-09-02 00:17:09 +00:00
|
|
|
dt, err := state.Marshal()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
llb.WriteTo(dt, os.Stdout)
|
|
|
|
}
|