-
Notifications
You must be signed in to change notification settings - Fork 3
/
volume.go
41 lines (35 loc) · 1.21 KB
/
volume.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) ClaceIO, LLC
// SPDX-License-Identifier: Apache-2.0
package container
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"os/exec"
"strings"
"github.com/claceio/clace/internal/types"
)
func GenVolumeName(appId types.AppId, dirName string) VolumeName {
dirHash := sha256.Sum256([]byte(dirName))
hashHex := hex.EncodeToString(dirHash[:])
return VolumeName(fmt.Sprintf("clv-%s-%s", appId, strings.ToLower(hashHex)))
}
func (c ContainerCommand) VolumeExists(config *types.SystemConfig, name VolumeName) bool {
c.Debug().Msgf("Checking volume exists %s", name)
cmd := exec.Command(config.ContainerCommand, "volume", "exists", string(name))
output, err := cmd.CombinedOutput()
if err != nil {
c.Debug().Msgf("volume exists check failed %s %s %s", name, err, output)
}
c.Debug().Msgf("volume exists %s %t", name, err == nil)
return err == nil
}
func (c ContainerCommand) VolumeCreate(config *types.SystemConfig, name VolumeName) error {
c.Debug().Msgf("Creating volume %s", name)
cmd := exec.Command(config.ContainerCommand, "volume", "create", string(name))
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("error creating volume %s: %w %s", name, err, output)
}
return nil
}