mirror of
https://github.com/containers/podman.git
synced 2025-06-24 03:08:13 +08:00
Merge pull request #12279 from mscherer/fix_11842
Always create working directory when using compat API
This commit is contained in:
@ -86,6 +86,8 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
|
|||||||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "fill out specgen"))
|
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "fill out specgen"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// moby always create the working directory
|
||||||
|
sg.CreateWorkingDir = true
|
||||||
|
|
||||||
ic := abi.ContainerEngine{Libpod: runtime}
|
ic := abi.ContainerEngine{Libpod: runtime}
|
||||||
report, err := ic.ContainerCreate(r.Context(), sg)
|
report, err := ic.ContainerCreate(r.Context(), sg)
|
||||||
|
@ -378,6 +378,9 @@ func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen.
|
|||||||
if s.WorkDir == "" {
|
if s.WorkDir == "" {
|
||||||
s.WorkDir = "/"
|
s.WorkDir = "/"
|
||||||
}
|
}
|
||||||
|
if s.CreateWorkingDir {
|
||||||
|
options = append(options, libpod.WithCreateWorkingDir())
|
||||||
|
}
|
||||||
if s.StopSignal != nil {
|
if s.StopSignal != nil {
|
||||||
options = append(options, libpod.WithStopSignal(*s.StopSignal))
|
options = append(options, libpod.WithStopSignal(*s.StopSignal))
|
||||||
}
|
}
|
||||||
|
@ -272,6 +272,10 @@ type ContainerStorageConfig struct {
|
|||||||
// If unset, the default, /, will be used.
|
// If unset, the default, /, will be used.
|
||||||
// Optional.
|
// Optional.
|
||||||
WorkDir string `json:"work_dir,omitempty"`
|
WorkDir string `json:"work_dir,omitempty"`
|
||||||
|
// Create the working directory if it doesn't exist.
|
||||||
|
// If unset, it doesn't create it.
|
||||||
|
// Optional.
|
||||||
|
CreateWorkingDir bool `json:"create_working_dir,omitempty"`
|
||||||
// StorageOpts is the container's storage options
|
// StorageOpts is the container's storage options
|
||||||
// Optional.
|
// Optional.
|
||||||
StorageOpts map[string]string `json:"storage_opts,omitempty"`
|
StorageOpts map[string]string `json:"storage_opts,omitempty"`
|
||||||
|
@ -251,3 +251,17 @@ class TestContainers(unittest.TestCase):
|
|||||||
ctr.start()
|
ctr.start()
|
||||||
ret, out = ctr.exec_run(["stat", "-c", "%u:%g", "/workspace"])
|
ret, out = ctr.exec_run(["stat", "-c", "%u:%g", "/workspace"])
|
||||||
self.assertEqual(out.rstrip(), b'1042:1043', "UID/GID set in dockerfile")
|
self.assertEqual(out.rstrip(), b'1042:1043', "UID/GID set in dockerfile")
|
||||||
|
|
||||||
|
|
||||||
|
def test_non_existant_workdir(self):
|
||||||
|
dockerfile = (B'FROM quay.io/libpod/alpine:latest\n'
|
||||||
|
B'USER root\n'
|
||||||
|
B'WORKDIR /workspace/scratch\n'
|
||||||
|
B'RUN touch test')
|
||||||
|
img: Image
|
||||||
|
img, out = self.client.images.build(fileobj=io.BytesIO(dockerfile))
|
||||||
|
ctr: Container = self.client.containers.create(image=img.id, detach=True, command="top",
|
||||||
|
volumes=["test_non_existant_workdir:/workspace"])
|
||||||
|
ctr.start()
|
||||||
|
ret, out = ctr.exec_run(["stat", "/workspace/scratch/test"])
|
||||||
|
self.assertEqual(ret, 0, "Working directory created if it doesn't exist")
|
||||||
|
Reference in New Issue
Block a user