Skip to content

Commit

Permalink
If Dockerfile exists in same directory as service, we should not use it.
Browse files Browse the repository at this point in the history
We should only use the Containerfiles/Dockerfiles found in the context
directory.

Fixes: containers#12054

[NO NEW TESTS NEEDED] It is difficult to setup a test for this in the
CI/CD system, but build tests should find if this PR broke anything.

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan authored and mheon committed Nov 12, 2021
1 parent 7275d38 commit 729310a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,19 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
var m = []string{}
if err := json.Unmarshal([]byte(query.Dockerfile), &m); err != nil {
// it's not json, assume just a string
m = append(m, query.Dockerfile)
m = []string{filepath.Join(contextDirectory, query.Dockerfile)}
}
containerFiles = m
} else {
containerFiles = []string{"Dockerfile"}
containerFiles = []string{filepath.Join(contextDirectory, "Dockerfile")}
if utils.IsLibpodRequest(r) {
containerFiles = []string{"Containerfile"}
if _, err = os.Stat(filepath.Join(contextDirectory, "Containerfile")); err != nil {
if _, err1 := os.Stat(filepath.Join(contextDirectory, "Dockerfile")); err1 == nil {
containerFiles = []string{"Dockerfile"}
} else {
containerFiles = []string{filepath.Join(contextDirectory, "Containerfile")}
if _, err = os.Stat(containerFiles[0]); err != nil {
containerFiles = []string{filepath.Join(contextDirectory, "Dockerfile")}
if _, err1 := os.Stat(containerFiles[0]); err1 != nil {
utils.BadRequest(w, "dockerfile", query.Dockerfile, err)
}
}
} else {
containerFiles = []string{"Dockerfile"}
}
}

Expand Down

0 comments on commit 729310a

Please sign in to comment.