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 f3866c5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
34 changes: 29 additions & 5 deletions pkgmgr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,61 @@ 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()
userHomeDir, err := os.UserHomeDir()
if err != nil {
return Config{}, fmt.Errorf(
"could not determine user config directory: %s",
"could not determine user home directory: %s",
err,
)
}
userBinDir := fmt.Sprintf("%s/.local/bin", userHomeDir)
userCacheDir, err := os.UserCacheDir()
if err != nil {
return Config{}, fmt.Errorf(
"could not determine user cache directory: %s",
err,
)
}
userConfigDir, err := os.UserConfigDir()
if err != nil {
return Config{}, fmt.Errorf(
"could not determine user config directory: %s",
err,
)
}
userDataDir, err := homedir.GetDataHome()
if err != nil {
return Config{}, fmt.Errorf(
"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 home directory: $HOME is not defined",
"darwin": "could not determine user home 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 f3866c5

Please sign in to comment.