Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actions: Support for local packages installation #165

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 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
local-packages-dir: directory
packages:
- package1
- package2
Expand All @@ -20,10 +21,18 @@ Optional properties:
- recommends -- boolean indicating if suggested packages will be installed

- unauthenticated -- boolean indicating if unauthenticated packages can be installed
- local-packages-dir -- directory containing local packages to be installed,
located in the recipe directory ($RECIPEDIR)
*/
package actions

import (
"fmt"
"io/ioutil"
"os"
"path"
"strings"

"github.com/go-debos/debos"
)

Expand All @@ -32,6 +41,7 @@ type AptAction struct {
Recommends bool
Unauthenticated bool
Packages []string
LocalPackagesDir string `yaml:"local-packages-dir"` // external path containing local packages
}

func (apt *AptAction) Run(context *debos.DebosContext) error {
Expand All @@ -49,6 +59,51 @@ func (apt *AptAction) Run(context *debos.DebosContext) error {
aptOptions = append(aptOptions, "install")
aptOptions = append(aptOptions, apt.Packages...)

if apt.LocalPackagesDir != "" {
localpackagesdir := path.Join(context.RecipeDir, apt.LocalPackagesDir)
destination, err := ioutil.TempDir(path.Join(context.Rootdir, "usr/local"), "debs")
if err != nil {
return err
}
defer os.RemoveAll(destination)

This comment was marked as resolved.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defer statement runs at the end of the function.
So, the destination directory is only available during this apt action, and subsequent apt actions will not have access to it.

This comment was marked as resolved.


err = debos.CopyTree(localpackagesdir, 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/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is only a warning i wonder if this should be a separate patch since debootstrap action also moans about this
also, this is in the middle of a chdir, for clarity move it above

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see this warning with debootstrap action

As it is related to following apt-ftparchive commands I think doing this here is right place


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 := os.OpenFile(path.Join(context.Rootdir, "/etc/apt/sources.list.d/debos-local-debs.list"),
os.O_RDWR | os.O_CREATE, 0644)
if err != nil {
return err
}
defer os.RemoveAll(locallist.Name())
_, err = locallist.WriteString(fmt.Sprintf("deb [trusted=yes] file://%s ./\n",
strings.TrimPrefix(destination, context.Rootdir)))
if err != nil {
return err
}
locallist.Close()
}

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 @@ -54,6 +54,7 @@ LABEL org.label-schema.docker.cmd 'docker run \
RUN apt-get update && \
apt-get install -y --no-install-recommends \
apt-transport-https \
apt-utils \

This comment was marked as resolved.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you're right but this is not managed in this project

binfmt-support \
bmap-tools \
btrfs-progs \
Expand Down