podman: add support for --rootfs

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2020-04-24 11:41:37 +02:00
parent 23d431f0bf
commit a3acc4f977
No known key found for this signature in database
GPG Key ID: E4730F97F60286ED
6 changed files with 36 additions and 23 deletions

View File

@ -75,8 +75,7 @@ func init() {
func create(cmd *cobra.Command, args []string) error { func create(cmd *cobra.Command, args []string) error {
var ( var (
err error err error
rawImageInput string
) )
cliVals.Net, err = common.NetFlagsToNetOptions(cmd) cliVals.Net, err = common.NetFlagsToNetOptions(cmd)
if err != nil { if err != nil {
@ -92,20 +91,16 @@ func create(cmd *cobra.Command, args []string) error {
defer errorhandling.SyncQuiet(cidFile) defer errorhandling.SyncQuiet(cidFile)
} }
if rfs := cliVals.RootFS; !rfs {
rawImageInput = args[0]
}
if err := createInit(cmd); err != nil { if err := createInit(cmd); err != nil {
return err return err
} }
if err := pullImage(args[0]); err != nil { if !cliVals.RootFS {
return err if err := pullImage(args[0]); err != nil {
return err
}
} }
s := specgen.NewSpecGenerator(args[0], cliVals.RootFS)
//TODO rootfs still
s := specgen.NewSpecGenerator(rawImageInput)
if err := common.FillOutSpecGen(s, &cliVals, args); err != nil { if err := common.FillOutSpecGen(s, &cliVals, args); err != nil {
return err return err
} }

View File

@ -104,8 +104,10 @@ func run(cmd *cobra.Command, args []string) error {
return err return err
} }
if err := pullImage(args[0]); err != nil { if !cliVals.RootFS {
return err if err := pullImage(args[0]); err != nil {
return err
}
} }
// If -i is not set, clear stdin // If -i is not set, clear stdin
@ -136,7 +138,7 @@ func run(cmd *cobra.Command, args []string) error {
} }
runOpts.Detach = cliVals.Detach runOpts.Detach = cliVals.Detach
runOpts.DetachKeys = cliVals.DetachKeys runOpts.DetachKeys = cliVals.DetachKeys
s := specgen.NewSpecGenerator(args[0]) s := specgen.NewSpecGenerator(args[0], cliVals.RootFS)
if err := common.FillOutSpecGen(s, &cliVals, args); err != nil { if err := common.FillOutSpecGen(s, &cliVals, args); err != nil {
return err return err
} }

View File

@ -24,6 +24,9 @@ func getSeccompConfig(s *specgen.SpecGenerator, configSpec *spec.Spec, img *imag
} }
if scp == seccomp.PolicyImage { if scp == seccomp.PolicyImage {
if img == nil {
return nil, errors.New("cannot read seccomp profile without a valid image")
}
labels, err := img.Labels(context.Background()) labels, err := img.Labels(context.Background())
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -15,7 +15,11 @@ import (
func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerator) error { func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerator) error {
var appendEntryPoint bool var appendEntryPoint bool
// TODO add support for raw rootfs // If a rootfs is used, then there is no image data
if s.ContainerStorageConfig.Rootfs != "" {
return nil
}
newImage, err := r.ImageRuntime().NewFromLocal(s.Image) newImage, err := r.ImageRuntime().NewFromLocal(s.Image)
if err != nil { if err != nil {
return err return err

View File

@ -7,6 +7,7 @@ import (
"github.com/containers/common/pkg/config" "github.com/containers/common/pkg/config"
"github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/define" "github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/pkg/specgen" "github.com/containers/libpod/pkg/specgen"
"github.com/containers/storage" "github.com/containers/storage"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -84,13 +85,16 @@ func MakeContainer(rt *libpod.Runtime, s *specgen.SpecGenerator) (*libpod.Contai
return nil, err return nil, err
} }
options = append(options, createExitCommandOption(s, rt.StorageConfig(), rtc, podmanPath)) options = append(options, createExitCommandOption(s, rt.StorageConfig(), rtc, podmanPath))
newImage, err := rt.ImageRuntime().NewFromLocal(s.Image) var newImage *image.Image
if err != nil { if s.Rootfs != "" {
return nil, err options = append(options, libpod.WithRootFS(s.Rootfs))
} else {
newImage, err = rt.ImageRuntime().NewFromLocal(s.Image)
if err != nil {
return nil, err
}
options = append(options, libpod.WithRootFSFromImage(newImage.ID(), s.Image, s.RawImageName))
} }
options = append(options, libpod.WithRootFSFromImage(newImage.ID(), s.Image, s.RawImageName))
if err := s.Validate(); err != nil { if err := s.Validate(); err != nil {
return nil, errors.Wrap(err, "invalid config provided") return nil, errors.Wrap(err, "invalid config provided")
} }

View File

@ -402,8 +402,13 @@ type NamedVolume struct {
} }
// NewSpecGenerator returns a SpecGenerator struct given one of two mandatory inputs // NewSpecGenerator returns a SpecGenerator struct given one of two mandatory inputs
func NewSpecGenerator(image string) *SpecGenerator { func NewSpecGenerator(arg string, rootfs bool) *SpecGenerator {
csc := ContainerStorageConfig{Image: image} csc := ContainerStorageConfig{}
if rootfs {
csc.Rootfs = arg
} else {
csc.Image = arg
}
return &SpecGenerator{ return &SpecGenerator{
ContainerStorageConfig: csc, ContainerStorageConfig: csc,
} }