Have Docker create a missing volume host path (closes #235)
Check / check (pull_request) Successful in 4m54s
Check / check (pull_request) Successful in 4m54s
Docker refused to bind-mount a host path that did not exist, so an app's first deploy failed until someone ran mkdir on the host. buildMounts now sets BindOptions.CreateMountpoint on every bind mount, so the Docker daemon creates a missing host path when the container starts and leaves an existing one alone. upaas itself cannot create it: it runs in a container and does not see the host's filesystem. The README gains a Volume mounts section saying so. Needs Docker Engine 23.0 or later. Model: opus-5-5
This commit was merged in pull request #252.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package docker //nolint:testpackage // tests unexported buildMounts
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// TestBuildMountsCreatesMissingHostPath checks that every mount asks Docker
|
||||
// to create its host path if it is missing, and keeps the rest of the volume
|
||||
// as configured.
|
||||
func TestBuildMountsCreatesMissingHostPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
volumes := []VolumeMount{
|
||||
{HostPath: "/srv/app/data", ContainerPath: "/data", ReadOnly: false},
|
||||
{HostPath: "/srv/app/config", ContainerPath: "/etc/app", ReadOnly: true},
|
||||
}
|
||||
|
||||
want := []mount.Mount{
|
||||
{
|
||||
Type: mount.TypeBind,
|
||||
Source: "/srv/app/data",
|
||||
Target: "/data",
|
||||
ReadOnly: false,
|
||||
BindOptions: &mount.BindOptions{CreateMountpoint: true},
|
||||
},
|
||||
{
|
||||
Type: mount.TypeBind,
|
||||
Source: "/srv/app/config",
|
||||
Target: "/etc/app",
|
||||
ReadOnly: true,
|
||||
BindOptions: &mount.BindOptions{CreateMountpoint: true},
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, want, buildMounts(volumes))
|
||||
}
|
||||
Reference in New Issue
Block a user