The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/94
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === This generator tries to follow to dump generator but for templates. Before i continue witht he work i would like your opinion about the direction this needs to take, or if you don't like it, it can stay in my fork for my personal use. Changes: - added name field `files: []` for the name of the template. .tpl is appended automaticly - added dump-template to the generator code/definition TODO: - [ ] Unit test - [ ] Add properties field for templates - [ ] Documentation
From ba5bdd49e59385614ac831b9f706604332e8c812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robbert=20M=C3=BCller?= <[email protected]> Date: Sat, 12 May 2018 21:22:48 +0200 Subject: [PATCH] add dump-template generator to add templates to the image This generator tries to follow to dump generator but for templates. Changes: - added name field `files: []` for the name of the template. .tpl is appended automaticly - added dump-template to the generator code/definition --- generators/dump-template.go | 62 +++++++++++++++++++++++++++++++++++++++++++++ generators/generators.go | 2 ++ shared/definition.go | 2 ++ 3 files changed, 66 insertions(+) create mode 100644 generators/dump-template.go diff --git a/generators/dump-template.go b/generators/dump-template.go new file mode 100644 index 0000000..e9d89e8 --- /dev/null +++ b/generators/dump-template.go @@ -0,0 +1,62 @@ +package generators + +import ( + "fmt" + "os" + "path/filepath" + + "github.com/lxc/distrobuilder/image" + "github.com/lxc/distrobuilder/shared" + "github.com/lxc/lxd/shared/api" +) + +// DumpTemplateGenerator represents the Remove generator. +type DumpTemplateGenerator struct{} + +// RunLXC dumps content to a file. +func (g DumpTemplateGenerator) RunLXC(cacheDir, sourceDir string, img *image.LXCImage, + defFile shared.DefinitionFile) error { + // no template support for LXC, ignoring generator + return nil +} + +// RunLXD dumps content to a file. +func (g DumpTemplateGenerator) RunLXD(cacheDir, sourceDir string, img *image.LXDImage, + defFile shared.DefinitionFile) error { + templateDir := filepath.Join(cacheDir, "templates") + + err := os.MkdirAll(templateDir, 0755) + if err != nil { + return err + } + template := fmt.Sprintf("%s.tpl", defFile.Name) + + file, err := os.Create(filepath.Join(templateDir, template)) + if err != nil { + return err + } + + defer file.Close() + + _, err = file.WriteString(defFile.Content) + if err != nil { + return fmt.Errorf("Failed to write to content to %s template: %s", defFile.Name, err) + } + + // Add to LXD templates + img.Metadata.Templates[defFile.Path] = &api.ImageMetadataTemplate{ + Template: template, + When: []string{ + "create", + "copy", + }, + } + + return err +} + +// Run does nothing. +func (g DumpTemplateGenerator) Run(cacheDir, sourceDir string, + defFile shared.DefinitionFile) error { + return nil +} diff --git a/generators/generators.go b/generators/generators.go index 60f2995..d91350b 100644 --- a/generators/generators.go +++ b/generators/generators.go @@ -29,6 +29,8 @@ func Get(generator string) Generator { return RemoveGenerator{} case "dump": return DumpGenerator{} + case "dump-template": + return DumpTemplateGenerator{} case "upstart-tty": return UpstartTTYGenerator{} } diff --git a/shared/definition.go b/shared/definition.go index 78b33ec..26e2050 100644 --- a/shared/definition.go +++ b/shared/definition.go @@ -77,6 +77,7 @@ type DefinitionFile struct { Path string `yaml:"path,omitempty"` Content string `yaml:"content,omitempty"` Releases []string `yaml:"releases,omitempty"` + Name string `yaml:"name"` } // A DefinitionAction specifies a custom action (script) which is to be run after @@ -209,6 +210,7 @@ func (d *Definition) Validate() error { validGenerators := []string{ "dump", + "dump-template", "hostname", "hosts", "remove",
_______________________________________________ lxc-devel mailing list [email protected] http://lists.linuxcontainers.org/listinfo/lxc-devel
