mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04: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:
		| @@ -67,6 +67,8 @@ $ cd coredns | |||||||
| $ make | $ 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. | This should yield a `coredns` binary. | ||||||
|  |  | ||||||
| ## Compilation with Docker | ## Compilation with Docker | ||||||
|   | |||||||
| @@ -14,6 +14,26 @@ func main() { | |||||||
| 	mi := make(map[string]string, 0) | 	mi := make(map[string]string, 0) | ||||||
| 	md := []string{} | 	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) | 	file, err := os.Open(pluginFile) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Fatalf("Failed to open %s: %q", pluginFile, err) | 		log.Fatalf("Failed to open %s: %q", pluginFile, err) | ||||||
| @@ -28,23 +48,11 @@ func main() { | |||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		items := strings.Split(line, ":") | 		parsePlugin(line) | ||||||
| 		if len(items) != 2 { | 	} | ||||||
| 			// ignore empty lines |  | ||||||
| 			continue |  | ||||||
| 		} |  | ||||||
| 		name, repo := items[0], items[1] |  | ||||||
|  |  | ||||||
| 		if _, ok := mi[name]; ok { | 	for _, element := range strings.Split(os.Getenv("COREDNS_PLUGINS"), ",") { | ||||||
| 			log.Fatalf("Duplicate entry %q", name) | 		parsePlugin(element) | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		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 |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	genImports("core/plugin/zplugin.go", "plugin", mi) | 	genImports("core/plugin/zplugin.go", "plugin", mi) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user