Skip to content

Commit

Permalink
checkin - foldup
Browse files Browse the repository at this point in the history
Signed-off-by: Serge Hallyn <[email protected]>
  • Loading branch information
hallyn committed Dec 22, 2023
1 parent da53040 commit fd6d1b2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
18 changes: 9 additions & 9 deletions pkg/mosconfig/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,14 @@ func (i *ImportFile) CompleteTargets(keyProject string) (UserTargets, error) {
}

type UserTarget struct {
ServiceName string `yaml:"service_name"` // name of target
Source string `yaml:"source"` // docker url from which to fetch
Version string `yaml:"version"` // A version for internal use.
Storage TargetStorageList `yaml:"storage"`
ServiceType ServiceType `yaml:"service_type"`
Network TargetNetwork `yaml:"network"`
NSGroup string `yaml:"nsgroup"`
Digest string `yaml:"digest"`
Size int64 `yaml:"size"`
ServiceName string `yaml:"service_name"` // name of target
Source string `yaml:"source"` // docker url from which to fetch
Version string `yaml:"version"` // A version for internal use.
Storage StorageList `yaml:"storage"`
ServiceType ServiceType `yaml:"service_type"`
Network TargetNetwork `yaml:"network"`
NSGroup string `yaml:"nsgroup"`
Digest string `yaml:"digest"`
Size int64 `yaml:"size"`
}
type UserTargets []UserTarget
16 changes: 15 additions & 1 deletion pkg/mosconfig/mos.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ func (mos *Mos) setupContainerService(t *Target) error {
func (mos *Mos) writeLxcConfig(t *Target) error {
// We are guaranteed to have stopped the container before reaching
// here
log.Infof("Writing lxc config for %#v", t)
lxcStateDir := filepath.Join(mos.opts.RootDir, "var/lib/lxc")
lxcconfigDir := filepath.Join(lxcStateDir, t.ServiceName)
lxclogDir := filepath.Join(mos.opts.RootDir, "/var/log/lxc")
Expand Down Expand Up @@ -458,7 +459,20 @@ func (mos *Mos) writeLxcConfig(t *Target) error {
lxcConf = append(lxcConf, fmt.Sprintf("lxc.environment = %s", env))
}

// TODO - setup the mounts
// setup the storage mounts
for _, m := range t.Storage {
dest := m.Dest
src := filepath.Join("/storage", m.Label)
isdir, err := utils.IsDirErr(src)
if err != nil {
return errors.Wrapf(err, "Source for storage not found: %q", src)
}
filetype := "file"
if isdir {
filetype = "dir"
}
lxcConf = append(lxcConf, fmt.Sprintf("lxc.mount.entry = %s %s none bind,create=%s 0 0", src, dest, filetype))
}

// Write the result
lxcConfFile := filepath.Join(lxcconfigDir, "config")
Expand Down
26 changes: 26 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,29 @@ func NewCpio(cpio, path string) error {

return nil
}

func IsSymlink(path string) (bool, error) {
statInfo, err := os.Lstat(path)
if err != nil {
return false, err
}
return (statInfo.Mode() & os.ModeSymlink) != 0, nil
}

func IsDirErr(path string) (bool, error) {
if !PathExists(path) {
return false, nil
}
isLink, err := IsSymlink(path)
if err != nil {
return false, err
}
if isLink {
return false, nil
}
statInfo, err := os.Stat(path)
if err != nil {
return false, err
}
return statInfo.IsDir(), nil
}

0 comments on commit fd6d1b2

Please sign in to comment.