The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/211
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) === Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
From 7728cf802964be59e0369f7f5767fb0a88dba64a Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Fri, 9 Aug 2019 14:54:49 +0200 Subject: [PATCH] distrobuilder: Support image variant "cloud" Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- distrobuilder/main.go | 21 ++++++++++++++++++++ distrobuilder/main_lxc.go | 11 +++++++++++ distrobuilder/main_lxd.go | 40 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/distrobuilder/main.go b/distrobuilder/main.go index 2cb49d5..29793ff 100644 --- a/distrobuilder/main.go +++ b/distrobuilder/main.go @@ -63,6 +63,7 @@ import ( "strings" "time" + lxd "github.com/lxc/lxd/shared" "github.com/spf13/cobra" "gopkg.in/yaml.v2" @@ -229,6 +230,26 @@ func (c *cmdGlobal) preRunBuild(cmd *cobra.Command, args []string) error { } } + if c.definition.Image.Variant == "cloud" { + // Make sure to install cloud-init if we're building a cloud image + foundCloudInit := false + + for _, set := range c.definition.Packages.Sets { + if lxd.StringInSlice("cloud-init", set.Packages) && lxd.StringInSlice(c.definition.Image.Release, set.Releases) && lxd.StringInSlice(c.definition.Image.ArchitectureMapped, set.Architectures) { + foundCloudInit = true + break + } + } + + if !foundCloudInit { + c.definition.Packages.Sets = append(c.definition.Packages.Sets, + shared.DefinitionPackagesSet{ + Action: "install", + Packages: []string{"cloud-init"}, + }) + } + } + // Install/remove/update packages err = managePackages(c.definition.Packages, c.definition.GetRunnableActions("post-update"), c.definition.Image.Release, diff --git a/distrobuilder/main_lxc.go b/distrobuilder/main_lxc.go index fa966cc..34e5708 100644 --- a/distrobuilder/main_lxc.go +++ b/distrobuilder/main_lxc.go @@ -54,6 +54,11 @@ func (c *cmdLXC) run(cmd *cobra.Command, args []string) error { return fmt.Errorf("Unknown generator '%s'", file.Generator) } + if file.Generator == "cloud-init" { + // Ignore for now and disable cloud-init once all files have been processed + continue + } + if len(file.Releases) > 0 && !lxd.StringInSlice( c.global.definition.Image.Release, file.Releases) { continue @@ -66,6 +71,12 @@ func (c *cmdLXC) run(cmd *cobra.Command, args []string) error { } } + // Disable cloud-init + err := generators.Get("cloud-init").RunLXC(c.global.flagCacheDir, c.global.sourceDir, img, shared.DefinitionFile{}) + if err != nil { + return err + } + exitChroot, err := shared.SetupChroot(c.global.sourceDir, c.global.definition.Environment) if err != nil { diff --git a/distrobuilder/main_lxd.go b/distrobuilder/main_lxd.go index 921d578..47964ee 100644 --- a/distrobuilder/main_lxd.go +++ b/distrobuilder/main_lxd.go @@ -67,6 +67,13 @@ func (c *cmdLXD) run(cmd *cobra.Command, args []string) error { img := image.NewLXDImage(c.global.sourceDir, c.global.targetDir, c.global.flagCacheDir, *c.global.definition) + definedCloudInitFiles := map[string]bool{ + "user-data": false, + "meta-data": false, + "vendor-data": false, + "network-config": false, + } + for _, file := range c.global.definition.Files { if len(file.Releases) > 0 && !lxd.StringInSlice(c.global.definition.Image.Release, file.Releases) { @@ -78,6 +85,16 @@ func (c *cmdLXD) run(cmd *cobra.Command, args []string) error { return fmt.Errorf("Unknown generator '%s'", file.Generator) } + if c.global.definition.Image.Variant == "cloud" && file.Generator == "cloud-init" { + _, ok := definedCloudInitFiles[file.Name] + if !ok { + // Skip unknown cloud-init configuration files + continue + } + + definedCloudInitFiles[file.Name] = true + } + err := generator.RunLXD(c.global.flagCacheDir, c.global.sourceDir, img, file) if err != nil { @@ -85,6 +102,29 @@ func (c *cmdLXD) run(cmd *cobra.Command, args []string) error { } } + // Make sure all cloud-init config files are present if we're building + // a cloud image. + if c.global.definition.Image.Variant == "cloud" { + generator := generators.Get("cloud-init") + + for configFile, ok := range definedCloudInitFiles { + if ok { + // The cloud-init config file has already been defined, possibly + // with custom content. Nothing to do here. + continue + } + + err := generator.RunLXD(c.global.flagCacheDir, c.global.sourceDir, img, + shared.DefinitionFile{ + Generator: "cloud-init", + Name: configFile, + }) + if err != nil { + return err + } + } + } + exitChroot, err := shared.SetupChroot(c.global.sourceDir, c.global.definition.Environment) if err != nil {
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel