mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #36960 from arm64b/fix-multi-stage-name-issue
Fix the target name issue for multi-stage build
This commit is contained in:
commit
51a9119f6b
3 changed files with 10 additions and 3 deletions
|
@ -226,7 +226,7 @@ func (b *Builder) build(source builder.Source, dockerfile *parser.Result) (*buil
|
|||
targetIx, found := instructions.HasStage(stages, b.options.Target)
|
||||
if !found {
|
||||
buildsFailed.WithValues(metricsBuildTargetNotReachableError).Inc()
|
||||
return nil, errors.Errorf("failed to reach build target %s in Dockerfile", b.options.Target)
|
||||
return nil, errdefs.InvalidParameter(errors.Errorf("failed to reach build target %s in Dockerfile", b.options.Target))
|
||||
}
|
||||
stages = stages[:targetIx+1]
|
||||
}
|
||||
|
|
|
@ -390,7 +390,8 @@ func CurrentStage(s []Stage) (*Stage, error) {
|
|||
// HasStage looks for the presence of a given stage name
|
||||
func HasStage(s []Stage, name string) (int, bool) {
|
||||
for i, stage := range s {
|
||||
if stage.Name == name {
|
||||
// Stage name is case-insensitive by design
|
||||
if strings.EqualFold(stage.Name, name) {
|
||||
return i, true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5965,10 +5965,16 @@ func (s *DockerSuite) TestBuildIntermediateTarget(c *check.C) {
|
|||
cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx),
|
||||
cli.WithFlags("--target", "build-env"))
|
||||
|
||||
//res := inspectFieldJSON(c, "build1", "Config.Cmd")
|
||||
res := cli.InspectCmd(c, "build1", cli.Format("json .Config.Cmd")).Combined()
|
||||
c.Assert(strings.TrimSpace(res), checker.Equals, `["/dev"]`)
|
||||
|
||||
// Stage name is case-insensitive by design
|
||||
cli.BuildCmd(c, "build1", build.WithExternalBuildContext(ctx),
|
||||
cli.WithFlags("--target", "BUIld-EnV"))
|
||||
|
||||
res = cli.InspectCmd(c, "build1", cli.Format("json .Config.Cmd")).Combined()
|
||||
c.Assert(strings.TrimSpace(res), checker.Equals, `["/dev"]`)
|
||||
|
||||
result := cli.Docker(cli.Build("build1"), build.WithExternalBuildContext(ctx),
|
||||
cli.WithFlags("--target", "nosuchtarget"))
|
||||
result.Assert(c, icmd.Expected{
|
||||
|
|
Loading…
Add table
Reference in a new issue