The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/42

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) ===
Resolves #37

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
From e0277d7c232c9d40c0717b9bfffebfd794f98ea5 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Wed, 7 Mar 2018 18:07:54 +0100
Subject: [PATCH] distrobuilder: Add actions

Resolves #37

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 distrobuilder/chroot.go   |  8 +++++++-
 distrobuilder/main.go     | 18 +++++++++++++++++-
 distrobuilder/main_lxc.go | 15 +++++++++++++--
 distrobuilder/main_lxd.go | 14 ++++++++++++--
 4 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/distrobuilder/chroot.go b/distrobuilder/chroot.go
index f859dcb..bb63cf9 100644
--- a/distrobuilder/chroot.go
+++ b/distrobuilder/chroot.go
@@ -228,7 +228,7 @@ func setupChroot(rootfs string) (func() error, error) {
        }, nil
 }
 
-func managePackages(def shared.DefinitionPackages) error {
+func managePackages(def shared.DefinitionPackages, postUpdate string) error {
        var err error
 
        manager := managers.Get(def.Manager)
@@ -246,6 +246,12 @@ func managePackages(def shared.DefinitionPackages) error {
                if err != nil {
                        return err
                }
+
+               // Run post update hook
+               err = shared.RunCommand("sh", postUpdate)
+               if err != nil {
+                       return err
+               }
        }
 
        err = manager.Install(def.Install)
diff --git a/distrobuilder/main.go b/distrobuilder/main.go
index f469978..fb4ac25 100644
--- a/distrobuilder/main.go
+++ b/distrobuilder/main.go
@@ -172,6 +172,14 @@ func (c *cmdGlobal) preRunBuild(cmd *cobra.Command, args 
[]string) error {
                return fmt.Errorf("Error while downloading source: %s", err)
        }
 
+       // Run post unpack hook
+       if c.definition.Actions.PostUnpack != "" {
+               err := shared.RunCommand("sh", c.definition.Actions.PostUnpack)
+               if err != nil {
+                       return fmt.Errorf("Failed to run post-unpack: %s", err)
+               }
+       }
+
        // Setup the mounts and chroot into the rootfs
        exitChroot, err := setupChroot(c.rootfsDir)
        if err != nil {
@@ -179,7 +187,7 @@ func (c *cmdGlobal) preRunBuild(cmd *cobra.Command, args 
[]string) error {
        }
 
        // Install/remove/update packages
-       err = managePackages(c.definition.Packages)
+       err = managePackages(c.definition.Packages, 
c.definition.Actions.PostUpdate)
        if err != nil {
                exitChroot()
                return fmt.Errorf("Failed to manage packages: %s", err)
@@ -188,6 +196,14 @@ func (c *cmdGlobal) preRunBuild(cmd *cobra.Command, args 
[]string) error {
        // Unmount everything and exit the chroot
        exitChroot()
 
+       // Run post packages hook
+       if c.definition.Actions.PostPackages != "" {
+               err := shared.RunCommand("sh", 
c.definition.Actions.PostPackages)
+               if err != nil {
+                       return fmt.Errorf("Failed to run post-packages: %s", 
err)
+               }
+       }
+
        return nil
 }
 
diff --git a/distrobuilder/main_lxc.go b/distrobuilder/main_lxc.go
index 8690ef7..2a6ed51 100644
--- a/distrobuilder/main_lxc.go
+++ b/distrobuilder/main_lxc.go
@@ -3,10 +3,12 @@ package main
 import (
        "fmt"
 
-       "github.com/lxc/distrobuilder/generators"
-       "github.com/lxc/distrobuilder/image"
        lxd "github.com/lxc/lxd/shared"
        "github.com/spf13/cobra"
+
+       "github.com/lxc/distrobuilder/generators"
+       "github.com/lxc/distrobuilder/image"
+       "github.com/lxc/distrobuilder/shared"
 )
 
 type cmdLXC struct {
@@ -63,6 +65,15 @@ func (c *cmdLXC) run(cmd *cobra.Command, args []string) 
error {
                if err != nil {
                        continue
                }
+
+       }
+
+       // Run post packages hook
+       if c.global.definition.Actions.PostPackages != "" {
+               err := shared.RunCommand("sh", 
c.global.definition.Actions.PostPackages)
+               if err != nil {
+                       return fmt.Errorf("Failed to run post-packages: %s", 
err)
+               }
        }
 
        err := img.Build()
diff --git a/distrobuilder/main_lxd.go b/distrobuilder/main_lxd.go
index 144abc6..ac57c70 100644
--- a/distrobuilder/main_lxd.go
+++ b/distrobuilder/main_lxd.go
@@ -4,10 +4,12 @@ import (
        "errors"
        "fmt"
 
-       "github.com/lxc/distrobuilder/generators"
-       "github.com/lxc/distrobuilder/image"
        lxd "github.com/lxc/lxd/shared"
        "github.com/spf13/cobra"
+
+       "github.com/lxc/distrobuilder/generators"
+       "github.com/lxc/distrobuilder/image"
+       "github.com/lxc/distrobuilder/shared"
 )
 
 type cmdLXD struct {
@@ -83,6 +85,14 @@ func (c *cmdLXD) run(cmd *cobra.Command, args []string) 
error {
                }
        }
 
+       // Run post packages hook
+       if c.global.definition.Actions.PostPackages != "" {
+               err := shared.RunCommand("sh", 
c.global.definition.Actions.PostPackages)
+               if err != nil {
+                       return fmt.Errorf("Failed to run post-packages: %s", 
err)
+               }
+       }
+
        err := img.Build(c.flagType == "unified", c.flagCompression)
        if err != nil {
                return fmt.Errorf("Failed to create LXD image: %s", err)
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to