Implement read only flag

Signed-off-by: Peter Mills <ptjm8422@gmail.com>
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Peter Mills
2023-09-12 20:34:25 +01:00
committed by Alex Ellis
parent ba601bfc67
commit aab5363e65
2 changed files with 19 additions and 5 deletions

View File

@ -57,8 +57,14 @@ type ServicePort struct {
}
type Mount struct {
// Src relative to the working directory for faasd
Src string
// Dest is the absolute path within the container
Dest string
// ReadOnly when set to true indicates the mount will be set to "ro" instead of "rw"
ReadOnly bool
}
type Supervisor struct {
@ -151,11 +157,18 @@ func (s *Supervisor) Start(svcs []Service) error {
mounts := []specs.Mount{}
if len(svc.Mounts) > 0 {
for _, mnt := range svc.Mounts {
var options = []string{"rbind"}
if mnt.ReadOnly {
options = append(options, "ro")
} else {
options = append(options, "rw")
}
mounts = append(mounts, specs.Mount{
Source: mnt.Src,
Destination: mnt.Dest,
Type: "bind",
Options: []string{"rbind", "rw"},
Options: options,
})
// Only create directories, not files.
@ -344,6 +357,7 @@ func ParseCompose(config *compose.Config) ([]Service, error) {
mounts = append(mounts, Mount{
Src: v.Source,
Dest: v.Target,
ReadOnly: v.ReadOnly,
})
}

View File

@ -180,7 +180,7 @@ func equalMountSlice(t *testing.T, want, found []Mount) {
for i := range want {
if !reflect.DeepEqual(want[i], found[i]) {
t.Fatalf("unexpected value at postition %d: want %s, got %s", i, want[i], found[i])
t.Fatalf("unexpected value at postition %d: want %v, got %v", i, want[i], found[i])
}
}
}