mirror of
https://github.com/coredns/coredns.git
synced 2025-08-05 13:56:59 +02:00
feat: enable plugins via environment during build (#7310)
* feat: enable plugins via environment during build Signed-off-by: Colden Cullen <colden@coldencullen.com> * doc: add note about COREDNS_PLUGINS Signed-off-by: Colden Cullen <colden@coldencullen.com> --------- Signed-off-by: Colden Cullen <colden@coldencullen.com>
This commit is contained in:
parent
1de92ec9dc
commit
82323554ae
@ -67,6 +67,8 @@ $ cd coredns
|
||||
$ make
|
||||
~~~
|
||||
|
||||
> **_NOTE:_** extra plugins may be enabled when building by setting the `COREDNS_PLUGINS` environment variable with comma separate list of plugins in the same format as plugin.cfg
|
||||
|
||||
This should yield a `coredns` binary.
|
||||
|
||||
## Compilation with Docker
|
||||
|
@ -14,6 +14,26 @@ func main() {
|
||||
mi := make(map[string]string, 0)
|
||||
md := []string{}
|
||||
|
||||
parsePlugin := func(element string) {
|
||||
items := strings.Split(element, ":")
|
||||
if len(items) != 2 {
|
||||
// ignore empty lines
|
||||
return
|
||||
}
|
||||
name, repo := items[0], items[1]
|
||||
|
||||
if _, ok := mi[name]; ok {
|
||||
log.Fatalf("Duplicate entry %q", name)
|
||||
}
|
||||
|
||||
md = append(md, name)
|
||||
mi[name] = pluginPath + repo // Default, unless overridden by 3rd arg
|
||||
|
||||
if _, err := os.Stat(pluginFSPath + repo); err != nil { // External package has been given
|
||||
mi[name] = repo
|
||||
}
|
||||
}
|
||||
|
||||
file, err := os.Open(pluginFile)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open %s: %q", pluginFile, err)
|
||||
@ -28,23 +48,11 @@ func main() {
|
||||
continue
|
||||
}
|
||||
|
||||
items := strings.Split(line, ":")
|
||||
if len(items) != 2 {
|
||||
// ignore empty lines
|
||||
continue
|
||||
}
|
||||
name, repo := items[0], items[1]
|
||||
|
||||
if _, ok := mi[name]; ok {
|
||||
log.Fatalf("Duplicate entry %q", name)
|
||||
parsePlugin(line)
|
||||
}
|
||||
|
||||
md = append(md, name)
|
||||
mi[name] = pluginPath + repo // Default, unless overridden by 3rd arg
|
||||
|
||||
if _, err := os.Stat(pluginFSPath + repo); err != nil { // External package has been given
|
||||
mi[name] = repo
|
||||
}
|
||||
for _, element := range strings.Split(os.Getenv("COREDNS_PLUGINS"), ",") {
|
||||
parsePlugin(element)
|
||||
}
|
||||
|
||||
genImports("core/plugin/zplugin.go", "plugin", mi)
|
||||
|
Loading…
Reference in New Issue
Block a user