Skip to content

Commit

Permalink
Add varlink support for prune
Browse files Browse the repository at this point in the history
Add the ability to prune unused images using the varlink
API.

Signed-off-by: baude <[email protected]>
  • Loading branch information
baude authored and mheon committed Feb 8, 2019
1 parent 9dfefed commit 28f5d25
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 26 deletions.
8 changes: 8 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in

[func ImageExists(name: string) int](#ImageExists)

[func ImagesPrune() []string](#ImagesPrune)

[func ImportImage(source: string, reference: string, message: string, changes: []string) string](#ImportImage)

[func InspectContainer(name: string) string](#InspectContainer)
Expand Down Expand Up @@ -543,6 +545,12 @@ $ varlink call -m unix:/run/podman/io.podman/io.podman.ImageExists '{"name": "im
"exists": 1
}
~~~
### <a name="ImagesPrune"></a>func ImagesPrune
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">

method ImagesPrune() [[]string](#[]string)</div>
ImagesPrune removes all unused images from the local store. Upon successful pruning,
the IDs of the removed images are returned.
### <a name="ImportImage"></a>func ImportImage
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">

Expand Down
15 changes: 13 additions & 2 deletions cmd/podman/images_prune.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"fmt"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/cmd/podman/shared"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -30,5 +30,16 @@ func pruneImagesCmd(c *cli.Context) error {
}
defer runtime.Shutdown(false)

return shared.Prune(runtime.ImageRuntime())
pruneImages, err := runtime.ImageRuntime().GetPruneImages()
if err != nil {
return err
}

for _, i := range pruneImages {
if err := i.Remove(true); err != nil {
return errors.Wrapf(err, "failed to remove %s", i.ID())
}
fmt.Println(i.ID())
}
return nil
}
24 changes: 0 additions & 24 deletions cmd/podman/shared/prune.go

This file was deleted.

4 changes: 4 additions & 0 deletions cmd/podman/varlink/io.podman.varlink
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,10 @@ method MountContainer(name: string) -> (path: string)
# ~~~
method UnmountContainer(name: string, force: bool) -> ()

# ImagesPrune removes all unused images from the local store. Upon successful pruning,
# the IDs of the removed images are returned.
method ImagesPrune() -> (pruned: []string)

# This function is not implemented yet.
method ListContainerPorts(name: string) -> (notimplemented: NotImplemented)

Expand Down
18 changes: 18 additions & 0 deletions pkg/varlinkapi/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,21 @@ func (i *LibpodAPI) ContainerRunlabel(call iopodman.VarlinkCall, input iopodman.
}
return call.ReplyContainerRunlabel()
}

// ImagesPrune ....
func (i *LibpodAPI) ImagesPrune(call iopodman.VarlinkCall) error {
var (
pruned []string
)
pruneImages, err := i.Runtime.ImageRuntime().GetPruneImages()
if err != nil {
return err
}
for _, i := range pruneImages {
if err := i.Remove(true); err != nil {
return call.ReplyErrorOccurred(err.Error())
}
pruned = append(pruned, i.ID())
}
return call.ReplyImagesPrune(pruned)
}

0 comments on commit 28f5d25

Please sign in to comment.