-
Notifications
You must be signed in to change notification settings - Fork 291
/
gen-plugin-index.go
50 lines (38 loc) · 1.75 KB
/
gen-plugin-index.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"flag"
"os"
"path/filepath"
"github.com/kubeshop/botkube/pkg/loggerx"
"github.com/kubeshop/botkube/pkg/plugin"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
)
const filePerm = 0o644
func main() {
var (
urlBasePath = flag.String("url-base-path", os.Getenv("PLUGIN_DOWNLOAD_URL_BASE_PATH"), "Defines the URL base path for downloading the plugin binaries")
binsDir = flag.String("binaries-path", "./plugin-dist", "Defines the local path to plugins binaries folder")
output = flag.String("output-path", "./plugins-index.yaml", "Defines the local path where index YAML should be saved")
pluginNameFilter = flag.String("plugin-name-filter", "", "Defines the plugin name regex for plugins which should be included in the index. Other plugins will be skipped.")
useArchive = flag.Bool("use-archive", true, "If enabled, archives are used instead of binaries for constructing plugin download URLs.")
)
flag.Parse()
logger := logrus.New()
idxBuilder := plugin.NewIndexBuilder(logger)
absBinsDir, err := filepath.Abs(*binsDir)
loggerx.ExitOnError(err, "while resolving an absolute path of binaries folder")
log := logger.WithFields(logrus.Fields{
"binDir": absBinsDir,
"urlBasePath": *urlBasePath,
"pluginNameFilter": *pluginNameFilter,
})
log.Info("Building index..")
idx, err := idxBuilder.Build(absBinsDir, *urlBasePath, *pluginNameFilter, false, *useArchive)
loggerx.ExitOnError(err, "while building plugin index")
raw, err := yaml.Marshal(idx)
loggerx.ExitOnError(err, "while marshaling index into YAML format")
logger.WithField("output", *output).Info("Saving index file...")
err = os.WriteFile(*output, raw, filePerm)
loggerx.ExitOnError(err, "while saving index file")
}