Skip to content

Commit a0d7838

Browse files
committed
fix(staged-dockerfile): do not store non-target Dockerfile stages in the final-repo
* Do not store non-target Dockerfile stages in the final-repo, nor set custom tags on non-target stages. * Changed staged-dockerfile builder digest calculation algorithm: do not use instruction number in digest input calculation, only instruction name. refs #2215 Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
1 parent c394c01 commit a0d7838

25 files changed

+123
-117
lines changed

pkg/build/build_phase.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ func (phase *BuildPhase) AfterImageStages(ctx context.Context, img *image.Image)
272272
if img.IsArtifact {
273273
return nil
274274
}
275+
if img.IsDockerfileImage && !img.IsDockerfileTargetStage {
276+
return nil
277+
}
275278

276279
if phase.Conveyor.StorageManager.GetFinalStagesStorage() != nil {
277280
if err := phase.Conveyor.StorageManager.CopyStageIntoFinalStorage(ctx, img.GetLastNonEmptyStage(), phase.Conveyor.ContainerBackend, manager.CopyStageIntoFinalStorageOptions{ShouldBeBuiltMode: phase.ShouldBeBuiltMode}); err != nil {

pkg/build/image/dockerfile.go

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77
"path/filepath"
8+
"strings"
89

910
"github.com/docker/docker/builder/dockerignore"
1011
"github.com/moby/buildkit/frontend/dockerfile/instructions"
@@ -68,15 +69,17 @@ func mapDockerfileToImagesSets(ctx context.Context, cfg *dockerfile.Dockerfile,
6869
WerfImageName string
6970
Stage *dockerfile.DockerfileStage
7071
Level int
72+
IsTargetStage bool
7173
}{
72-
{WerfImageName: dockerfileImageConfig.Name, Stage: targetStage, Level: 0},
74+
{WerfImageName: dockerfileImageConfig.Name, Stage: targetStage, Level: 0, IsTargetStage: true},
7375
}
7476

7577
appendQueue := func(werfImageName string, stage *dockerfile.DockerfileStage, level int) {
7678
queue = append(queue, struct {
7779
WerfImageName string
7880
Stage *dockerfile.DockerfileStage
7981
Level int
82+
IsTargetStage bool
8083
}{WerfImageName: werfImageName, Stage: stage, Level: level})
8184
}
8285

@@ -103,6 +106,7 @@ func mapDockerfileToImagesSets(ctx context.Context, cfg *dockerfile.Dockerfile,
103106
if baseStg := cfg.FindStage(stg.BaseName); baseStg != nil {
104107
img, err = NewImage(ctx, item.WerfImageName, StageAsBaseImage, ImageOptions{
105108
IsDockerfileImage: true,
109+
IsDockerfileTargetStage: item.IsTargetStage,
106110
DockerfileImageConfig: dockerfileImageConfig,
107111
CommonImageOptions: opts,
108112
BaseImageName: baseStg.WerfImageName(),
@@ -116,6 +120,7 @@ func mapDockerfileToImagesSets(ctx context.Context, cfg *dockerfile.Dockerfile,
116120
} else {
117121
img, err = NewImage(ctx, item.WerfImageName, ImageFromRegistryAsBaseImage, ImageOptions{
118122
IsDockerfileImage: true,
123+
IsDockerfileTargetStage: item.IsTargetStage,
119124
DockerfileImageConfig: dockerfileImageConfig,
120125
CommonImageOptions: opts,
121126
BaseImageReference: stg.BaseName,
@@ -127,10 +132,11 @@ func mapDockerfileToImagesSets(ctx context.Context, cfg *dockerfile.Dockerfile,
127132
}
128133

129134
for ind, instr := range stg.Instructions {
130-
stageName := stage.StageName(fmt.Sprintf("%s%d", instr.GetInstructionData().Name(), ind))
135+
stageLogName := fmt.Sprintf("%s%d", strings.ToUpper(instr.GetInstructionData().Name()), ind+1)
131136
isFirstStage := (len(img.stages) == 0)
132137
baseStageOptions := &stage.BaseStageOptions{
133138
ImageName: img.Name,
139+
LogName: stageLogName,
134140
ImageTmpDir: img.TmpDir,
135141
ContainerWerfDir: img.ContainerWerfDir,
136142
ProjectName: opts.ProjectName,
@@ -141,37 +147,37 @@ func mapDockerfileToImagesSets(ctx context.Context, cfg *dockerfile.Dockerfile,
141147
case *dockerfile.DockerfileStageInstruction[*instructions.ArgCommand]:
142148
continue
143149
case *dockerfile.DockerfileStageInstruction[*instructions.AddCommand]:
144-
stg = stage_instruction.NewAdd(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
150+
stg = stage_instruction.NewAdd(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
145151
case *dockerfile.DockerfileStageInstruction[*instructions.CmdCommand]:
146-
stg = stage_instruction.NewCmd(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
152+
stg = stage_instruction.NewCmd(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
147153
case *dockerfile.DockerfileStageInstruction[*instructions.CopyCommand]:
148-
stg = stage_instruction.NewCopy(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
154+
stg = stage_instruction.NewCopy(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
149155
case *dockerfile.DockerfileStageInstruction[*instructions.EntrypointCommand]:
150-
stg = stage_instruction.NewEntrypoint(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
156+
stg = stage_instruction.NewEntrypoint(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
151157
case *dockerfile.DockerfileStageInstruction[*instructions.EnvCommand]:
152-
stg = stage_instruction.NewEnv(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
158+
stg = stage_instruction.NewEnv(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
153159
case *dockerfile.DockerfileStageInstruction[*instructions.ExposeCommand]:
154-
stg = stage_instruction.NewExpose(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
160+
stg = stage_instruction.NewExpose(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
155161
case *dockerfile.DockerfileStageInstruction[*instructions.HealthCheckCommand]:
156-
stg = stage_instruction.NewHealthcheck(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
162+
stg = stage_instruction.NewHealthcheck(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
157163
case *dockerfile.DockerfileStageInstruction[*instructions.LabelCommand]:
158-
stg = stage_instruction.NewLabel(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
164+
stg = stage_instruction.NewLabel(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
159165
case *dockerfile.DockerfileStageInstruction[*instructions.MaintainerCommand]:
160-
stg = stage_instruction.NewMaintainer(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
166+
stg = stage_instruction.NewMaintainer(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
161167
case *dockerfile.DockerfileStageInstruction[*instructions.OnbuildCommand]:
162-
stg = stage_instruction.NewOnBuild(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
168+
stg = stage_instruction.NewOnBuild(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
163169
case *dockerfile.DockerfileStageInstruction[*instructions.RunCommand]:
164-
stg = stage_instruction.NewRun(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
170+
stg = stage_instruction.NewRun(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
165171
case *dockerfile.DockerfileStageInstruction[*instructions.ShellCommand]:
166-
stg = stage_instruction.NewShell(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
172+
stg = stage_instruction.NewShell(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
167173
case *dockerfile.DockerfileStageInstruction[*instructions.StopSignalCommand]:
168-
stg = stage_instruction.NewStopSignal(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
174+
stg = stage_instruction.NewStopSignal(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
169175
case *dockerfile.DockerfileStageInstruction[*instructions.UserCommand]:
170-
stg = stage_instruction.NewUser(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
176+
stg = stage_instruction.NewUser(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
171177
case *dockerfile.DockerfileStageInstruction[*instructions.VolumeCommand]:
172-
stg = stage_instruction.NewVolume(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
178+
stg = stage_instruction.NewVolume(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
173179
case *dockerfile.DockerfileStageInstruction[*instructions.WorkdirCommand]:
174-
stg = stage_instruction.NewWorkdir(stageName, typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
180+
stg = stage_instruction.NewWorkdir(typedInstr, dockerfileImageConfig.Dependencies, !isFirstStage, baseStageOptions)
175181
default:
176182
panic(fmt.Sprintf("unsupported instruction type %#v", instr))
177183
}
@@ -191,9 +197,10 @@ func mapDockerfileToImagesSets(ctx context.Context, cfg *dockerfile.Dockerfile,
191197

192198
func mapLegacyDockerfileToImage(ctx context.Context, dockerfileImageConfig *config.ImageFromDockerfile, opts CommonImageOptions) (*Image, error) {
193199
img, err := NewImage(ctx, dockerfileImageConfig.Name, NoBaseImage, ImageOptions{
194-
CommonImageOptions: opts,
195-
IsDockerfileImage: true,
196-
DockerfileImageConfig: dockerfileImageConfig,
200+
CommonImageOptions: opts,
201+
IsDockerfileImage: true,
202+
IsDockerfileTargetStage: true,
203+
DockerfileImageConfig: dockerfileImageConfig,
197204
})
198205
if err != nil {
199206
return nil, fmt.Errorf("unable to create image %q: %w", dockerfileImageConfig.Name, err)

pkg/build/image/image.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ type CommonImageOptions struct {
4141

4242
type ImageOptions struct {
4343
CommonImageOptions
44-
IsArtifact, IsDockerfileImage bool
45-
DockerfileImageConfig *config.ImageFromDockerfile
44+
IsArtifact, IsDockerfileImage, IsDockerfileTargetStage bool
45+
DockerfileImageConfig *config.ImageFromDockerfile
4646

4747
BaseImageReference string
4848
BaseImageName string
@@ -58,11 +58,12 @@ func NewImage(ctx context.Context, name string, baseImageType BaseImageType, opt
5858
}
5959

6060
i := &Image{
61-
Name: name,
62-
CommonImageOptions: opts.CommonImageOptions,
63-
IsArtifact: opts.IsArtifact,
64-
IsDockerfileImage: opts.IsDockerfileImage,
65-
DockerfileImageConfig: opts.DockerfileImageConfig,
61+
Name: name,
62+
CommonImageOptions: opts.CommonImageOptions,
63+
IsArtifact: opts.IsArtifact,
64+
IsDockerfileImage: opts.IsDockerfileImage,
65+
IsDockerfileTargetStage: opts.IsDockerfileTargetStage,
66+
DockerfileImageConfig: opts.DockerfileImageConfig,
6667

6768
baseImageType: baseImageType,
6869
baseImageReference: opts.BaseImageReference,
@@ -82,10 +83,11 @@ func NewImage(ctx context.Context, name string, baseImageType BaseImageType, opt
8283
type Image struct {
8384
CommonImageOptions
8485

85-
IsArtifact bool
86-
IsDockerfileImage bool
87-
Name string
88-
DockerfileImageConfig *config.ImageFromDockerfile
86+
IsArtifact bool
87+
IsDockerfileImage bool
88+
IsDockerfileTargetStage bool
89+
Name string
90+
DockerfileImageConfig *config.ImageFromDockerfile
8991

9092
stages []stage.Interface
9193
lastNonEmptyStage stage.Interface

pkg/build/stage/base.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ var AllStages = []StageName{
7474
}
7575

7676
type BaseStageOptions struct {
77+
LogName string
7778
ImageName string
7879
ConfigMounts []*config.Mount
7980
ImageTmpDir string
@@ -84,6 +85,7 @@ type BaseStageOptions struct {
8485
func NewBaseStage(name StageName, options *BaseStageOptions) *BaseStage {
8586
s := &BaseStage{}
8687
s.name = name
88+
s.logName = options.LogName
8789
s.imageName = options.ImageName
8890
s.configMounts = options.ConfigMounts
8991
s.imageTmpDir = options.ImageTmpDir
@@ -94,6 +96,7 @@ func NewBaseStage(name StageName, options *BaseStageOptions) *BaseStage {
9496

9597
type BaseStage struct {
9698
name StageName
99+
logName string
97100
imageName string
98101
digest string
99102
contentDigest string
@@ -119,13 +122,20 @@ func (s *BaseStage) LogDetailedName() string {
119122
imageName = "~"
120123
}
121124

122-
return fmt.Sprintf("%s/%s", imageName, s.Name())
125+
return fmt.Sprintf("%s/%s", imageName, s.LogName())
123126
}
124127

125128
func (s *BaseStage) ImageName() string {
126129
return s.imageName
127130
}
128131

132+
func (s *BaseStage) LogName() string {
133+
if s.logName != "" {
134+
return s.logName
135+
}
136+
return string(s.Name())
137+
}
138+
129139
func (s *BaseStage) Name() StageName {
130140
if s.name != "" {
131141
return s.name
@@ -164,7 +174,7 @@ func (s *BaseStage) getNextStageGitDependencies(ctx context.Context, c Conveyor)
164174
}
165175
}
166176

167-
logboek.Context(ctx).Debug().LogF("Stage %q next stage dependencies: %#v\n", s.Name(), args)
177+
logboek.Context(ctx).Debug().LogF("Stage %q next stage dependencies: %#v\n", s.LogName(), args)
168178
sort.Strings(args)
169179

170180
return util.Sha256Hash(args...), nil

pkg/build/stage/instruction/add.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ type Add struct {
1919
*Base[*instructions.AddCommand, *backend_instruction.Add]
2020
}
2121

22-
func NewAdd(name stage.StageName, i *dockerfile.DockerfileStageInstruction[*instructions.AddCommand], dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Add {
23-
return &Add{Base: NewBase(name, i, backend_instruction.NewAdd(i.Data), dependencies, hasPrevStage, opts)}
22+
func NewAdd(i *dockerfile.DockerfileStageInstruction[*instructions.AddCommand], dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Add {
23+
return &Add{Base: NewBase(i, backend_instruction.NewAdd(i.Data), dependencies, hasPrevStage, opts)}
2424
}
2525

2626
func (stg *Add) GetDependencies(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevImage, prevBuiltImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) (string, error) {
@@ -29,7 +29,6 @@ func (stg *Add) GetDependencies(ctx context.Context, c stage.Conveyor, cb contai
2929
return "", err
3030
}
3131

32-
args = append(args, "Instruction", stg.instruction.Data.Name())
3332
args = append(args, append([]string{"Sources"}, stg.instruction.Data.Sources()...)...)
3433
args = append(args, "Dest", stg.instruction.Data.Dest())
3534
args = append(args, "Chown", stg.instruction.Data.Chown)

pkg/build/stage/instruction/add_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var _ = DescribeTable("ADD digest",
2525
},
2626

2727
Entry("ADD basic", NewTestData(
28-
NewAdd("ADD",
28+
NewAdd(
2929
dockerfile.NewDockerfileStageInstruction(
3030
&instructions.AddCommand{SourcesAndDest: []string{"src", "/app"}, Chown: "1000:1000", Chmod: ""},
3131
dockerfile.DockerfileStageInstructionOptions{},
@@ -36,7 +36,7 @@ var _ = DescribeTable("ADD digest",
3636
ProjectName: "example-project",
3737
},
3838
),
39-
"88c31da85ac26ae35d29462c6dc309c2a02997c0de92b4ccee7db2e41be17187",
39+
"79d3642e997030deb225e0414f0c2d0e3c6681cc036899aaba62895f7e2ac4e3",
4040
TestDataOptions{
4141
Files: []*FileData{
4242
{Name: "src/main/java/worker/Worker.java", Data: []byte(`package worker;`)},
@@ -46,7 +46,7 @@ var _ = DescribeTable("ADD digest",
4646
)),
4747

4848
Entry("ADD with changed chown", NewTestData(
49-
NewAdd("ADD",
49+
NewAdd(
5050
dockerfile.NewDockerfileStageInstruction(
5151
&instructions.AddCommand{SourcesAndDest: []string{"src", "/app"}, Chown: "1000:1001", Chmod: ""},
5252
dockerfile.DockerfileStageInstructionOptions{},
@@ -57,7 +57,7 @@ var _ = DescribeTable("ADD digest",
5757
ProjectName: "example-project",
5858
},
5959
),
60-
"846ef29e994224dd84bf0a5de47b0b3255c8681b8178e8da5611b21547cd182b",
60+
"ccfda65ec4fa8667abe7a54b047a98158d122b39e224929dbb7c33ea466e7f5a",
6161
TestDataOptions{
6262
Files: []*FileData{
6363
{Name: "src/main/java/worker/Worker.java", Data: []byte(`package worker;`)},
@@ -68,7 +68,7 @@ var _ = DescribeTable("ADD digest",
6868
)),
6969

7070
Entry("ADD with changed chmod", NewTestData(
71-
NewAdd("ADD",
71+
NewAdd(
7272
dockerfile.NewDockerfileStageInstruction(
7373
&instructions.AddCommand{SourcesAndDest: []string{"src", "/app"}, Chown: "1000:1001", Chmod: "0777"},
7474
dockerfile.DockerfileStageInstructionOptions{},
@@ -79,7 +79,7 @@ var _ = DescribeTable("ADD digest",
7979
ProjectName: "example-project",
8080
},
8181
),
82-
"cef21e87710631a08edeb176a9487f81ae20171c22ec4537a3dc8fbc67aca868",
82+
"19e86e1145aecd554d7d492add3c6c6ed51b022279f059f6c8c54a4eac9d07f0",
8383
TestDataOptions{
8484
Files: []*FileData{
8585
{Name: "src/main/java/worker/Worker.java", Data: []byte(`package worker;`)},
@@ -90,7 +90,7 @@ var _ = DescribeTable("ADD digest",
9090
)),
9191

9292
Entry("ADD with changed sources paths", NewTestData(
93-
NewAdd("ADD",
93+
NewAdd(
9494
dockerfile.NewDockerfileStageInstruction(
9595
&instructions.AddCommand{SourcesAndDest: []string{"src", "pom.xml", "/app"}, Chown: "1000:1001", Chmod: "0777"},
9696
dockerfile.DockerfileStageInstructionOptions{},
@@ -101,7 +101,7 @@ var _ = DescribeTable("ADD digest",
101101
ProjectName: "example-project",
102102
},
103103
),
104-
"97f3f8a240902d73ec9a209f6c8368047b56d9247bdf9da88a40ac5dba925209",
104+
"4d17db1e6926bbe9e4f7b70d18bb055b7735f6bfb6db35452524bde561e8b95f",
105105
TestDataOptions{
106106
Files: []*FileData{
107107
{Name: "src/main/java/worker/Worker.java", Data: []byte(`package worker;`)},
@@ -112,7 +112,7 @@ var _ = DescribeTable("ADD digest",
112112
)),
113113

114114
Entry("ADD with changed source files", NewTestData(
115-
NewAdd("ADD",
115+
NewAdd(
116116
dockerfile.NewDockerfileStageInstruction(
117117
&instructions.AddCommand{SourcesAndDest: []string{"src", "pom.xml", "/app"}, Chown: "1000:1001", Chmod: "0777"},
118118
dockerfile.DockerfileStageInstructionOptions{},
@@ -123,7 +123,7 @@ var _ = DescribeTable("ADD digest",
123123
ProjectName: "example-project",
124124
},
125125
),
126-
"60178e0b174bd1bce1cd29f8132ea84cc7212773b6fce9fad3ddff842d5cf2e0",
126+
"372ed0cb6fff0a58e087fa8bf19e1f62a146d3983ca4510c496c452db8a7080e",
127127
TestDataOptions{
128128
Files: []*FileData{
129129
{Name: "src/main/java/worker/Worker.java", Data: []byte(`package worker2;`)},
@@ -134,7 +134,7 @@ var _ = DescribeTable("ADD digest",
134134
)),
135135

136136
Entry("ADD with changed destination path", NewTestData(
137-
NewAdd("ADD",
137+
NewAdd(
138138
dockerfile.NewDockerfileStageInstruction(
139139
&instructions.AddCommand{SourcesAndDest: []string{"src", "pom.xml", "/app2"}, Chown: "1000:1001", Chmod: "0777"},
140140
dockerfile.DockerfileStageInstructionOptions{},
@@ -145,7 +145,7 @@ var _ = DescribeTable("ADD digest",
145145
ProjectName: "example-project",
146146
},
147147
),
148-
"c1f03d5701951fe9c5836957c753c9486f22e14b2d9291780ae70f288e531e1c",
148+
"825c66ecb926ed7897fc99f7686ed4fc2a7f8133d6a66860c8755772764d0293",
149149
TestDataOptions{
150150
Files: []*FileData{
151151
{Name: "src/main/java/worker/Worker.java", Data: []byte(`package worker2;`)},

pkg/build/stage/instruction/base.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ type Base[T dockerfile.InstructionDataInterface, BT container_backend.Instructio
1919
hasPrevStage bool
2020
}
2121

22-
func NewBase[T dockerfile.InstructionDataInterface, BT container_backend.InstructionInterface](name stage.StageName, instruction *dockerfile.DockerfileStageInstruction[T], backendInstruction BT, dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Base[T, BT] {
22+
func NewBase[T dockerfile.InstructionDataInterface, BT container_backend.InstructionInterface](instruction *dockerfile.DockerfileStageInstruction[T], backendInstruction BT, dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Base[T, BT] {
2323
return &Base[T, BT]{
24-
BaseStage: stage.NewBaseStage(name, opts),
24+
BaseStage: stage.NewBaseStage(stage.StageName(instruction.Data.Name()), opts),
2525
instruction: instruction,
2626
backendInstruction: backendInstruction,
2727
dependencies: dependencies,

pkg/build/stage/instruction/cmd.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ type Cmd struct {
1818
*Base[*instructions.CmdCommand, *backend_instruction.Cmd]
1919
}
2020

21-
func NewCmd(name stage.StageName, i *dockerfile.DockerfileStageInstruction[*instructions.CmdCommand], dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Cmd {
22-
return &Cmd{Base: NewBase(name, i, backend_instruction.NewCmd(i.Data), dependencies, hasPrevStage, opts)}
21+
func NewCmd(i *dockerfile.DockerfileStageInstruction[*instructions.CmdCommand], dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Cmd {
22+
return &Cmd{Base: NewBase(i, backend_instruction.NewCmd(i.Data), dependencies, hasPrevStage, opts)}
2323
}
2424

2525
func (stg *Cmd) GetDependencies(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevImage, prevBuiltImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) (string, error) {
@@ -28,7 +28,6 @@ func (stg *Cmd) GetDependencies(ctx context.Context, c stage.Conveyor, cb contai
2828
return "", err
2929
}
3030

31-
args = append(args, "Instruction", stg.instruction.Data.Name())
3231
args = append(args, append([]string{"Cmd"}, stg.instruction.Data.CmdLine...)...)
3332
args = append(args, "PrependShell", fmt.Sprintf("%v", stg.instruction.Data.PrependShell))
3433

0 commit comments

Comments
 (0)