From ebe21e8bf0e3b40717e153bedada8c2c1a8031b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= Date: Thu, 25 Apr 2019 12:02:50 +0200 Subject: [PATCH] actions: Support for local packages installation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #157 Signed-off-by: Frédéric Danis --- actions/apt_action.go | 50 +++++++++++++++++++++++++++++++++++++++++++ docker/Dockerfile | 1 + 2 files changed, 51 insertions(+) diff --git a/actions/apt_action.go b/actions/apt_action.go index 6f3988f8..8c39af03 100644 --- a/actions/apt_action.go +++ b/actions/apt_action.go @@ -7,6 +7,7 @@ Yaml syntax: - action: apt recommends: bool unauthenticated: bool + source: directory packages: - package1 - package2 @@ -19,10 +20,15 @@ Optional properties: - recommends -- boolean indicating if suggested packages will be installed - unauthenticated -- boolean indicating if unauthenticated packages can be installed +- source -- directory containing local packages to be installed */ package actions import ( + "fmt" + "os" + "path" + "github.com/go-debos/debos" ) @@ -31,6 +37,7 @@ type AptAction struct { Recommends bool Unauthenticated bool Packages []string + Source string // external path containing local packages } func (apt *AptAction) Run(context *debos.DebosContext) error { @@ -48,6 +55,49 @@ func (apt *AptAction) Run(context *debos.DebosContext) error { aptOptions = append(aptOptions, "install") aptOptions = append(aptOptions, apt.Packages...) + if apt.Source != "" { + sourcedir := path.Join(context.RecipeDir, apt.Source) + destination, err := debos.RestrictedPath(context.Rootdir, "/usr/local/debs") + if err != nil { + return err + } + defer os.RemoveAll(destination) + + err = debos.CopyTree(sourcedir, destination) + if err != nil { + return err + } + + currentDir, _ := os.Getwd() + os.Chdir(destination) + + // apt-ftparchive tries to read /etc/apt/apt.conf.d, add this path temporarily to prevent warnings + os.MkdirAll("/etc/apt/apt.conf.d", 0755) + defer os.RemoveAll("/etc/apt/apt.conf.d/") + + err = debos.Command{}.Run("apt", "sh", "-c", "apt-ftparchive packages . > Packages") + if err != nil { + return err + } + err = debos.Command{}.Run("apt", "sh", "-c", "apt-ftparchive release . > Release") + if err != nil { + return err + } + + os.Chdir(currentDir) + + locallist, err := debos.RestrictedPath(context.Rootdir, "/etc/apt/sources.list.d/local.list") + if err != nil { + return err + } + defer os.RemoveAll(locallist) + cmd := fmt.Sprintf("echo 'deb [trusted=yes] file:///usr/local/debs/ ./' > %s", locallist) + err = debos.Command{}.Run("apt", "sh", "-c", cmd) + if err != nil { + return err + } + } + c := debos.NewChrootCommandForContext(*context) c.AddEnv("DEBIAN_FRONTEND=noninteractive") diff --git a/docker/Dockerfile b/docker/Dockerfile index afe375fb..8ba5b310 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -55,6 +55,7 @@ RUN apt-get update && \ apt-get install -y --no-install-recommends \ libostree-1-1 \ apt-transport-https \ + apt-utils \ ca-certificates \ debootstrap \ pkg-config \