feat(runtime-templates): add support for runtime templates in bind mounts (#412)

This commit is contained in:
Pasha Sviderski committed 2026-09-23 15:12:10 +10:00
1 parent 88dda435e7
commit 5c33e4be86
17 files changed
+571 -10

No files matched your search

+50
View File
@@ -160,6 +160,10 @@ func TestServiceSpecFromCompose(t *testing.T) {
ContainerPath: "/host/etc/passwd",
ReadOnly: true,
},
{
VolumeName: "bind-cd9bef32904c6831a0cd0d49cf503078a46a0989acea375fdd3d3b43b2bfec4f",
ContainerPath: "/unique/host/bind",
},
{
VolumeName: "data1",
ContainerPath: "/data1",
@@ -240,6 +244,14 @@ func TestServiceSpecFromCompose(t *testing.T) {
CreateHostPath: true,
},
},
{
Name: "bind-cd9bef32904c6831a0cd0d49cf503078a46a0989acea375fdd3d3b43b2bfec4f",
Type: "bind",
BindOptions: &api.BindOptions{
HostPath: "/runtime/template/{{.Container.Name}}",
CreateHostPath: true,
},
},
{
Name: "data-external",
Type: api.VolumeTypeVolume,
@@ -1293,3 +1305,41 @@ services:
})
}
}
func TestServiceSpecFromCompose_RuntimeTemplates(t *testing.T) {
t.Setenv("UNCLOUD_TEST_TEMPLATE_ROOT", "uncloud-test")
project, err := LoadProjectFromContent(context.Background(), `
services:
short:
image: busybox:latest
volumes:
- "/var/lib/${UNCLOUD_TEST_TEMPLATE_ROOT}/{{.Container.Name}}:/data/{{.Container.Name}}:ro"
long:
image: busybox:latest
volumes:
- type: bind
source: "/var/lib/${UNCLOUD_TEST_TEMPLATE_ROOT}/{{.Container.Name}}"
target: "/data/{{.Container.Name}}"
read_only: true
bind:
create_host_path: true
`)
require.NoError(t, err)
shortSpec, err := ServiceSpecFromCompose(project, "short")
require.NoError(t, err)
longSpec, err := ServiceSpecFromCompose(project, "long")
require.NoError(t, err)
for _, spec := range []api.ServiceSpec{shortSpec, longSpec} {
require.Len(t, spec.Volumes, 1)
require.NotNil(t, spec.Volumes[0].BindOptions)
assert.Equal(t, "/var/lib/uncloud-test/{{.Container.Name}}", spec.Volumes[0].BindOptions.HostPath)
assert.True(t, spec.Volumes[0].BindOptions.CreateHostPath)
require.Len(t, spec.Container.VolumeMounts, 1)
assert.Equal(t, "/data/{{.Container.Name}}", spec.Container.VolumeMounts[0].ContainerPath)
assert.True(t, spec.Container.VolumeMounts[0].ReadOnly)
require.NoError(t, spec.Validate())
}
}
+1
View File
@@ -52,6 +52,7 @@ services:
user: nginx:nginx
volumes:
- /etc/passwd:/host/etc/passwd:ro
- /runtime/template/{{.Container.Name}}:/unique/host/bind
- data1:/data1
- type: bind
source: /path/on/host