Skip to content

Commit

Permalink
Merge pull request containers#10652 from rhatdan/devices
Browse files Browse the repository at this point in the history
Fix handling of podman-remote build --device
  • Loading branch information
openshift-merge-robot authored Jun 14, 2021
2 parents e549ca5 + e8006c7 commit e3dd12a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
var devices = []string{}
if _, found := r.URL.Query()["devices"]; found {
var m = []string{}
if err := json.Unmarshal([]byte(query.DropCapabilities), &m); err != nil {
utils.BadRequest(w, "devices", query.DropCapabilities, err)
if err := json.Unmarshal([]byte(query.Devices), &m); err != nil {
utils.BadRequest(w, "devices", query.Devices, err)
return
}
devices = m
Expand Down
34 changes: 34 additions & 0 deletions test/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,4 +604,38 @@ RUN echo hello`, ALPINE)
Expect(inspect.OutputToString()).To(Equal("windows"))

})

It("podman build device test", func() {
if _, err := os.Lstat("/dev/fuse"); err != nil {
Skip(fmt.Sprintf("test requires stat /dev/fuse to work: %v", err))
}
containerfile := fmt.Sprintf(`FROM %s
RUN ls /dev/fuse`, ALPINE)
containerfilePath := filepath.Join(podmanTest.TempDir, "Containerfile")
err := ioutil.WriteFile(containerfilePath, []byte(containerfile), 0755)
Expect(err).To(BeNil())
session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(125))

session = podmanTest.Podman([]string{"build", "--pull-never", "--device", "/dev/fuse", "-t", "test", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
})

It("podman build device rename test", func() {
SkipIfRootless("rootless builds do not currently support renaming devices")
containerfile := fmt.Sprintf(`FROM %s
RUN ls /dev/test1`, ALPINE)
containerfilePath := filepath.Join(podmanTest.TempDir, "Containerfile")
err := ioutil.WriteFile(containerfilePath, []byte(containerfile), 0755)
Expect(err).To(BeNil())
session := podmanTest.Podman([]string{"build", "--pull-never", "-t", "test", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(125))

session = podmanTest.Podman([]string{"build", "--pull-never", "--device", "/dev/zero:/dev/test1", "-t", "test", "--file", containerfilePath, podmanTest.TempDir})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
})
})

0 comments on commit e3dd12a

Please sign in to comment.