Skip to content

Commit

Permalink
Implement read only flag
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Mills <[email protected]>
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
petertjmills authored and alexellis committed Sep 27, 2023
1 parent ba601bf commit aab5363
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions pkg/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ type ServicePort struct {
}

type Mount struct {
Src string
// 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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -342,8 +355,9 @@ func ParseCompose(config *compose.Config) ([]Service, error) {
return nil, errors.Errorf("unsupported volume mount type '%s' when parsing service '%s'", v.Type, s.Name)
}
mounts = append(mounts, Mount{
Src: v.Source,
Dest: v.Target,
Src: v.Source,
Dest: v.Target,
ReadOnly: v.ReadOnly,
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/supervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
}
Expand Down

0 comments on commit aab5363

Please sign in to comment.