Skip to content

Commit

Permalink
run/create: record raw image
Browse files Browse the repository at this point in the history
Record the user-specified "raw" image name in the SpecGenerator, so we
can pass it along to the config when creating a container.  We need a
separate field as the image name in the generator may be set to the
ID of the previously pulled image - ultimately the cause of containers#7404.

Reverting the image name from the ID to the user input would not work
since "alpine" for pulling iterates over the search registries in the
registries.conf but looking up "alpine" normalizes to
"localhost/alpine".

Recording the raw-image name directly in the generator was the best of
the options I considered as no hidden magic from search registries or
normalizations (that may or may not change in the future) can interfere.
The auto-update backend enforces that the raw-image name is a
fully-qualified reference, so we need to worry about that in the front
end.

Fixes: containers#7407
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
  • Loading branch information
vrothberg committed Sep 15, 2020
1 parent 5c47a33 commit a7c30a4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/podman/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ func create(cmd *cobra.Command, args []string) error {
}

imageName := args[0]
rawImageName := ""
if !cliVals.RootFS {
rawImageName = args[0]
name, err := pullImage(args[0])
if err != nil {
return err
Expand All @@ -121,6 +123,7 @@ func create(cmd *cobra.Command, args []string) error {
if err := common.FillOutSpecGen(s, &cliVals, args); err != nil {
return err
}
s.RawImageName = rawImageName

if _, err := createPodIfNecessary(s, cliVals.Net); err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions cmd/podman/containers/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func run(cmd *cobra.Command, args []string) error {
}

imageName := args[0]
rawImageName := ""
if !cliVals.RootFS {
rawImageName = args[0]
name, err := pullImage(args[0])
if err != nil {
return err
Expand Down Expand Up @@ -177,6 +179,7 @@ func run(cmd *cobra.Command, args []string) error {
if err := common.FillOutSpecGen(s, &cliVals, args); err != nil {
return err
}
s.RawImageName = rawImageName
runOpts.Spec = s

if _, err := createPodIfNecessary(s, cliVals.Net); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/specgen/generate/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func MakeContainer(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGener
if len(names) > 0 {
imgName = names[0]
}
options = append(options, libpod.WithRootFSFromImage(newImage.ID(), imgName, s.Image))
options = append(options, libpod.WithRootFSFromImage(newImage.ID(), imgName, s.RawImageName))
}
if err := s.Validate(); err != nil {
return nil, errors.Wrap(err, "invalid config provided")
Expand Down
3 changes: 3 additions & 0 deletions pkg/specgen/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ type ContainerBasicConfig struct {
// If not given, a default location will be used.
// Optional.
ConmonPidFile string `json:"conmon_pid_file,omitempty"`
// RawImageName is the user-specified and unprocessed input referring
// to a local or a remote image.
RawImageName string `json:"raw_image_name,omitempty"`
// RestartPolicy is the container's restart policy - an action which
// will be taken when the container exits.
// If not given, the default policy, which does nothing, will be used.
Expand Down

0 comments on commit a7c30a4

Please sign in to comment.