0.0.970 cdbcd03

images.go RawHistoryFolder

1package docker
2
3import (
4	"bytes"
5	"context"
6	"io"
7	"os"
8
9	"github.com/docker/docker/api/types"
10)
11
12func ListContainerImages() ([]types.ImageSummary, error) {
13	// Check if the Docker client has been initialized
14	CheckIfInitialized()
15
16	// List images using the Docker client
17	images, err := dockerCli.ImageList(context.Background(), types.ImageListOptions{})
18	if err != nil {
19		return nil, err
20	}
21
22	return images, nil
23}
24
25// DeleteContainerImage deletes an image from the Docker engine
26func DeleteContainerImage(imageID string) error {
27	_, err := dockerCli.ImageRemove(context.Background(), imageID, types.ImageRemoveOptions{})
28	if err != nil {
29		return err
30	}
31
32	return nil
33}
34
35func GetImageID(imageName string) (string, error) {
36	// Check if the Docker client has been initialized
37	CheckIfInitialized()
38
39	// List all images
40	images, err := dockerCli.ImageList(context.Background(), types.ImageListOptions{})
41	if err != nil {
42		return "", err
43	}
44
45	// Search for the image we just loaded
46	var imageID string
47	for _, image := range images {
48		for _, tag := range image.RepoTags {
49			if tag == imageName {
50				imageID = image.ID
51			}
52		}
53	}
54
55	if imageID == "" {
56		return "", err
57	}
58
59	return imageID, nil
60}
61
62// ImportImageToEngine imports an image to the Docker engine
63func ImportImageToEngine(imagePath string) (string, error) {
64	// Open the image file
65	imageFile, err := os.Open(imagePath)
66	if err != nil {
67		return "", err
68	}
69
70	_, err = dockerCli.ImageLoad(context.Background(), imageFile, false)
71	if err != nil {
72		return "", err
73	}
74	// Close the image file
75	imageFile.Close()
76
77	// List all images
78	images, err := dockerCli.ImageList(context.Background(), types.ImageListOptions{})
79	if err != nil {
80		return "", err
81	}
82
83	// Search for the image we just loaded
84	var imageID string
85	for _, image := range images {
86		for _, tag := range image.RepoTags {
87			if tag == "<none>:<none>" {
88				imageID = image.ID
89			}
90		}
91	}
92
93	if imageID == "" {
94		return "", err
95	}
96
97	return imageID, nil
98}
99
100// ExportImageFromEngine exports an image from the Docker engine and returns it as a byte array
101func ExportImageFromEngine(imageName string) ([]byte, error) {
102	// we check if the image exists
103	_, err := GetImageID(imageName)
104	if err != nil {
105		return nil, err
106	}
107
108	image, err := dockerCli.ImageSave(context.Background(), []string{imageName})
109	if err != nil {
110		return nil, err
111	}
112	defer image.Close()
113
114	var buf bytes.Buffer
115	_, err = io.Copy(&buf, image)
116	if err != nil {
117		return nil, err
118	}
119
120	return buf.Bytes(), nil
121}
122
123// From an ID, get the all the information about the image
124func GetImageInfo(imageID string) (*types.ImageInspect, error) {
125	// Get the image information using the Docker client
126	imageInfo, _, err := dockerCli.ImageInspectWithRaw(context.Background(), imageID)
127	if err != nil {
128		return nil, err
129	}
130
131	return &imageInfo, nil
132}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close