Skip to content

Commit

Permalink
POD-769: Check build target exists in Dockerfile (#1218)
Browse files Browse the repository at this point in the history
* POD-769: Check build target exists in Dockerfile

* POD-769: Use fmt.Errorf instead of wrapping

* POD-769: Only check target if set
  • Loading branch information
bkneis authored Aug 14, 2024
1 parent c2855e6 commit c9501dd
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/devcontainer/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ func (r *runner) getImageBuildInfoFromDockerfile(substitutionContext *config.Sub
return nil, errors.Wrap(err, "parse dockerfile")
}

// Check that the build target specified in the devcontainer.json exists in the Dockerfile
if target != "" && parsedDockerfile.StagesByTarget != nil {
_, ok := parsedDockerfile.StagesByTarget[target]
if !ok {
return nil, fmt.Errorf("build target does not exist")
}
}

baseImage := parsedDockerfile.FindBaseImage(buildArgs, target)
if baseImage == "" {
return nil, fmt.Errorf("find base image %s", target)
Expand Down

0 comments on commit c9501dd

Please sign in to comment.