Skip to content

Commit

Permalink
Fix issue when using relative paths for KITOPS_HOME
Browse files Browse the repository at this point in the history
Since kit sometimes changes directory while packing/unpacking, using a
relative path for KITOPS_HOME (or the --config parameter) would lead to
the CLI using an unexpected location -- for example, running

  KITOPS_HOME=./my-kitops-storage
  kit pack -t my-model ./my-model-path

would lead to kit storing the model in ./my-model-path/my-kitops-storage
instead of the expected ./my-kitops-storage.

Instead, we take the absolute path for the parameter at the
beginning and use that.
  • Loading branch information
amisevsk committed Jun 26, 2024
1 parent 0826358 commit 2301093
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package cmd

import (
"context"
"fmt"
"os"
"path/filepath"

"kitops/pkg/cmd/dev"
"kitops/pkg/cmd/info"
Expand Down Expand Up @@ -117,13 +119,21 @@ func Execute() {
func getConfigHome(opts *rootOptions) (string, error) {
if opts.configHome != "" {
output.Debugf("Using config directory from flag: %s", opts.configHome)
return opts.configHome, nil
absHome, err := filepath.Abs(opts.configHome)
if err != nil {
return "", fmt.Errorf("failed to get absolute path for %s: %w", opts.configHome, err)
}
return absHome, nil
}

envHome := os.Getenv("KITOPS_HOME")
if envHome != "" {
output.Debugf("Using config directory from environment variable: %s", envHome)
return envHome, nil
absHome, err := filepath.Abs(envHome)
if err != nil {
return "", fmt.Errorf("failed to get absolute path for $KITOPS_HOME: %w", err)
}
return absHome, nil
}

defaultHome, err := constants.DefaultConfigPath()
Expand Down

0 comments on commit 2301093

Please sign in to comment.