Skip to content

Commit

Permalink
feat: cardano-node data persistence
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <[email protected]>
  • Loading branch information
wolf31o2 committed Feb 29, 2024
1 parent 05bd709 commit 51fed23
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
29 changes: 23 additions & 6 deletions pkgmgr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,54 @@ import (
"log/slog"
"os"
"path/filepath"

"github.com/docker/docker/pkg/homedir"
)

type Config struct {
ConfigDir string
BinDir string
CacheDir string
ConfigDir string
DataDir string
Logger *slog.Logger
Template *Template
}

func NewDefaultConfig() (Config, error) {
userConfigDir, err := os.UserConfigDir()
userBinDir := fmt.Sprintf("%s/.local/bin", homedir.Get())
userCacheDir, err := os.UserCacheDir()
if err != nil {
return Config{}, fmt.Errorf(
"could not determine user cache directory: %s",
err,
)
}
userConfigDir, err := homedir.GetConfigHome()
if err != nil {
return Config{}, fmt.Errorf(
"could not determine user config directory: %s",
err,
)
}
userCacheDir, err := os.UserCacheDir()
userDataDir, err := homedir.GetDataHome()
if err != nil {
return Config{}, fmt.Errorf(
"could not determine user cache directory: %s",
"could not determine user data directory: %s",
err,
)
}
ret := Config{
BinDir: userBinDir,
CacheDir: filepath.Join(
userCacheDir,
"cardano-up",
),
ConfigDir: filepath.Join(
userConfigDir,
"cardano-up",
),
CacheDir: filepath.Join(
userCacheDir,
DataDir: filepath.Join(
userDataDir,
"cardano-up",
),
Logger: slog.Default(),
Expand Down
4 changes: 2 additions & 2 deletions pkgmgr/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func TestNewDefaultConfigXdgConfigCacheEnvVars(t *testing.T) {

func TestNewDefaultConfigEmptyHome(t *testing.T) {
expectedErrs := map[string]string{
"linux": "could not determine user config directory: neither $XDG_CONFIG_HOME nor $HOME are defined",
"darwin": "could not determine user config directory: $HOME is not defined",
"linux": "could not determine user cache directory: neither $XDG_CACHE_HOME nor $HOME are defined",
"darwin": "could not determine user cache directory: $HOME is not defined",
}
origEnvVars := setEnvVars(
map[string]string{
Expand Down
9 changes: 3 additions & 6 deletions pkgmgr/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func (p Package) install(cfg Config, context string) error {
"Version": p.Version,
},
"DataDir": filepath.Join(
cfg.ConfigDir,
"data",
cfg.DataDir,
pkgName,
),
},
Expand Down Expand Up @@ -230,8 +229,7 @@ func (p *PackageInstallStepFile) install(cfg Config, pkgName string) error {
return err
}
filePath := filepath.Join(
cfg.ConfigDir,
"data",
cfg.DataDir,
pkgName,
tmpFilePath,
)
Expand All @@ -256,8 +254,7 @@ func (p *PackageInstallStepFile) install(cfg Config, pkgName string) error {

func (p *PackageInstallStepFile) uninstall(cfg Config, pkgName string) error {
filePath := filepath.Join(
cfg.ConfigDir,
"data",
cfg.DataDir,
pkgName,
p.Filename,
)
Expand Down
3 changes: 3 additions & 0 deletions pkgmgr/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ var RegistryPackages = []Package{
"NETWORK": "{{ .Context.Network }}",
"CARDANO_NODE_SOCKET_PATH": "/ipc/node.socket",
},
Binds: []string{
"{{ .DataDir }}/data:/data",
},
Ports: []string{
"3001",
},
Expand Down

0 comments on commit 51fed23

Please sign in to comment.