Skip to content

Commit

Permalink
Merge pull request #10 from DOO-DEV/trim-image_id
Browse files Browse the repository at this point in the history
feat: trim image id to 12 characters
  • Loading branch information
arshamalh authored Nov 26, 2023
2 parents 318baab + ef28905 commit 0cce93d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 2do.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- [x] Logs streaming
- [x] Add image handlers, next, prev, back
- [x] Image size should be in human readable units
- [ ] Image ID should be shorted (trimmed)
- [x] Image ID should be shorted (trimmed)
- [ ] Image name and tag should be separated???
- [ ] Add Image status and created at
- [ ] Image run, rename, remove commands
Expand Down
18 changes: 11 additions & 7 deletions docker/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@ package docker
import (
"context"
"fmt"
"strings"
"time"

"github.com/arshamalh/dockeroller/entities"
"github.com/docker/docker/api/types"
)

func (d *docker) ImagesList() (images []*entities.Image) {
raw_images, _ := d.cli.ImageList(context.TODO(), types.ImageListOptions{All: true})
for _, raw_img := range raw_images {
status := d.getImageStatus(context.TODO(), raw_img)
rawImages, _ := d.cli.ImageList(context.TODO(), types.ImageListOptions{All: true})
for _, rawImg := range rawImages {
status := d.getImageStatus(context.TODO(), rawImg)
// In docker the result of `docker image -q` give us
// images ids with 12 characters long
imageID := strings.TrimPrefix(rawImg.ID, "sha256:")[0:12]
images = append(images, &entities.Image{
ID: raw_img.ID,
Size: raw_img.Size,
Tags: raw_img.RepoTags,
ID: imageID,
Size: rawImg.Size,
Tags: rawImg.RepoTags,
Status: entities.ImageStatus(status),
CreatedAt: fmt.Sprint(time.Unix(raw_img.Created, 0).Format("2006-01-02 15:04:05")),
CreatedAt: fmt.Sprint(time.Unix(rawImg.Created, 0).Format("2006-01-02 15:04:05")),
})
}
return
Expand Down

0 comments on commit 0cce93d

Please sign in to comment.