Skip to content
Closed
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
23 changes: 10 additions & 13 deletions cmd/buildah/list.go → cmd/buildah/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,28 @@ import (
)

var (
// TODO implement
listFlags = []cli.Flag{
containersFlags = []cli.Flag{
cli.BoolFlag{
Name: "quiet, q",
Usage: "list only container image id's",
Usage: "display only container IDs",
},
cli.BoolFlag{
Name: "noheading, n",
Usage: "do not print column headings",
},
}
listDescription = "Lists containers which appear to be " + buildah.Package + " working containers, their\n names and IDs, and the names and IDs of the images from which they were\n initialized"

listCommand = cli.Command{
Name: "list",
containersDescription = "Lists containers which appear to be " + buildah.Package + " working containers, their\n names and IDs, and the names and IDs of the images from which they were\n initialized"
containersCommand = cli.Command{
Name: "containers",
Usage: "List working containers and their base images",
Description: listDescription,
Flags: listFlags,
Action: listCmd,
Description: containersDescription,
Flags: containersFlags,
Action: containersCmd,
ArgsUsage: " ",
}
)

func listCmd(c *cli.Context) error {
func containersCmd(c *cli.Context) error {
store, err := getStore(c)
if err != nil {
return err
Expand All @@ -41,7 +39,6 @@ func listCmd(c *cli.Context) error {
if c.IsSet("quiet") {
quiet = c.Bool("quiet")
}

noheading := false
if c.IsSet("noheading") {
noheading = c.Bool("noheading")
Expand All @@ -59,7 +56,7 @@ func listCmd(c *cli.Context) error {
builder.FromImage = buildah.BaseImageFakeName
}
if quiet {
fmt.Printf("%-64s\n", builder.ContainerID)
fmt.Printf("%s\n", builder.ContainerID)
} else {
fmt.Printf("%-64s %-64s %-10s %s\n", builder.ContainerID, builder.FromImageID, builder.FromImage, builder.Container)
}
Expand Down
69 changes: 69 additions & 0 deletions cmd/buildah/images.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package main

import (
"fmt"

"github.com/urfave/cli"
)

var (
imagesFlags = []cli.Flag{
cli.BoolFlag{
Name: "quiet, q",
Usage: "display only container IDs",
},
cli.BoolFlag{
Name: "noheading, n",
Usage: "do not print column headings",
},
}
imagesDescription = "Lists locally stored images."
imagesCommand = cli.Command{
Name: "images",
Usage: "List images in local storage",
Description: imagesDescription,
Flags: imagesFlags,
Action: imagesCmd,
ArgsUsage: " ",
}
)

func imagesCmd(c *cli.Context) error {
store, err := getStore(c)
if err != nil {
return err
}

quiet := false
if c.IsSet("quiet") {
quiet = c.Bool("quiet")
}
noheading := false
if c.IsSet("noheading") {
noheading = c.Bool("noheading")
}

images, err := store.Images()
if err != nil {
return fmt.Errorf("error reading images: %v", err)
}

if len(images) > 0 && !noheading && !quiet {
fmt.Printf("%-64s %s\n", "IMAGE ID", "IMAGE NAME")
}
for _, image := range images {
if quiet {
fmt.Printf("%s\n", image.ID)
} else {
names := []string{""}
if len(image.Names) > 0 {
names = image.Names
}
for _, name := range names {
fmt.Printf("%-64s %s\n", image.ID, name)
}
}
}

return nil
}
6 changes: 4 additions & 2 deletions cmd/buildah/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ func main() {
commitCommand,
configCommand,
copyCommand,
deleteCommand,
rmCommand,
fromCommand,
listCommand,
containersCommand,
mountCommand,
runCommand,
umountCommand,
imagesCommand,
rmiCommand,
}
err := app.Run(os.Args)
if err != nil {
Expand Down
17 changes: 9 additions & 8 deletions cmd/buildah/delete.go → cmd/buildah/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import (
)

var (
deleteDescription = "Deletes working container(s), unmounting them if necessary"
deleteCommand = cli.Command{
Name: "delete",
Usage: "Deletes working container(s)",
Description: deleteDescription,
Action: deleteCmd,
rmDescription = "Removes one or more working containers, unmounting them if necessary"
rmCommand = cli.Command{
Name: "rm",
Aliases: []string{"delete"},
Usage: "Remove one or more working containers",
Description: rmDescription,
Action: rmCmd,
ArgsUsage: "CONTAINER-NAME-OR-ID [...]",
}
)

func deleteCmd(c *cli.Context) error {
func rmCmd(c *cli.Context) error {
args := c.Args()
if len(args) == 0 {
return fmt.Errorf("container ID must be specified")
Expand All @@ -35,7 +36,7 @@ func deleteCmd(c *cli.Context) error {

err = builder.Delete()
if err != nil {
return fmt.Errorf("error deleting container %q: %v", builder.Container, err)
return fmt.Errorf("error removing container %q: %v", builder.Container, err)
}
}

Expand Down
40 changes: 40 additions & 0 deletions cmd/buildah/rmi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"fmt"

"github.com/urfave/cli"
)

var (
rmiDescription = "Removes one or more locally stored images."
rmiCommand = cli.Command{
Name: "rmi",
Usage: "Removes one or more images from local storage",
Description: rmiDescription,
Action: rmiCmd,
ArgsUsage: "IMAGE-NAME-OR-ID [...]",
}
)

func rmiCmd(c *cli.Context) error {
args := c.Args()
if len(args) == 0 {
return fmt.Errorf("container ID must be specified")
}

store, err := getStore(c)
if err != nil {
return err
}

for _, id := range args {
_, err := store.DeleteImage(id, true)
if err != nil {
return fmt.Errorf("error removing image %q: %v", id, err)
}
fmt.Printf("%s\n", id)
}

return nil
}
4 changes: 2 additions & 2 deletions examples/all-the-things.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ read
: " Unmount our working container and delete it "
read
buildah umount "$container1"
buildah delete "$container1"
buildah rm "$container1"
read
: " Now try it with ocid not running! "
read
Expand Down Expand Up @@ -65,7 +65,7 @@ read
: " Unmount our new working container and delete it "
read
buildah umount "$container2"
buildah delete "$container2"
buildah rm "$container2"
read
: " Verify that our new new image is there"
read
Expand Down
2 changes: 1 addition & 1 deletion examples/copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ read
: " Clean up, because I ran this like fifty times while testing "
read
echo '[buildah delete $container1]'
buildah delete $container1
buildah rm $container1
8 changes: 4 additions & 4 deletions tests/add.bats
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ load helpers
buildah add $cid ${TESTDIR}/randomfile
buildah unmount $cid
buildah commit --signature-policy ${TESTSDIR}/policy.json $cid containers-storage:new-image
buildah delete $cid
buildah rm $cid

newcid=$(buildah from new-image)
newroot=$(buildah mount $newcid)
Expand All @@ -41,7 +41,7 @@ load helpers
test -d $newroot/cwd
test -s $newroot/cwd/randomfile
cmp ${TESTDIR}/randomfile $newroot/cwd/randomfile
buildah delete $newcid
buildah rm $newcid
}

@test "add-local-archive" {
Expand Down Expand Up @@ -73,7 +73,7 @@ load helpers
buildah add $cid ${TESTDIR}/tarball4.tar.bz2
buildah unmount $cid
buildah commit --signature-policy ${TESTSDIR}/policy.json $cid containers-storage:new-image
buildah delete $cid
buildah rm $cid

newcid=$(buildah from new-image)
newroot=$(buildah mount $newcid)
Expand All @@ -93,5 +93,5 @@ load helpers
cmp ${TESTDIR}/tarball4/tarball4.random1 $newroot/tarball4/tarball4.random1
test -s $newroot/tarball4/tarball4.random2
cmp ${TESTDIR}/tarball4/tarball4.random2 $newroot/tarball4/tarball4.random2
buildah delete $newcid
buildah rm $newcid
}
24 changes: 12 additions & 12 deletions tests/basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ load helpers

@test "from" {
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine)
buildah delete $cid
buildah rm $cid
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine)
buildah delete $cid
buildah rm $cid
cid=$(buildah from alpine --pull --signature-policy ${TESTSDIR}/policy.json --name i-love-naming-things)
buildah delete i-love-naming-things
buildah rm i-love-naming-things
}

@test "from-defaultpull" {
cid=$(buildah from --signature-policy ${TESTSDIR}/policy.json alpine)
buildah delete $cid
buildah rm $cid
}

@test "from-nopull" {
Expand All @@ -28,21 +28,21 @@ load helpers
root=$(buildah mount $cid)
touch $root/foobar
buildah unmount $cid
buildah delete $cid
buildah rm $cid
}

@test "by-name" {
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json --name alpine-working-image-for-test alpine)
root=$(buildah mount alpine-working-image-for-test)
buildah unmount alpine-working-image-for-test
buildah delete alpine-working-image-for-test
buildah rm alpine-working-image-for-test
}

@test "by-root" {
cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine)
root=$(buildah mount $cid)
buildah unmount $cid
buildah delete $cid
buildah rm $cid
}

@test "commit" {
Expand All @@ -54,7 +54,7 @@ load helpers
cp ${TESTDIR}/randomfile $root/randomfile
buildah unmount $cid
buildah commit --signature-policy ${TESTSDIR}/policy.json $cid containers-storage:new-image
buildah delete $cid
buildah rm $cid

newcid=$(buildah from new-image)
newroot=$(buildah mount $newcid)
Expand All @@ -68,29 +68,29 @@ load helpers
buildah commit --signature-policy ${TESTSDIR}/policy.json $newcid containers-storage:another-new-image
buildah commit --signature-policy ${TESTSDIR}/policy.json $newcid containers-storage:yet-another-new-image
buildah unmount $newcid
buildah delete $newcid
buildah rm $newcid

othernewcid=$(buildah from other-new-image)
othernewroot=$(buildah mount $othernewcid)
test -s $othernewroot/randomfile
cmp ${TESTDIR}/randomfile $othernewroot/randomfile
test -s $othernewroot/other-randomfile
cmp ${TESTDIR}/other-randomfile $othernewroot/other-randomfile
buildah delete $othernewcid
buildah rm $othernewcid

anothernewcid=$(buildah from another-new-image)
anothernewroot=$(buildah mount $anothernewcid)
test -s $anothernewroot/randomfile
cmp ${TESTDIR}/randomfile $anothernewroot/randomfile
test -s $anothernewroot/other-randomfile
cmp ${TESTDIR}/other-randomfile $anothernewroot/other-randomfile
buildah delete $anothernewcid
buildah rm $anothernewcid

yetanothernewcid=$(buildah from yet-another-new-image)
yetanothernewroot=$(buildah mount $yetanothernewcid)
test -s $yetanothernewroot/randomfile
cmp ${TESTDIR}/randomfile $yetanothernewroot/randomfile
test -s $yetanothernewroot/other-randomfile
cmp ${TESTDIR}/other-randomfile $yetanothernewroot/other-randomfile
buildah delete $yetanothernewcid
buildah rm $yetanothernewcid
}
8 changes: 4 additions & 4 deletions tests/copy.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ load helpers
buildah copy $cid ${TESTDIR}/randomfile
run buildah copy $cid ${TESTDIR}/other-randomfile ${TESTDIR}/third-randomfile ${TESTDIR}/randomfile
[ "$status" -eq 1 ]
buildah delete $cid
buildah rm $cid

cid=$(buildah from --pull --signature-policy ${TESTSDIR}/policy.json alpine)
root=$(buildah mount $cid)
buildah config --workingdir / $cid
buildah copy $cid ${TESTDIR}/randomfile
buildah copy $cid ${TESTDIR}/other-randomfile ${TESTDIR}/third-randomfile ${TESTDIR}/randomfile /etc
buildah delete $cid
buildah rm $cid
}

@test "copy-local-plain" {
Expand All @@ -35,13 +35,13 @@ load helpers
buildah copy $cid ${TESTDIR}/other-randomfile
buildah unmount $cid
buildah commit --signature-policy ${TESTSDIR}/policy.json $cid containers-storage:new-image
buildah delete $cid
buildah rm $cid

newcid=$(buildah from new-image)
newroot=$(buildah mount $newcid)
test -s $newroot/randomfile
cmp ${TESTDIR}/randomfile $newroot/randomfile
test -s $newroot/other-randomfile
cmp ${TESTDIR}/other-randomfile $newroot/other-randomfile
buildah delete $newcid
buildah rm $newcid
}
Loading