fix: respect DOKKU_LIB_HOST_ROOT for storage bind mounts
When Dokku runs in Docker with a shared socket, create/chown still use DOKKU_LIB_ROOT inside the container, but Docker -v flags for storage:exec and deploy must use DOKKU_LIB_HOST_ROOT so the daemon mounts the host data volume instead of the real host's /var/lib/dokku. Closes #9126.
This commit is contained in:
@@ -137,7 +137,7 @@ func buildDockerExecArgs(entry *storage.Entry, input StorageExecInput) ([]string
|
||||
args = append(args, "--user", user)
|
||||
}
|
||||
|
||||
args = append(args, "-v", fmt.Sprintf("%s:/data", entry.HostPath))
|
||||
args = append(args, "-v", fmt.Sprintf("%s:/data", storage.HostPathForDocker(entry.HostPath)))
|
||||
args = append(args, input.Image)
|
||||
args = append(args, cmd...)
|
||||
return args, nil
|
||||
|
||||
@@ -116,3 +116,25 @@ func TestBuildDockerExecArgsMountsHostPath(t *testing.T) {
|
||||
t.Fatalf("expected -v /srv/demo:/data, got: %s", joined)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildDockerExecArgsRewritesLibHostRoot(t *testing.T) {
|
||||
t.Setenv("DOKKU_LIB_ROOT", "/var/lib/dokku")
|
||||
t.Setenv("DOKKU_LIB_HOST_ROOT", "/host/var/lib/dokku")
|
||||
|
||||
entry := &storage.Entry{
|
||||
Name: "demo-data",
|
||||
Scheduler: storage.SchedulerDockerLocal,
|
||||
HostPath: "/var/lib/dokku/data/storage/demo-data",
|
||||
}
|
||||
args, err := buildDockerExecArgs(entry, StorageExecInput{
|
||||
Image: "alpine:3",
|
||||
Command: []string{"ls"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
joined := strings.Join(args, " ")
|
||||
if !strings.Contains(joined, "-v /host/var/lib/dokku/data/storage/demo-data:/data") {
|
||||
t.Fatalf("expected rewritten -v host path, got: %s", joined)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user