Skip to content

Commit

Permalink
optimize: don't parse Dockerfile twice and just reuse stages
Browse files Browse the repository at this point in the history
  • Loading branch information
Dani Raznikov committed Apr 3, 2020
1 parent 0fe0a64 commit a3ce1ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 5 additions & 6 deletions pkg/executor/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,7 @@ func (s *stageBuilder) saveLayerToImage(layer v1.Layer, createdBy string) error
return err
}

func CalculateDependencies(opts *config.KanikoOptions) (map[int][]string, error) {
stages, err := dockerfile.Stages(opts)
if err != nil {
return nil, err
}
func CalculateDependencies(stages []config.KanikoStage, opts *config.KanikoOptions) (map[int][]string, error) {
images := []v1.Image{}
depGraph := map[int][]string{}
for _, s := range stages {
Expand Down Expand Up @@ -559,15 +555,18 @@ func DoBuild(opts *config.KanikoOptions) (v1.Image, error) {
if err != nil {
return nil, err
}

// TODO is this even used?
if err := util.GetExcludedFiles(opts.DockerfilePath, opts.SrcContext); err != nil {
return nil, err
}

// Some stages may refer to other random images, not previous stages
if err := fetchExtraStages(stages, opts); err != nil {
return nil, err
}

crossStageDependencies, err := CalculateDependencies(opts)
crossStageDependencies, err := CalculateDependencies(stages, opts)
if err != nil {
return nil, err
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/executor/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,12 @@ COPY --from=stage2 /bar /bat
opts := &config.KanikoOptions{
DockerfilePath: f.Name(),
}

got, err := CalculateDependencies(opts)
testStages, err := dockerfile.Stages(opts)
if err != nil {
t.Errorf("Failed to parse test dockerfile to stages: %s", err)
}

got, err := CalculateDependencies(testStages, opts)
if err != nil {
t.Errorf("got error: %s,", err)
}
Expand Down

0 comments on commit a3ce1ce

Please sign in to comment.