Skip to content

Instantly share code, notes, and snippets.

@iwanhae
Created July 24, 2022 08:15
Show Gist options
  • Save iwanhae/59e40d0da3f5371f014b5e1585784d7e to your computer and use it in GitHub Desktop.
Save iwanhae/59e40d0da3f5371f014b5e1585784d7e to your computer and use it in GitHub Desktop.
Use buildkit with go client
package main
import (
"context"
"fmt"
"os"
"github.com/containerd/console"
"github.com/moby/buildkit/client"
_ "github.com/moby/buildkit/client/connhelper/dockercontainer"
"github.com/moby/buildkit/util/progress/progressui"
)
func main() {
fmt.Println("START")
if err := xmain(); err != nil {
panic(err)
}
fmt.Println("DONE")
}
func xmain() error {
ctx := context.Background()
c, err := client.New(ctx, "docker-container://buildkitd", client.WithFailFast)
if err != nil {
return err
}
ch := make(chan *client.SolveStatus)
go func() {
var c console.Console
progressui.DisplaySolveStatus(ctx, "", c, os.Stdout, ch)
}()
response, err := c.Solve(ctx, nil, client.SolveOpt{
Exports: []client.ExportEntry{
{
Type: "image",
Attrs: map[string]string{
"type": "image",
"name": "idock.iwanhae.kr/test:iswork",
"push": "true",
"store": "false",
},
},
},
CacheExports: []client.CacheOptionsEntry{
{Type: "registry", Attrs: map[string]string{"ref": "idock.iwanhae.kr/cache:test"}},
},
CacheImports: []client.CacheOptionsEntry{
{Type: "registry", Attrs: map[string]string{"ref": "idock.iwanhae.kr/cache:test"}},
},
LocalDirs: map[string]string{
"context": "/home/wan/git/buildkit/images",
"dockerfile": "/home/wan/git/buildkit/images",
},
Frontend: "dockerfile.v0",
FrontendAttrs: map[string]string{
"filename": "Dockerfile.coder",
"platform": "linux/amd64,linux/arm64",
},
}, ch)
fmt.Println("FIN", response, err)
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment