Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Jockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ local std = import "std.libsonnet";
},
],
"image": {
"Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],
// "Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],
"Cmd": ["darkhttpd", "/www"],
},
"excludes" : ["*", "!docs", "!mkdocs.yml"],
Expand Down
49 changes: 25 additions & 24 deletions cmd/jocker/debug-dump.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
package jocker

import (
"context"
"log"
"os"
// "context"
// "log"
// "os"

"github.com/jocker-org/jocker/internal/parser"
"github.com/moby/buildkit/client/llb"
// "github.com/jocker-org/jocker/internal/parser"
// "github.com/moby/buildkit/client/llb"
)

func DebugDump() error {
// Initialize Jsonnet VM and evaluate Jockerfile
jsonStr, err := parser.EvaluateJsonnetFile("Jockerfile")
if err != nil {
log.Fatal(err)
}
// // Initialize Jsonnet VM and evaluate Jockerfile
// jsonStr, err := parser.EvaluateJsonnetFile("Jockerfile")
// if err != nil {
// log.Fatal(err)
// }

// Parse JSON into Jockerfile struct
j, err := parser.ParseJockerfile(jsonStr)
if err != nil {
log.Fatal(err)
}
// // Parse JSON into Jockerfile struct
// j, err := parser.ParseJockerfile(jsonStr)
// if err != nil {
// log.Fatal(err)
// }

// Generate LLB state from Jockerfile
state := j.ToLLB()
ctx := context.TODO()
dt, err := state.Marshal(ctx, llb.LinuxAmd64)
if err != nil {
log.Fatal(err)
}
// // Generate LLB state from Jockerfile
// state := j.ToLLB()
// ctx := context.TODO()
// dt, err := state.Marshal(ctx, llb.LinuxAmd64)
// if err != nil {
// log.Fatal(err)
// }

// Write LLB definition to stdout
return llb.WriteTo(dt, os.Stdout)
// // Write LLB definition to stdout
// return llb.WriteTo(dt, os.Stdout)
return nil
}
6 changes: 5 additions & 1 deletion internal/parser/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"path/filepath"
"time"

"github.com/containerd/platforms"
"github.com/google/go-jsonnet"
Expand Down Expand Up @@ -111,7 +112,7 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
j.Excludes, _ = dockerignore.Parse(bytes.NewReader(content))
}
}
state := j.ToLLB()
state := j.ToLLB(c)

dt, err := state.Marshal(ctx, llb.LinuxAmd64)
if err != nil {
Expand All @@ -132,9 +133,12 @@ func Build(ctx context.Context, c client.Client) (*client.Result, error) {
}

p := platforms.DefaultSpec()
t := time.Now()

img := &specs.Image{
Platform: p,
Config: j.Image,
Created: &t,
}

config, err := json.Marshal(img)
Expand Down
8 changes: 6 additions & 2 deletions internal/parser/llb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"log"

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

type BuildContext struct {
stages map[string]llb.State
state llb.State
context llb.State
client client.Client
}

type BuildStep interface {
Expand Down Expand Up @@ -51,7 +53,8 @@ func (stage *BuildStage) ToLLB(b *BuildContext) llb.State {
if stage.From == "scratch" {
b.state = llb.Scratch()
} else {
b.state = llb.Image(stage.From)
// b.state = llb.Image(stage.From)
b.state = llb.Image(stage.From, llb.WithMetaResolver(b.client))
}

b.state = b.state.With(llb.User(stage.User))
Expand All @@ -65,9 +68,10 @@ func (stage *BuildStage) ToLLB(b *BuildContext) llb.State {
return b.state
}

func (j *Jockerfile) ToLLB() llb.State {
func (j *Jockerfile) ToLLB(c client.Client) llb.State {
b := BuildContext{
stages: make(map[string]llb.State),
client: c,
}
var state llb.State
opts := []llb.LocalOption{
Expand Down