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:
Jose Diaz-Gonzalez committed 2026-10-16 11:52:01 -04:00
1 parent b82f4718c8
commit cbde55a4a0
8 files changed
+103 -3

No files matched your search

+43
View File
@@ -107,3 +107,46 @@ func TestGetStorageDirectory(t *testing.T) {
dir := GetStorageDirectory()
Expect(dir).To(ContainSubstring("data/storage"))
}
func TestHostPathForDocker(t *testing.T) {
RegisterTestingT(t)
t.Setenv("DOKKU_LIB_ROOT", "/var/lib/dokku")
t.Run("unset host root leaves path unchanged", func(t *testing.T) {
RegisterTestingT(t)
t.Setenv("DOKKU_LIB_HOST_ROOT", "")
Expect(HostPathForDocker("/var/lib/dokku/data/storage/foo")).To(Equal("/var/lib/dokku/data/storage/foo"))
})
t.Run("equal host root leaves path unchanged", func(t *testing.T) {
RegisterTestingT(t)
t.Setenv("DOKKU_LIB_HOST_ROOT", "/var/lib/dokku")
Expect(HostPathForDocker("/var/lib/dokku/data/storage/foo")).To(Equal("/var/lib/dokku/data/storage/foo"))
})
t.Run("rewrites paths under lib root", func(t *testing.T) {
RegisterTestingT(t)
t.Setenv("DOKKU_LIB_HOST_ROOT", "/host/var/lib/dokku")
Expect(HostPathForDocker("/var/lib/dokku/data/storage/foo")).To(Equal("/host/var/lib/dokku/data/storage/foo"))
Expect(HostPathForDocker("/var/lib/dokku")).To(Equal("/host/var/lib/dokku"))
})
t.Run("leaves named volumes unchanged", func(t *testing.T) {
RegisterTestingT(t)
t.Setenv("DOKKU_LIB_HOST_ROOT", "/host/var/lib/dokku")
Expect(HostPathForDocker("myvolume")).To(Equal("myvolume"))
})
t.Run("leaves custom absolute paths unchanged", func(t *testing.T) {
RegisterTestingT(t)
t.Setenv("DOKKU_LIB_HOST_ROOT", "/host/var/lib/dokku")
Expect(HostPathForDocker("/srv/demo")).To(Equal("/srv/demo"))
})
t.Run("does not false-match similar prefixes", func(t *testing.T) {
RegisterTestingT(t)
t.Setenv("DOKKU_LIB_HOST_ROOT", "/host/var/lib/dokku")
Expect(HostPathForDocker("/var/lib/dokku-extra/data")).To(Equal("/var/lib/dokku-extra/data"))
})
}