Skip to content
Open
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
10 changes: 8 additions & 2 deletions src/cmd/rmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,14 @@ func rmi(cmd *cobra.Command, args []string) error {
}

for _, image := range args {
if _, err := podman.IsToolboxImage(image); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
imageObj, err := podman.InspectImage(image)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: failed to inspect image %s\n", image)
continue
}

if !imageObj.IsToolbx() {
fmt.Fprintf(os.Stderr, "Error: %s is not a Toolbx image\n", image)
continue
}

Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sources = files(
'pkg/podman/errors.go',
'pkg/podman/image.go',
Comment thread
debarshiray marked this conversation as resolved.
'pkg/podman/imageImages_test.go',
'pkg/podman/imageInspect_test.go',
'pkg/podman/podman.go',
'pkg/podman/containerInspect_test.go',
'pkg/shell/shell.go',
Expand Down
137 changes: 129 additions & 8 deletions src/pkg/podman/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Image interface {
Labels() map[string]string
Name() string
Names() []string
Comment thread
DaliborKr marked this conversation as resolved.
RepoTags() []string
}

type Images struct {
Expand All @@ -37,10 +38,21 @@ type Images struct {
}

type imageImages struct {
created string
id string
labels map[string]string
names []string
created string
id string
labels map[string]string
names []string
repoTags []string
}

type imageInspect struct {
created string
entrypoint []string
envVars []string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like entrypoint and envVars are not needed to parse the output of podman inspect --type image into an Image implementation. I suppose you needed them for the changes in #1707 to address #1622 , right? If so, it might be better to move these parts to the pull request that needs them.

More importantly, don't we need to add methods to the Image interface to cover these?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you are right. I prepared fields entrypoint and envVars in advance for #1707, so there is no use case for them right now. We can get rid of them now, and we can add them once we rewrite #1707.

I am not sure about adding methods for them to the Image interface, since imageImages, which parses the podman images command introduced in #1779, does not provide entrypoint and envVars information.

Copy link
Copy Markdown
Collaborator Author

@DaliborKr DaliborKr Apr 14, 2026

Choose a reason for hiding this comment

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

I checked it out to be sure, and it is true. The podman images --format json does not provide properties for entrypoint and envVars.

id string
labels map[string]string
namesHistory []string
repoTags []string
}

type imageSlice []imageImages
Expand Down Expand Up @@ -163,12 +175,24 @@ func (image *imageImages) Names() []string {
return ret
}

func (image *imageImages) RepoTags() []string {
if image.repoTags == nil {
return nil
}

repoTagsCount := len(image.repoTags)
ret := make([]string, repoTagsCount)
copy(ret, image.repoTags)
return ret
}

func (image *imageImages) UnmarshalJSON(data []byte) error {
var raw struct {
Created interface{}
ID string
Labels map[string]string
Names []string
Created interface{}
ID string
Labels map[string]string
Names []string
RepoTags []string
}

if err := json.Unmarshal(data, &raw); err != nil {
Expand All @@ -188,6 +212,103 @@ func (image *imageImages) UnmarshalJSON(data []byte) error {
image.id = raw.ID
image.labels = raw.Labels
image.names = raw.Names
image.repoTags = raw.RepoTags
return nil
}

func (image *imageInspect) Created() string {
return image.created
}

func (image *imageInspect) Entrypoint() []string {
return image.entrypoint
}

func (image *imageInspect) EnvVars() []string {
return image.envVars
}

func (image *imageInspect) ID() string {
return image.id
}

func (image *imageInspect) IsToolbx() bool {
return isToolbx(image.labels)
}

func (image *imageInspect) Labels() map[string]string {
if image.labels == nil {
return nil
}

labelsCount := len(image.labels)
ret := make(map[string]string, labelsCount)
for label, value := range image.labels {
ret[label] = value
}

return ret
}

func (image *imageInspect) Names() []string {
if image.namesHistory == nil {
return nil
}

namesHistoryCount := len(image.namesHistory)
ret := make([]string, namesHistoryCount)
copy(ret, image.namesHistory)
return ret
}

func (image *imageInspect) Name() string {
if len(image.namesHistory) == 0 {
panic("no name is available in Image name history")
}
return image.namesHistory[0]
}

func (image *imageInspect) RepoTags() []string {
if image.repoTags == nil {
return nil
}

repoTagsCount := len(image.repoTags)
ret := make([]string, repoTagsCount)
copy(ret, image.repoTags)
return ret
}

func (image *imageInspect) UnmarshalJSON(data []byte) error {
var raw struct {
Created interface{}
ID string
Config struct {
Labels map[string]string
Env []string
Entrypoint []string
}
NamesHistory []string
RepoTags []string
}

if err := json.Unmarshal(data, &raw); err != nil {
return err
}

switch value := raw.Created.(type) {
case string:
image.created = value
case float64:
image.created = utils.HumanDuration(int64(value))
}

image.id = raw.ID
image.labels = raw.Config.Labels
image.envVars = raw.Config.Env
image.namesHistory = raw.NamesHistory
image.repoTags = raw.RepoTags
image.entrypoint = raw.Config.Entrypoint
return nil
}

Expand Down
32 changes: 30 additions & 2 deletions src/pkg/podman/imageImages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestImageImages(t *testing.T) {
isToolbx bool
labels map[string]string
names []string
repoTags []string
}

testCases := []struct {
Expand Down Expand Up @@ -66,6 +67,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"registry.fedoraproject.org/f29/fedora-toolbox:29",
},
repoTags: nil,
},
{
id: "8c5e0075ddaf4651b73e71dcf420bab922209f246e1165f306f223112a3061a4",
Expand All @@ -74,6 +76,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"localhost/fedora-toolbox-user:29",
},
repoTags: nil,
},
},
imagesCount: 2,
Expand Down Expand Up @@ -101,6 +104,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"registry.fedoraproject.org/f30/fedora-toolbox:30",
},
repoTags: nil,
},
},
imagesCount: 1,
Expand Down Expand Up @@ -156,6 +160,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"registry.fedoraproject.org/fedora-toolbox:32",
},
repoTags: nil,
},
},
imagesCount: 1,
Expand Down Expand Up @@ -217,6 +222,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"registry.fedoraproject.org/fedora-toolbox:35",
},
repoTags: nil,
},
},
imagesCount: 1,
Expand Down Expand Up @@ -276,6 +282,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"registry.fedoraproject.org/fedora-toolbox:38",
},
repoTags: nil,
},
},
imagesCount: 1,
Expand Down Expand Up @@ -350,6 +357,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"localhost/fedora-toolbox:38",
},
repoTags: nil,
},
{
id: "3eda970c1318e5ea564134338746c04d86ae9817c3a0defdc138b8ccdf787285",
Expand All @@ -363,6 +371,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"registry.fedoraproject.org/fedora:38",
},
repoTags: nil,
},
},
imagesCount: 2,
Expand Down Expand Up @@ -432,7 +441,8 @@ func TestImageImages(t *testing.T) {
"vendor": "Fedora Project",
"version": "38",
},
names: nil,
names: nil,
repoTags: nil,
},
{
id: "3eda970c1318e5ea564134338746c04d86ae9817c3a0defdc138b8ccdf787285",
Expand All @@ -446,6 +456,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"registry.fedoraproject.org/fedora:38",
},
repoTags: nil,
},
},
imagesCount: 2,
Expand Down Expand Up @@ -493,6 +504,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"registry.fedoraproject.org/fedora-toolbox:39",
},
repoTags: nil,
},
},
imagesCount: 1,
Expand Down Expand Up @@ -552,6 +564,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"registry.fedoraproject.org/fedora-toolbox:40",
},
repoTags: nil,
},
},
imagesCount: 1,
Expand Down Expand Up @@ -606,7 +619,8 @@ func TestImageImages(t *testing.T) {
"vendor": "Fedora Project",
"version": "40",
},
names: nil,
names: nil,
repoTags: nil,
},
},
imagesCount: 1,
Expand Down Expand Up @@ -701,6 +715,7 @@ func TestImageImages(t *testing.T) {
"localhost/fedora-toolbox:40",
"registry.fedoraproject.org/fedora-toolbox:40",
},
repoTags: nil,
},
{
id: "5c5b2e637806fccb644effa4affc4a5d08dc7e6140586ecb8c601c8739e12628",
Expand All @@ -722,6 +737,7 @@ func TestImageImages(t *testing.T) {
"localhost/fedora-toolbox:40",
"registry.fedoraproject.org/fedora-toolbox:40",
},
repoTags: nil,
},
},
imagesCount: 2,
Expand Down Expand Up @@ -816,6 +832,7 @@ func TestImageImages(t *testing.T) {
"registry.fedoraproject.org/fedora-toolbox:40-test",
"registry.fedoraproject.org/fedora-toolbox:40",
},
repoTags: nil,
},
{
id: "5c5b2e637806fccb644effa4affc4a5d08dc7e6140586ecb8c601c8739e12628",
Expand All @@ -837,6 +854,7 @@ func TestImageImages(t *testing.T) {
"registry.fedoraproject.org/fedora-toolbox:40-test",
"registry.fedoraproject.org/fedora-toolbox:40",
},
repoTags: nil,
},
},
imagesCount: 2,
Expand Down Expand Up @@ -932,6 +950,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"docker.io/library/postgres:latest",
},
repoTags: nil,
},
{
id: "5c5b2e637806fccb644effa4affc4a5d08dc7e6140586ecb8c601c8739e12628",
Expand All @@ -952,6 +971,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"registry.fedoraproject.org/fedora-toolbox:40",
},
repoTags: nil,
},
{
id: "49008798958db0411330d8b6a996c03bdab1d1b10d139e7df2b75ed3298f84a7",
Expand All @@ -972,6 +992,7 @@ func TestImageImages(t *testing.T) {
names: []string{
"registry.fedoraproject.org/fedora-toolbox:40-aarch64",
},
repoTags: nil,
},
},
imagesCount: 3,
Expand Down Expand Up @@ -1020,6 +1041,13 @@ func TestImageImages(t *testing.T) {
}

}

repoTags := image.RepoTags()
if len(repoTags) != 0 {
repoTags[0] = "foo/bar"
}

assert.Equal(t, expect.repoTags, image.RepoTags())
}
})
}
Expand Down
Loading
Loading