Skip to content

Commit

Permalink
dockerfile: set progress index by grouping stages together
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Feb 24, 2022
1 parent 939448d commit 31e6d71
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions frontend/dockerfile/dockerfile2llb/convert.go
Expand Up @@ -145,6 +145,7 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
st.BaseName = name

ds := &dispatchState{
stageIndex: i,
deps: make(map[*dispatchState]struct{}),
ctxPaths: make(map[string]struct{}),
stageName: st.Name,
Expand Down Expand Up @@ -367,7 +368,7 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
opt.ImageResolveMode,
llb.WithCustomName(prefixCommand(d, "FROM "+d.stage.BaseName, opt.PrefixPlatform, platform, nil)),
location(opt.SourceMap, d.stage.Location),
llb.ProgressIndex(d.cmdIndex),
d.progressIndex(),
)
}
d.platform = platform
Expand Down Expand Up @@ -685,6 +686,7 @@ func dispatch(d *dispatchState, cmd command, opt dispatchOpt) error {
}

type dispatchState struct {
stageIndex int
state llb.State
image Image
platform *ocispecs.Platform
Expand All @@ -705,6 +707,11 @@ type dispatchState struct {
buildSource *binfotypes.Source
}

func (d *dispatchState) progressIndex() llb.ConstraintsOpt {
maxSteps := 512
return llb.ProgressIndex(d.cmdIndex + d.stageIndex*maxSteps)
}

type dispatchStates struct {
states []*dispatchState
statesByName map[string]*dispatchState
Expand Down Expand Up @@ -892,7 +899,7 @@ func dispatchRun(d *dispatchState, c *instructions.RunCommand, proxy *llb.ProxyE
}
opt = append(opt,
llb.WithCustomName(prefixCommand(d, uppercaseCmd(processCmdEnv(&shlex, customname, env)), d.prefixPlatform, pl, env)),
llb.ProgressIndex(d.cmdIndex),
d.progressIndex(),
)
for _, h := range dopt.extraHosts {
opt = append(opt, llb.AddExtraHost(h.Host, h.IP))
Expand Down Expand Up @@ -939,7 +946,7 @@ func dispatchWorkdir(d *dispatchState, c *instructions.WorkdirCommand, commit bo
d.state = d.state.File(llb.Mkdir(wd, 0755, mkdirOpt...),
llb.WithCustomName(prefixCommand(d, uppercaseCmd(processCmdEnv(opt.shlex, c.String(), env)), d.prefixPlatform, &platform, env)),
location(opt.sourceMap, c.Location()),
llb.ProgressIndex(d.cmdIndex),
d.progressIndex(),
)
withLayer = true
}
Expand Down Expand Up @@ -1071,17 +1078,17 @@ func dispatchCopyFileOp(d *dispatchState, cfg copyConfig) error {
fileOpt := []llb.ConstraintsOpt{
llb.WithCustomName(prefixCommand(d, name, d.prefixPlatform, &platform, env)),
location(cfg.opt.sourceMap, cfg.location),
llb.ProgressIndex(d.cmdIndex),
d.progressIndex(),
}
if d.ignoreCache {
fileOpt = append(fileOpt, llb.IgnoreCache)
}

if cfg.opt.llbCaps.Supports(pb.CapMergeOp) == nil && cfg.link && cfg.chmod == "" {
d.cmdIndex-- // prefixCommand increases it
fileOpt = append(fileOpt, llb.ProgressGroup(identity.NewID(), prefixCommand(d, name, d.prefixPlatform, &platform, env)), llb.ProgressIndex(d.cmdIndex))
fileOpt = append(fileOpt, llb.ProgressGroup(identity.NewID(), prefixCommand(d, name, d.prefixPlatform, &platform, env)), d.progressIndex())
d.cmdIndex--
mergeOpt := append(fileOpt, llb.WithCustomName(prefixCommand(d, "LINK "+name, d.prefixPlatform, &platform, env)), llb.ProgressIndex(d.cmdIndex))
mergeOpt := append(fileOpt, llb.WithCustomName(prefixCommand(d, "LINK "+name, d.prefixPlatform, &platform, env)), d.progressIndex())
d.state = d.state.WithOutput(llb.Merge([]llb.State{d.state, llb.Scratch().File(a, fileOpt...)}, mergeOpt...).Output())
} else {
d.state = d.state.File(a, fileOpt...)
Expand Down Expand Up @@ -1208,7 +1215,7 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
dfCmd(cfg.cmdToPrint),
llb.WithCustomName(prefixCommand(d, uppercaseCmd(processCmdEnv(cfg.opt.shlex, cfg.cmdToPrint.String(), env)), d.prefixPlatform, &platform, env)),
location(cfg.opt.sourceMap, cfg.location),
llb.ProgressIndex(d.cmdIndex),
d.progressIndex(),
}
if d.ignoreCache {
runOpt = append(runOpt, llb.IgnoreCache)
Expand Down

0 comments on commit 31e6d71

Please sign in to comment.