Skip to content

Commit

Permalink
actions: Support for local packages installation
Browse files Browse the repository at this point in the history
Fix go-debos#157

Signed-off-by: Frédéric Danis <[email protected]>
  • Loading branch information
fdanis-oss committed Apr 26, 2019
1 parent 0236d75 commit ebe21e8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
50 changes: 50 additions & 0 deletions actions/apt_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Yaml syntax:
- action: apt
recommends: bool
unauthenticated: bool
source: directory
packages:
- package1
- package2
Expand All @@ -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"
)

Expand All @@ -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 {
Expand All @@ -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")

Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit ebe21e8

Please sign in to comment.