[lxc-devel] [distrobuilder/master] distrobuilder: Extend pongo2 template usage

monstermunchkin on Github lxc-bot at linuxcontainers.org
Mon Nov 18 08:34:54 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 454 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191118/0ea7a708/attachment.bin>
-------------- next part --------------
From 6f3be50263eb658a2afa15f1c6d99716f4a4df84 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 18 Nov 2019 09:26:56 +0100
Subject: [PATCH] distrobuilder: Extend pongo2 template usage

This enables rendering of source keys as well as repository keys.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 distrobuilder/chroot.go | 6 ++++++
 distrobuilder/main.go   | 8 ++++++++
 2 files changed, 14 insertions(+)

diff --git a/distrobuilder/chroot.go b/distrobuilder/chroot.go
index bd116e7..15ee624 100644
--- a/distrobuilder/chroot.go
+++ b/distrobuilder/chroot.go
@@ -30,6 +30,12 @@ func manageRepositories(def *shared.Definition, manager *managers.Manager) error
 			return err
 		}
 
+		// Run template on repo.Key
+		repo.Key, err = shared.RenderTemplate(repo.Key, def)
+		if err != nil {
+			return err
+		}
+
 		err = manager.RepoHandler(repo)
 		if err != nil {
 			return fmt.Errorf("Error for repository %s: %s", repo.Name, err)
diff --git a/distrobuilder/main.go b/distrobuilder/main.go
index ba49e72..043d656 100644
--- a/distrobuilder/main.go
+++ b/distrobuilder/main.go
@@ -236,6 +236,14 @@ func (c *cmdGlobal) preRunBuild(cmd *cobra.Command, args []string) error {
 		return fmt.Errorf("Unsupported source downloader: %s", c.definition.Source.Downloader)
 	}
 
+	// Run template on source keys
+	for i, key := range c.definition.Source.Keys {
+		c.definition.Source.Keys[i], err = shared.RenderTemplate(key, c.definition)
+		if err != nil {
+			return fmt.Errorf("Failed to render source keys: %s", err)
+		}
+	}
+
 	// Download the root filesystem
 	err = downloader.Run(*c.definition, c.sourceDir)
 	if err != nil {


More information about the lxc-devel mailing list