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

@@ -0,0 +1,53 @@
package docker
import (
"context"
"encoding/json"
"strings"
"testing"
"github.com/psviderski/uncloud/api/pb"
"github.com/psviderski/uncloud/pkg/api"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
_ "modernc.org/sqlite"
)
func TestCreateServiceContainer_RejectsRuntimeTemplateError(t *testing.T) {
t.Parallel()
desiredSpec := api.ServiceSpec{
Name: "web",
Container: api.ContainerSpec{
Image: "busybox:latest",
VolumeMounts: []api.VolumeMount{
{VolumeName: "data", ContainerPath: "/data"},
},
},
Volumes: []api.VolumeSpec{
{
Name: "data",
Type: api.VolumeTypeBind,
BindOptions: &api.BindOptions{
// Early validation takes the valid branch. Rendering with the real container name takes the invalid one.
HostPath: `/host/{{if eq .Container.Name "web-a1b2"}}{{.Container.ID}}{{else}}valid{{end}}`,
},
},
},
}
specJSON, err := json.Marshal(desiredSpec)
require.NoError(t, err)
server := &Server{}
_, err = server.CreateServiceContainer(context.Background(), &pb.CreateServiceContainerRequest{
ServiceId: strings.Repeat("a", 32),
ServiceSpec: specJSON,
ContainerName: "web-a1b2",
})
require.Error(t, err)
assert.Equal(t, codes.InvalidArgument, status.Code(err))
assert.ErrorContains(t, err, "render runtime template in bind volume 'data' host path")
}