[lxc-devel] [distrobuilder/master] distrobuilder: Add actions
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Wed Mar 7 17:08:28 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 379 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180307/12f46fd8/attachment.bin>
-------------- next part --------------
From e0277d7c232c9d40c0717b9bfffebfd794f98ea5 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 7 Mar 2018 18:07:54 +0100
Subject: [PATCH] distrobuilder: Add actions
Resolves #37
Signed-off-by: Thomas Hipp <thomas.hipp at 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)
More information about the lxc-devel
mailing list