run corrosion in Docker as uncloud user, bind mount data dir

This commit is contained in:
Pavel Sviderski
2024-11-27 16:35:35 +10:00
parent 871fd8c035
commit c3d3a4242e
4 changed files with 80 additions and 48 deletions
+21
View File
@@ -6,6 +6,7 @@ import (
"github.com/BurntSushi/toml"
"net/netip"
"os"
"path/filepath"
"uncloud/internal/fs"
)
@@ -57,3 +58,23 @@ func (c *Config) Write(path, owner string) error {
}
return nil
}
func MkDataDir(dir, owner string) error {
parent, _ := filepath.Split(dir)
// Use 0711 for parent directories to allow `owner` to access its nested data directory.
if err := os.MkdirAll(parent, 0711); err != nil {
return fmt.Errorf("create directory %q: %w", parent, err)
}
if err := os.Mkdir(dir, 0700); err != nil {
if !os.IsExist(err) {
return fmt.Errorf("create directory %q: %w", dir, err)
}
}
if owner != "" {
if err := fs.Chown(dir, owner); err != nil {
return err
}
}
return nil
}