Skip to content

Commit

Permalink
feat: install aqua-proxy automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Aug 25, 2021
1 parent 42902cb commit 052129e
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions pkg/controller/install.go
Expand Up @@ -23,6 +23,13 @@ func (ctrl *Controller) Install(ctx context.Context, param *Param) error {
for _, pkgInfo := range cfg.InlineRepository {
inlineRepo[pkgInfo.Name] = pkgInfo
}

if _, err := os.Stat(filepath.Join(ctrl.RootDir, "bin", "aqua-proxy")); err != nil {
if err := ctrl.installProxy(ctx); err != nil {
return err
}
}

for _, pkg := range cfg.Packages {
if err := ctrl.installPackage(ctx, inlineRepo, pkg); err != nil {
return fmt.Errorf("install the package %s: %w", pkg.Name, err)
Expand Down Expand Up @@ -87,3 +94,52 @@ func (ctrl *Controller) installPackage(ctx context.Context, inlineRepo map[strin
func getPkgPath(aquaRootDir string, pkg *Package, pkgInfo *PackageInfo, assetName string) string {
return filepath.Join(aquaRootDir, "pkgs", pkgInfo.Type, "github.com", pkgInfo.Repo, pkg.Version, assetName)
}

func (ctrl *Controller) installProxy(ctx context.Context) error {
pkg := &Package{
Name: "aqua-proxy",
Version: "v0.1.0",
Repository: "inline",
}
logE := logrus.WithFields(logrus.Fields{
"package_name": pkg.Name,
"package_version": pkg.Version,
"repository": pkg.Repository,
})
logE.Info("install the proxy")
pkgInfo := &PackageInfo{
Name: "inline",
Type: "github_release",
Repo: "suzuki-shunsuke/aqua-proxy",
Artifact: nil,
Files: []*File{
{
Name: "aqua-proxy",
Src: "aqua-proxy",
},
},
}
assetName := "aqua-proxy_linux_amd64.tar.gz"

pkgPath := getPkgPath(ctrl.RootDir, pkg, pkgInfo, assetName)
// check if the repository exists
logE.Debug("check if the package is already installed")
finfo, err := os.Stat(pkgPath)
if err != nil {
// file doesn't exist
if err := ctrl.download(ctx, pkg, pkgInfo, pkgPath, assetName); err != nil {
return err
}
} else {
if !finfo.IsDir() {
return fmt.Errorf("%s isn't a directory", pkgPath)
}
}

// create a symbolic link
if err := os.Symlink(filepath.Join(pkgPath, "aqua-proxy"), filepath.Join(ctrl.RootDir, "bin", "aqua-proxy")); err != nil {
return fmt.Errorf("create a symbolic link: %w", err)
}

return nil
}

0 comments on commit 052129e

Please sign in to comment.