Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Commit 4e55fbf

Browse files
committed
fixed unable to start plugins issue
1 parent e0a7816 commit 4e55fbf

1 file changed

Lines changed: 55 additions & 4 deletions

File tree

plugin/service.go

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,13 @@ func (svc *Service) GetPublicPluginInfo(fullName string) (res interface{}, err e
352352
}
353353

354354
func (svc *Service) installPublic(p interfaces.Plugin) (err error) {
355-
p.SetInstallUrl(fmt.Sprintf("%s/%s", svc.ps.PluginBaseUrl, p.GetFullName()))
356-
return svc.installGit(p)
355+
if utils.IsDocker() {
356+
p.SetInstallUrl(fmt.Sprintf("%s/%s", constants.DefaultSettingPluginBaseUrl, p.GetFullName()))
357+
return svc.installRemote(p)
358+
} else {
359+
p.SetInstallUrl(fmt.Sprintf("%s/%s", svc.ps.PluginBaseUrl, p.GetFullName()))
360+
return svc.installGit(p)
361+
}
357362
}
358363

359364
func (svc *Service) installGit(p interfaces.Plugin) (err error) {
@@ -440,6 +445,52 @@ func (svc *Service) installLocal(p interfaces.Plugin) (err error) {
440445
return nil
441446
}
442447

448+
func (svc *Service) installRemote(p interfaces.Plugin) (err error) {
449+
log.Infof("remote installing %s", p.GetInstallUrl())
450+
451+
// download plugin.json
452+
res, err := req.Get(p.GetInstallUrl())
453+
if err != nil {
454+
return trace.TraceError(err)
455+
}
456+
pluginPath := filepath.Join(os.TempDir(), uuid.New().String())
457+
if err := ioutil.WriteFile(pluginPath, res.Bytes(), os.FileMode(0666)); err != nil {
458+
return trace.TraceError(err)
459+
}
460+
461+
// plugin.json
462+
_p, err := svc.getPluginFromJson(pluginPath)
463+
if err != nil {
464+
return err
465+
}
466+
467+
// set plugin name
468+
if p.GetFullName() != "" && _p.GetFullName() == "" {
469+
_p.SetFullName(p.GetFullName())
470+
}
471+
472+
// fill plugin data and save to db
473+
if svc.cfgSvc.IsMaster() {
474+
_p.SetId(p.GetId())
475+
if err := svc.savePlugin(_p); err != nil {
476+
return err
477+
}
478+
}
479+
480+
// sync to fs
481+
fsSvc, err := GetPluginFsService(p.GetId())
482+
if err != nil {
483+
return err
484+
}
485+
if err := fsSvc.GetFsService().GetFs().SyncLocalToRemote(pluginPath, fsSvc.GetFsPath()); err != nil {
486+
return err
487+
}
488+
489+
log.Infof("remote installed %s", p.GetInstallUrl())
490+
491+
return nil
492+
}
493+
443494
func (svc *Service) getDaemon(id primitive.ObjectID) (d interfaces.ProcessDaemon) {
444495
res, ok := svc.daemonMap.Load(id)
445496
if !ok {
@@ -755,7 +806,7 @@ func (svc *Service) _getGlobalSettings() (err error) {
755806
if err != nil {
756807
if err.Error() == mongo.ErrNoDocuments.Error() {
757808
svc.ps = entity.PluginSetting{
758-
PluginBaseUrl: constants.DefaultSettingPluginBaseUrl,
809+
PluginBaseUrl: constants.DefaultSettingPluginBaseUrlGitHub,
759810
GithubPublicOrg: constants.DefaultSettingPluginGithubPublicOrg,
760811
RepoPrefix: constants.DefaultSettingPluginRepoPrefix,
761812
}
@@ -801,7 +852,7 @@ func (svc *Service) _getGlobalSettings() (err error) {
801852

802853
func (svc *Service) _getPublicPluginList() (res string, err error) {
803854
// http request
804-
url := fmt.Sprintf("https://api.github.com/orgs/%s/repos", svc.ps.GithubPublicOrg)
855+
url := fmt.Sprintf("%s/plugins.json", constants.DefaultSettingPluginBaseUrl)
805856
r, err := req.Get(url)
806857
if err != nil {
807858
return "", trace.TraceError(err)

0 commit comments

Comments
 (0)