summaryrefslogtreecommitdiff
path: root/actions/apt_action.go
diff options
context:
space:
mode:
Diffstat (limited to 'actions/apt_action.go')
-rw-r--r--actions/apt_action.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/actions/apt_action.go b/actions/apt_action.go
new file mode 100644
index 0000000..681c069
--- /dev/null
+++ b/actions/apt_action.go
@@ -0,0 +1,61 @@
+/*
+Apt Action
+
+Install packages and their dependencies to the target rootfs with 'apt'.
+
+Yaml syntax:
+ - action: apt
+ recommends: bool
+ packages:
+ - package1
+ - package2
+
+Mandatory properties:
+
+- packages -- list of packages to install
+
+Optional properties:
+
+- recommends -- boolean indicating if suggested packages will be installed
+*/
+package actions
+
+import (
+ "github.com/go-debos/debos"
+)
+
+type AptAction struct {
+ debos.BaseAction `yaml:",inline"`
+ Recommends bool
+ Packages []string
+}
+
+func (apt *AptAction) Run(context *debos.DebosContext) error {
+ apt.LogStart()
+ aptOptions := []string{"apt-get", "-y"}
+
+ if !apt.Recommends {
+ aptOptions = append(aptOptions, "--no-install-recommends")
+ }
+
+ aptOptions = append(aptOptions, "install")
+ aptOptions = append(aptOptions, apt.Packages...)
+
+ c := debos.NewChrootCommandForContext(*context)
+ c.AddEnv("DEBIAN_FRONTEND=noninteractive")
+
+ err := c.Run("apt", "apt-get", "update")
+ if err != nil {
+ return err
+ }
+ err = c.Run("apt", aptOptions...)
+ if err != nil {
+ return err
+ }
+ err = c.Run("apt", "apt-get", "clean")
+ if err != nil {
+ return err
+ }
+
+ return nil
+}