Skip to content

Commit

Permalink
fix: add Config.BinDir
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Aug 25, 2021
1 parent 6002576 commit 5ee68a4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/controller/config.go
Expand Up @@ -14,6 +14,7 @@ import (
type Config struct {
Packages []*Package
InlineRepository []*PackageInfo `yaml:"inline_repository"`
BinDir string `yaml:"bin_dir"`
}

type Package struct {
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/exec.go
Expand Up @@ -17,12 +17,12 @@ func (ctrl *Controller) Exec(ctx context.Context, param *Param, args []string) e
return errors.New("command is required")
}
exeName := args[0]
cfg := Config{}
cfg := &Config{}
wd, err := os.Getwd()
if err != nil {
return fmt.Errorf("get the current directory: %w", err)
}
if err := ctrl.readConfig(wd, param.ConfigFilePath, &cfg); err != nil {
if err := ctrl.readConfig(wd, param.ConfigFilePath, cfg); err != nil {
return err
}
inlineRepo := make(map[string]*PackageInfo, len(cfg.InlineRepository))
Expand All @@ -34,7 +34,7 @@ func (ctrl *Controller) Exec(ctx context.Context, param *Param, args []string) e
continue
}

if err := ctrl.installPackage(ctx, inlineRepo, pkg); err != nil {
if err := ctrl.installPackage(ctx, inlineRepo, pkg, cfg); err != nil {
return err
}

Expand Down
18 changes: 12 additions & 6 deletions pkg/controller/install.go
Expand Up @@ -11,14 +11,20 @@ import (
)

func (ctrl *Controller) Install(ctx context.Context, param *Param) error {
cfg := Config{}
cfg := &Config{}
wd, err := os.Getwd()
if err != nil {
return fmt.Errorf("get the current directory: %w", err)
}
if err := ctrl.readConfig(wd, param.ConfigFilePath, &cfg); err != nil {
if err := ctrl.readConfig(wd, param.ConfigFilePath, cfg); err != nil {
return err
}
if cfg.BinDir == "" {
cfg.BinDir = filepath.Join(filepath.Dir(param.ConfigFilePath), ".aqua", "bin")
}
if err := os.MkdirAll(cfg.BinDir, 0o775); err != nil { //nolint:gomnd
return fmt.Errorf("create the directory: %w", err)
}
inlineRepo := make(map[string]*PackageInfo, len(cfg.InlineRepository))
for _, pkgInfo := range cfg.InlineRepository {
inlineRepo[pkgInfo.Name] = pkgInfo
Expand All @@ -31,14 +37,14 @@ func (ctrl *Controller) Install(ctx context.Context, param *Param) error {
}

for _, pkg := range cfg.Packages {
if err := ctrl.installPackage(ctx, inlineRepo, pkg); err != nil {
if err := ctrl.installPackage(ctx, inlineRepo, pkg, cfg); err != nil {
return fmt.Errorf("install the package %s: %w", pkg.Name, err)
}
}
return nil
}

func (ctrl *Controller) installPackage(ctx context.Context, inlineRepo map[string]*PackageInfo, pkg *Package) error {
func (ctrl *Controller) installPackage(ctx context.Context, inlineRepo map[string]*PackageInfo, pkg *Package, cfg *Config) error {
logE := logrus.WithFields(logrus.Fields{
"package_name": pkg.Name,
"package_version": pkg.Version,
Expand Down Expand Up @@ -80,10 +86,10 @@ func (ctrl *Controller) installPackage(ctx context.Context, inlineRepo map[strin

// create a symbolic link
for _, file := range pkgInfo.Files {
if _, err := os.Stat(filepath.Join(ctrl.RootDir, "bin", file.Name)); err == nil {
if _, err := os.Stat(filepath.Join(cfg.BinDir, file.Name)); err == nil {
continue
}
if err := os.Symlink("aqua-proxy", filepath.Join(ctrl.RootDir, "bin", file.Name)); err != nil {
if err := os.Symlink(filepath.Join(ctrl.RootDir, "bin", "aqua-proxy"), filepath.Join(cfg.BinDir, file.Name)); err != nil {
return fmt.Errorf("create a symbolic link: %w", err)
}
}
Expand Down

0 comments on commit 5ee68a4

Please sign in to comment.