-
Notifications
You must be signed in to change notification settings - Fork 32
/
images.go
69 lines (64 loc) · 1.89 KB
/
images.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package common
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/joyrex2001/kubedock/internal/config"
"github.com/joyrex2001/kubedock/internal/model/types"
"github.com/joyrex2001/kubedock/internal/server/httputil"
)
// ImageList - list Images. Stubbed, not relevant on k8s.
// https://docs.docker.com/engine/api/v1.41/#operation/ImageList
// https://docs.podman.io/en/latest/_static/api.html?version=v4.2#tag/images/operation/ImageListLibpod
// GET "/images/json"
// GET "/libpod/images/json"
func ImageList(cr *ContextRouter, c *gin.Context) {
imgs, err := cr.DB.GetImages()
if err != nil {
httputil.Error(c, http.StatusInternalServerError, err)
return
}
res := []gin.H{}
for _, img := range imgs {
name := img.Name
if !strings.Contains(name, ":") {
name = name + ":latest"
}
res = append(res, gin.H{"ID": img.ID, "Size": 0, "Created": img.Created.Unix(), "RepoTags": []string{name}})
}
c.JSON(http.StatusOK, res)
}
// ImageJSON - return low-level information about an image.
// https://docs.docker.com/engine/api/v1.41/#operation/ImageInspect
// GET "/images/:image/json"
func ImageJSON(cr *ContextRouter, c *gin.Context) {
id := strings.TrimSuffix(c.Param("image")+c.Param("json"), "/json")
img, err := cr.DB.GetImageByNameOrID(id)
if err != nil {
img = &types.Image{Name: id}
if cr.Config.Inspector {
pts, err := cr.Backend.GetImageExposedPorts(id)
if err != nil {
httputil.Error(c, http.StatusInternalServerError, err)
return
}
img.ExposedPorts = pts
}
if err := cr.DB.SaveImage(img); err != nil {
httputil.Error(c, http.StatusNotFound, err)
return
}
}
c.JSON(http.StatusOK, gin.H{
"Id": img.Name,
"Architecture": config.GOARCH,
"Created": img.Created.Format("2006-01-02T15:04:05Z"),
"Size": 0,
"ContainerConfig": gin.H{
"Image": img.Name,
},
"Config": gin.H{
"Env": []string{},
},
})
}