Skip to content

Commit

Permalink
Search for local runtime per values in containers.conf
Browse files Browse the repository at this point in the history
After determining the type of runtime to use,
either "runc" or "crun" dependent upon the system, search
the list of that type of runtime in the containers.conf
file.  It includes the location of those runtimes in a
number of different architectures.  Once found, set the
runtime to use to that value.

Fixes: containers#2113

Signed-off-by: TomSweeneyRedHat <[email protected]>
  • Loading branch information
TomSweeneyRedHat committed Feb 27, 2020
1 parent 270e9e7 commit 20a4cd0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/buildah/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/containers/buildah"
buildahcli "github.com/containers/buildah/pkg/cli"
"github.com/containers/buildah/pkg/parse"
"github.com/containers/buildah/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -62,7 +61,8 @@ func init() {
flags.StringSliceVar(&opts.capDrop, "cap-drop", []string{}, "drop the specified capability (default [])")
flags.StringVar(&opts.hostname, "hostname", "", "set the hostname inside of the container")
flags.StringVar(&opts.isolation, "isolation", buildahcli.DefaultIsolation(), "`type` of process isolation to use. Use BUILDAH_ISOLATION environment variable to override.")
flags.StringVar(&opts.runtime, "runtime", util.Runtime(), "`path` to an alternate OCI runtime")
// Do not set a default runtime here, we'll do that later in the processing.
flags.StringVar(&opts.runtime, "runtime", "", "`path` to an alternate OCI runtime")
flags.StringSliceVar(&opts.runtimeFlag, "runtime-flag", []string{}, "add global flags for the container runtime")
flags.BoolVar(&opts.noPivot, "no-pivot", false, "do not use pivot root to jail process inside rootfs")
flags.StringArrayVar(&opts.securityOption, "security-opt", []string{}, "security options (default [])")
Expand Down
5 changes: 5 additions & 0 deletions run_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ func runUsingRuntime(isolation Isolation, options RunOptions, configureNetwork b
runtime := options.Runtime
if runtime == "" {
runtime = util.Runtime()

localRuntime := util.FindLocalRuntime(runtime)
if localRuntime != "" {
runtime = localRuntime
}
}

// Default to just passing down our stdio.
Expand Down
31 changes: 31 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sync"
"syscall"

"github.com/containers/common/pkg/config"
"github.com/containers/image/v5/docker/reference"
"github.com/containers/image/v5/pkg/sysregistriesv2"
"github.com/containers/image/v5/signature"
Expand Down Expand Up @@ -432,3 +433,33 @@ var (
isUnified bool
isUnifiedErr error
)

// fileExistsAndNotADir - Check to see if a file exists
// and that it is not a directory.
func fileExistsAndNotADir(path string) bool {
file, err := os.Stat(path)

if file == nil || err != nil || os.IsNotExist(err) == true {
return false
}
return !file.IsDir()
}

// FindLocalRuntime find the local runtime of the
// system searching through the config file for
// possible locations.
func FindLocalRuntime(runtime string) string {
var localRuntime string
conf, err := config.Default()
if err != nil {
logrus.Debugf("Error loading container config when searching for local runtime.")
return localRuntime
}
for _, val := range conf.Libpod.OCIRuntimes[runtime] {
if fileExistsAndNotADir(val) {
localRuntime = val
break
}
}
return localRuntime
}

0 comments on commit 20a4cd0

Please sign in to comment.