Skip to content

Instantly share code, notes, and snippets.

@developer-guy
Created April 1, 2022 18:45
Show Gist options
  • Save developer-guy/373d393a36ab5fc3ff164710aafe3a08 to your computer and use it in GitHub Desktop.
Save developer-guy/373d393a36ab5fc3ff164710aafe3a08 to your computer and use it in GitHub Desktop.

Revisions

  1. developer-guy created this gist Apr 1, 2022.
    33 changes: 33 additions & 0 deletions llb.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    package main

    import (
    "context"
    "os"

    "github.com/moby/buildkit/client/llb"
    )

    func createLLBState() llb.State {
    base := llb.Image("docker.io/library/alpine")

    base = base.
    File(llb.Mkdir("/tmp/dir", 0755)).
    File(llb.Copy(llb.Local("context"), "README.md", "/tmp/dir/README.md")).
    File(llb.Copy(llb.Local("context"), "README.md", "README.md"))

    anotbase := llb.Image("docker.io/library/alpine:3.6")
    anotbase = anotbase.Run(llb.Shlexf("cp -a /tmp/dir/%s /tmp/dir/%s", "README.md", "README.copy.md")).
    AddMount("/", base)

    return anotbase.Run(llb.Args([]string{"/bin/sh"})).Root()
    }

    func main() {
    dt, err := createLLBState().Marshal(context.TODO(), llb.LinuxAmd64)
    if err != nil {
    panic(err)
    }
    llb.WriteTo(dt, os.Stdout)
    }

    # go run main.go | buildctl debug dumb-llb | jq