docker: check if the user submitted an image ID or Name
- commit
- 9f503cc17c90295ef3823ef9e7b5fc6b635dbf81
- author
- bnema · · 2024-04-21 21:26 UTC
- parent
- b485310
- signature
- unsigned
8 files · +230 -9
M go.mod +35 -0
| @@ -8,6 +8,7 @@ require ( | |||
| 8 | 8 | github.com/charmbracelet/bubbles v0.16.1 | |
| 9 | 9 | github.com/charmbracelet/bubbletea v0.24.1 | |
| 10 | 10 | github.com/charmbracelet/lipgloss v0.7.1 | |
| 11 | + | github.com/containerd/containerd v1.7.15 | |
| 11 | 12 | github.com/docker/docker v24.0.6+incompatible | |
| 12 | 13 | github.com/docker/go-connections v0.4.0 | |
| 13 | 14 | github.com/fatih/color v1.15.0 | |
| @@ -23,27 +24,61 @@ require ( | |||
| 23 | 24 | ) | |
| 24 | 25 | ||
| 25 | 26 | require ( | |
| 27 | + | github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect | |
| 28 | + | github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 // indirect | |
| 29 | + | github.com/Microsoft/hcsshim v0.11.4 // indirect | |
| 26 | 30 | github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect | |
| 27 | 31 | github.com/charmbracelet/harmonica v0.2.0 // indirect | |
| 32 | + | github.com/containerd/cgroups v1.1.0 // indirect | |
| 28 | 33 | github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect | |
| 34 | + | github.com/containerd/continuity v0.4.2 // indirect | |
| 35 | + | github.com/containerd/fifo v1.1.0 // indirect | |
| 36 | + | github.com/containerd/log v0.1.0 // indirect | |
| 37 | + | github.com/containerd/ttrpc v1.2.3 // indirect | |
| 38 | + | github.com/containerd/typeurl/v2 v2.1.1 // indirect | |
| 29 | 39 | github.com/creack/pty v1.1.18 // indirect | |
| 40 | + | github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect | |
| 30 | 41 | github.com/dustin/go-humanize v1.0.1 // indirect | |
| 42 | + | github.com/felixge/httpsnoop v1.0.3 // indirect | |
| 43 | + | github.com/go-logr/logr v1.2.4 // indirect | |
| 44 | + | github.com/go-logr/stdr v1.2.2 // indirect | |
| 45 | + | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect | |
| 46 | + | github.com/golang/protobuf v1.5.4 // indirect | |
| 47 | + | github.com/google/go-cmp v0.5.9 // indirect | |
| 31 | 48 | github.com/inconshreveable/mousetrap v1.1.0 // indirect | |
| 32 | 49 | github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect | |
| 50 | + | github.com/klauspost/compress v1.16.0 // indirect | |
| 33 | 51 | github.com/kr/text v0.2.0 // indirect | |
| 34 | 52 | github.com/lucasb-eyer/go-colorful v1.2.0 // indirect | |
| 35 | 53 | github.com/mattn/go-localereader v0.0.1 // indirect | |
| 36 | 54 | github.com/mattn/go-runewidth v0.0.15 // indirect | |
| 37 | 55 | github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect | |
| 56 | + | github.com/moby/locker v1.0.1 // indirect | |
| 57 | + | github.com/moby/sys/mountinfo v0.6.2 // indirect | |
| 58 | + | github.com/moby/sys/sequential v0.5.0 // indirect | |
| 59 | + | github.com/moby/sys/signal v0.7.0 // indirect | |
| 60 | + | github.com/moby/sys/user v0.1.0 // indirect | |
| 38 | 61 | github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect | |
| 39 | 62 | github.com/muesli/cancelreader v0.2.2 // indirect | |
| 40 | 63 | github.com/muesli/reflow v0.3.0 // indirect | |
| 41 | 64 | github.com/muesli/termenv v0.15.1 // indirect | |
| 65 | + | github.com/opencontainers/runtime-spec v1.1.0 // indirect | |
| 66 | + | github.com/opencontainers/selinux v1.11.0 // indirect | |
| 42 | 67 | github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect | |
| 43 | 68 | github.com/rivo/uniseg v0.4.4 // indirect | |
| 69 | + | github.com/sirupsen/logrus v1.9.3 // indirect | |
| 44 | 70 | github.com/spf13/pflag v1.0.5 // indirect | |
| 71 | + | go.opencensus.io v0.24.0 // indirect | |
| 72 | + | go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect | |
| 73 | + | go.opentelemetry.io/otel v1.19.0 // indirect | |
| 74 | + | go.opentelemetry.io/otel/metric v1.19.0 // indirect | |
| 75 | + | go.opentelemetry.io/otel/trace v1.19.0 // indirect | |
| 45 | 76 | golang.org/x/sync v0.4.0 // indirect | |
| 46 | 77 | golang.org/x/term v0.13.0 // indirect | |
| 78 | + | google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a // indirect | |
| 79 | + | google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect | |
| 80 | + | google.golang.org/grpc v1.59.0 // indirect | |
| 81 | + | google.golang.org/protobuf v1.33.0 // indirect | |
| 47 | 82 | lukechampine.com/uint128 v1.3.0 // indirect | |
| 48 | 83 | modernc.org/cc/v3 v3.41.0 // indirect | |
| 49 | 84 | modernc.org/ccgo/v3 v3.16.15 // indirect | |
| @@ -8,6 +8,7 @@ require ( | |||||
| 8 | github.com/charmbracelet/bubbles v0.16.1 | 8 | github.com/charmbracelet/bubbles v0.16.1 | ||
| 9 | github.com/charmbracelet/bubbletea v0.24.1 | 9 | github.com/charmbracelet/bubbletea v0.24.1 | ||
| 10 | github.com/charmbracelet/lipgloss v0.7.1 | 10 | github.com/charmbracelet/lipgloss v0.7.1 | ||
| 11 | + | github.com/containerd/containerd v1.7.15 | |||
| 11 | github.com/docker/docker v24.0.6+incompatible | 12 | github.com/docker/docker v24.0.6+incompatible | ||
| 12 | github.com/docker/go-connections v0.4.0 | 13 | github.com/docker/go-connections v0.4.0 | ||
| 13 | github.com/fatih/color v1.15.0 | 14 | github.com/fatih/color v1.15.0 | ||
| @@ -23,27 +24,61 @@ require ( | |||||
| 23 | ) | 24 | ) | ||
| 24 | 25 | ||||
| 25 | require ( | 26 | require ( | ||
| 27 | + | github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect | |||
| 28 | + | github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 // indirect | |||
| 29 | + | github.com/Microsoft/hcsshim v0.11.4 // indirect | |||
| 26 | github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect | 30 | github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect | ||
| 27 | github.com/charmbracelet/harmonica v0.2.0 // indirect | 31 | github.com/charmbracelet/harmonica v0.2.0 // indirect | ||
| 32 | + | github.com/containerd/cgroups v1.1.0 // indirect | |||
| 28 | github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect | 33 | github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect | ||
| 34 | + | github.com/containerd/continuity v0.4.2 // indirect | |||
| 35 | + | github.com/containerd/fifo v1.1.0 // indirect | |||
| 36 | + | github.com/containerd/log v0.1.0 // indirect | |||
| 37 | + | github.com/containerd/ttrpc v1.2.3 // indirect | |||
| 38 | + | github.com/containerd/typeurl/v2 v2.1.1 // indirect | |||
| 29 | github.com/creack/pty v1.1.18 // indirect | 39 | github.com/creack/pty v1.1.18 // indirect | ||
| 40 | + | github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect | |||
| 30 | github.com/dustin/go-humanize v1.0.1 // indirect | 41 | github.com/dustin/go-humanize v1.0.1 // indirect | ||
| 42 | + | github.com/felixge/httpsnoop v1.0.3 // indirect | |||
| 43 | + | github.com/go-logr/logr v1.2.4 // indirect | |||
| 44 | + | github.com/go-logr/stdr v1.2.2 // indirect | |||
| 45 | + | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect | |||
| 46 | + | github.com/golang/protobuf v1.5.4 // indirect | |||
| 47 | + | github.com/google/go-cmp v0.5.9 // indirect | |||
| 31 | github.com/inconshreveable/mousetrap v1.1.0 // indirect | 48 | github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
| 32 | github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect | 49 | github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect | ||
| 50 | + | github.com/klauspost/compress v1.16.0 // indirect | |||
| 33 | github.com/kr/text v0.2.0 // indirect | 51 | github.com/kr/text v0.2.0 // indirect | ||
| 34 | github.com/lucasb-eyer/go-colorful v1.2.0 // indirect | 52 | github.com/lucasb-eyer/go-colorful v1.2.0 // indirect | ||
| 35 | github.com/mattn/go-localereader v0.0.1 // indirect | 53 | github.com/mattn/go-localereader v0.0.1 // indirect | ||
| 36 | github.com/mattn/go-runewidth v0.0.15 // indirect | 54 | github.com/mattn/go-runewidth v0.0.15 // indirect | ||
| 37 | github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect | 55 | github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect | ||
| 56 | + | github.com/moby/locker v1.0.1 // indirect | |||
| 57 | + | github.com/moby/sys/mountinfo v0.6.2 // indirect | |||
| 58 | + | github.com/moby/sys/sequential v0.5.0 // indirect | |||
| 59 | + | github.com/moby/sys/signal v0.7.0 // indirect | |||
| 60 | + | github.com/moby/sys/user v0.1.0 // indirect | |||
| 38 | github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect | 61 | github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect | ||
| 39 | github.com/muesli/cancelreader v0.2.2 // indirect | 62 | github.com/muesli/cancelreader v0.2.2 // indirect | ||
| 40 | github.com/muesli/reflow v0.3.0 // indirect | 63 | github.com/muesli/reflow v0.3.0 // indirect | ||
| 41 | github.com/muesli/termenv v0.15.1 // indirect | 64 | github.com/muesli/termenv v0.15.1 // indirect | ||
| 65 | + | github.com/opencontainers/runtime-spec v1.1.0 // indirect | |||
| 66 | + | github.com/opencontainers/selinux v1.11.0 // indirect | |||
| 42 | github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect | 67 | github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect | ||
| 43 | github.com/rivo/uniseg v0.4.4 // indirect | 68 | github.com/rivo/uniseg v0.4.4 // indirect | ||
| 69 | + | github.com/sirupsen/logrus v1.9.3 // indirect | |||
| 44 | github.com/spf13/pflag v1.0.5 // indirect | 70 | github.com/spf13/pflag v1.0.5 // indirect | ||
| 71 | + | go.opencensus.io v0.24.0 // indirect | |||
| 72 | + | go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect | |||
| 73 | + | go.opentelemetry.io/otel v1.19.0 // indirect | |||
| 74 | + | go.opentelemetry.io/otel/metric v1.19.0 // indirect | |||
| 75 | + | go.opentelemetry.io/otel/trace v1.19.0 // indirect | |||
| 45 | golang.org/x/sync v0.4.0 // indirect | 76 | golang.org/x/sync v0.4.0 // indirect | ||
| 46 | golang.org/x/term v0.13.0 // indirect | 77 | golang.org/x/term v0.13.0 // indirect | ||
| 78 | + | google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a // indirect | |||
| 79 | + | google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect | |||
| 80 | + | google.golang.org/grpc v1.59.0 // indirect | |||
| 81 | + | google.golang.org/protobuf v1.33.0 // indirect | |||
| 47 | lukechampine.com/uint128 v1.3.0 // indirect | 82 | lukechampine.com/uint128 v1.3.0 // indirect | ||
| 48 | modernc.org/cc/v3 v3.41.0 // indirect | 83 | modernc.org/cc/v3 v3.41.0 // indirect | ||
| 49 | modernc.org/ccgo/v3 v3.16.15 // indirect | 84 | modernc.org/ccgo/v3 v3.16.15 // indirect | ||
M go.sum +149 -0 generated file: collapsed
M internal/cli/cmd/deploy.go +18 -5
| @@ -177,21 +177,34 @@ func NewDeployCommand(a *cli.App) *cobra.Command { | |||
| 177 | 177 | ||
| 178 | 178 | // export the docker image to a reader and return its true size | |
| 179 | 179 | func exportDockerImage(imageName string) (io.ReadCloser, int64, error) { | |
| 180 | - | imageID, err := docker.GetImageID(imageName) | |
| 180 | + | // Check if what the user submitted is a valid image ID | |
| 181 | + | exists, err := docker.CheckIfImageExists(imageName) | |
| 181 | 182 | if err != nil { | |
| 182 | - | return nil, 0, fmt.Errorf("error getting image ID: %w", err) | |
| 183 | + | return nil, 0, fmt.Errorf("error while checking image existence: %w", err) | |
| 184 | + | } | |
| 185 | + | ||
| 186 | + | var imageID string | |
| 187 | + | if exists { | |
| 188 | + | // What the user submitted is a valid image ID | |
| 189 | + | imageID = imageName | |
| 190 | + | } else { | |
| 191 | + | // What the user submitted is not a valid image ID, search by name | |
| 192 | + | imageID, err = docker.GetImageIDByName(imageName) | |
| 193 | + | if err != nil { | |
| 194 | + | return nil, 0, fmt.Errorf("error while searching for image by name: %w", err) | |
| 195 | + | } | |
| 183 | 196 | } | |
| 184 | 197 | ||
| 185 | 198 | actualSize, err := docker.GetImageSizeFromReader(imageID) | |
| 186 | 199 | if err != nil { | |
| 187 | - | return nil, 0, fmt.Errorf("error getting image size: %w", err) | |
| 200 | + | return nil, 0, fmt.Errorf("error while retrieving image size: %w", err) | |
| 188 | 201 | } | |
| 189 | 202 | ||
| 190 | 203 | reader, err := docker.ExportImageFromEngine(imageID) | |
| 191 | 204 | if err != nil { | |
| 192 | - | return nil, 0, fmt.Errorf("error exporting image: %w", err) | |
| 205 | + | return nil, 0, fmt.Errorf("error while exporting image: %w", err) | |
| 193 | 206 | } | |
| 194 | 207 | ||
| 195 | - | // Return the wrapped reader. | |
| 208 | + | // Return the reader and the actual size | |
| 196 | 209 | return reader, actualSize, nil | |
| 197 | 210 | } | |
| @@ -177,21 +177,34 @@ func NewDeployCommand(a *cli.App) *cobra.Command { | |||||
| 177 | 177 | ||||
| 178 | // export the docker image to a reader and return its true size | 178 | // export the docker image to a reader and return its true size | ||
| 179 | func exportDockerImage(imageName string) (io.ReadCloser, int64, error) { | 179 | func exportDockerImage(imageName string) (io.ReadCloser, int64, error) { | ||
| 180 | - | imageID, err := docker.GetImageID(imageName) | 180 | + | // Check if what the user submitted is a valid image ID |
| 181 | + | exists, err := docker.CheckIfImageExists(imageName) | |||
| 181 | if err != nil { | 182 | if err != nil { | ||
| 182 | - | return nil, 0, fmt.Errorf("error getting image ID: %w", err) | 183 | + | return nil, 0, fmt.Errorf("error while checking image existence: %w", err) |
| 184 | + | } | |||
| 185 | + | ||||
| 186 | + | var imageID string | |||
| 187 | + | if exists { | |||
| 188 | + | // What the user submitted is a valid image ID | |||
| 189 | + | imageID = imageName | |||
| 190 | + | } else { | |||
| 191 | + | // What the user submitted is not a valid image ID, search by name | |||
| 192 | + | imageID, err = docker.GetImageIDByName(imageName) | |||
| 193 | + | if err != nil { | |||
| 194 | + | return nil, 0, fmt.Errorf("error while searching for image by name: %w", err) | |||
| 195 | + | } | |||
| 183 | } | 196 | } | ||
| 184 | 197 | ||||
| 185 | actualSize, err := docker.GetImageSizeFromReader(imageID) | 198 | actualSize, err := docker.GetImageSizeFromReader(imageID) | ||
| 186 | if err != nil { | 199 | if err != nil { | ||
| 187 | - | return nil, 0, fmt.Errorf("error getting image size: %w", err) | 200 | + | return nil, 0, fmt.Errorf("error while retrieving image size: %w", err) |
| 188 | } | 201 | } | ||
| 189 | 202 | ||||
| 190 | reader, err := docker.ExportImageFromEngine(imageID) | 203 | reader, err := docker.ExportImageFromEngine(imageID) | ||
| 191 | if err != nil { | 204 | if err != nil { | ||
| 192 | - | return nil, 0, fmt.Errorf("error exporting image: %w", err) | 205 | + | return nil, 0, fmt.Errorf("error while exporting image: %w", err) |
| 193 | } | 206 | } | ||
| 194 | 207 | ||||
| 195 | - | // Return the wrapped reader. | 208 | + | // Return the reader and the actual size |
| 196 | return reader, actualSize, nil | 209 | return reader, actualSize, nil | ||
| 197 | } | 210 | } | ||
M internal/httpserve/handler/clientendpoins.go +1 -1
| @@ -110,7 +110,7 @@ func PostDeploy(c echo.Context, a *server.App) error { | |||
| 110 | 110 | payload.ImageName = "localhost/" + payload.ImageName | |
| 111 | 111 | ||
| 112 | 112 | // Get the image ID | |
| 113 | - | imageID, err := docker.GetImageID(payload.ImageName) | |
| 113 | + | imageID, err := docker.GetImageIDByName(payload.ImageName) | |
| 114 | 114 | if err != nil { | |
| 115 | 115 | return sendJsonError(c, err) | |
| 116 | 116 | } | |
| @@ -110,7 +110,7 @@ func PostDeploy(c echo.Context, a *server.App) error { | |||||
| 110 | payload.ImageName = "localhost/" + payload.ImageName | 110 | payload.ImageName = "localhost/" + payload.ImageName | ||
| 111 | 111 | ||||
| 112 | // Get the image ID | 112 | // Get the image ID | ||
| 113 | - | imageID, err := docker.GetImageID(payload.ImageName) | 113 | + | imageID, err := docker.GetImageIDByName(payload.ImageName) |
| 114 | if err != nil { | 114 | if err != nil { | ||
| 115 | return sendJsonError(c, err) | 115 | return sendJsonError(c, err) | ||
| 116 | } | 116 | } | ||
M internal/templating/cmdparams/fromcli.go +1 -1
| @@ -13,7 +13,7 @@ import ( | |||
| 13 | 13 | // FromYAMLStructToCmdParams converts a YAMLContainerParams struct to a ContainerCommandParams struct | |
| 14 | 14 | func FromPayloadStructToCmdParams(ppl *common.DeployPayload, a *server.App) (docker.ContainerCommandParams, error) { | |
| 15 | 15 | ||
| 16 | - | imageID, err := docker.GetImageID(ppl.ImageName) | |
| 16 | + | imageID, err := docker.GetImageIDByName(ppl.ImageName) | |
| 17 | 17 | if err != nil { | |
| 18 | 18 | return docker.ContainerCommandParams{}, err | |
| 19 | 19 | } | |
| @@ -13,7 +13,7 @@ import ( | |||||
| 13 | // FromYAMLStructToCmdParams converts a YAMLContainerParams struct to a ContainerCommandParams struct | 13 | // FromYAMLStructToCmdParams converts a YAMLContainerParams struct to a ContainerCommandParams struct | ||
| 14 | func FromPayloadStructToCmdParams(ppl *common.DeployPayload, a *server.App) (docker.ContainerCommandParams, error) { | 14 | func FromPayloadStructToCmdParams(ppl *common.DeployPayload, a *server.App) (docker.ContainerCommandParams, error) { | ||
| 15 | 15 | ||||
| 16 | - | imageID, err := docker.GetImageID(ppl.ImageName) | 16 | + | imageID, err := docker.GetImageIDByName(ppl.ImageName) |
| 17 | if err != nil { | 17 | if err != nil { | ||
| 18 | return docker.ContainerCommandParams{}, err | 18 | return docker.ContainerCommandParams{}, err | ||
| 19 | } | 19 | } | ||
M internal/templating/cmdparams/fromyaml.go +1 -1
| @@ -22,7 +22,7 @@ type YAMLContainerParams struct { | |||
| 22 | 22 | // FromYAMLStructToCmdParams converts a YAMLContainerParams struct to a ContainerCommandParams struct | |
| 23 | 23 | func FromYAMLStructToCmdParams(yamlParams YAMLContainerParams) (docker.ContainerCommandParams, error) { | |
| 24 | 24 | // with the image name find the image id | |
| 25 | - | imageID, err := docker.GetImageID(yamlParams.Image) | |
| 25 | + | imageID, err := docker.GetImageIDByName(yamlParams.Image) | |
| 26 | 26 | if err != nil { | |
| 27 | 27 | return docker.ContainerCommandParams{}, err | |
| 28 | 28 | } | |
| @@ -22,7 +22,7 @@ type YAMLContainerParams struct { | |||||
| 22 | // FromYAMLStructToCmdParams converts a YAMLContainerParams struct to a ContainerCommandParams struct | 22 | // FromYAMLStructToCmdParams converts a YAMLContainerParams struct to a ContainerCommandParams struct | ||
| 23 | func FromYAMLStructToCmdParams(yamlParams YAMLContainerParams) (docker.ContainerCommandParams, error) { | 23 | func FromYAMLStructToCmdParams(yamlParams YAMLContainerParams) (docker.ContainerCommandParams, error) { | ||
| 24 | // with the image name find the image id | 24 | // with the image name find the image id | ||
| 25 | - | imageID, err := docker.GetImageID(yamlParams.Image) | 25 | + | imageID, err := docker.GetImageIDByName(yamlParams.Image) |
| 26 | if err != nil { | 26 | if err != nil { | ||
| 27 | return docker.ContainerCommandParams{}, err | 27 | return docker.ContainerCommandParams{}, err | ||
| 28 | } | 28 | } | ||
M pkg/docker/client.go +2 -0
| @@ -2,6 +2,7 @@ package docker | |||
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "context" | |
| 5 | + | "crypto/tls" | |
| 5 | 6 | "fmt" | |
| 6 | 7 | "os" | |
| 7 | 8 | "time" | |
| @@ -17,6 +18,7 @@ type ContainerEngineClient interface { | |||
| 17 | 18 | type Config struct { | |
| 18 | 19 | Sock string | |
| 19 | 20 | PodmanEnable bool | |
| 21 | + | TLSConfig *tls.Config | |
| 20 | 22 | } | |
| 21 | 23 | ||
| 22 | 24 | var ( | |
| @@ -2,6 +2,7 @@ package docker | |||||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | "context" | 4 | "context" | ||
| 5 | + | "crypto/tls" | |||
| 5 | "fmt" | 6 | "fmt" | ||
| 6 | "os" | 7 | "os" | ||
| 7 | "time" | 8 | "time" | ||
| @@ -17,6 +18,7 @@ type ContainerEngineClient interface { | |||||
| 17 | type Config struct { | 18 | type Config struct { | ||
| 18 | Sock string | 19 | Sock string | ||
| 19 | PodmanEnable bool | 20 | PodmanEnable bool | ||
| 21 | + | TLSConfig *tls.Config | |||
| 20 | } | 22 | } | ||
| 21 | 23 | ||||
| 22 | var ( | 24 | var ( | ||
M pkg/docker/images.go +23 -1
| @@ -32,7 +32,18 @@ func DeleteContainerImage(imageID string) error { | |||
| 32 | 32 | return nil | |
| 33 | 33 | } | |
| 34 | 34 | ||
| 35 | - | func GetImageID(imageName string) (string, error) { | |
| 35 | + | // CheckIfImageExists checks if an image exists in the Docker engine | |
| 36 | + | func CheckIfImageExists(imageID string) (bool, error) { | |
| 37 | + | // Get the image information using the Docker client | |
| 38 | + | _, err := GetImageInfo(imageID) | |
| 39 | + | if err != nil { | |
| 40 | + | return false, nil | |
| 41 | + | } | |
| 42 | + | ||
| 43 | + | return true, nil | |
| 44 | + | } | |
| 45 | + | ||
| 46 | + | func GetImageIDByName(imageName string) (string, error) { | |
| 36 | 47 | ||
| 37 | 48 | images, err := dockerCli.ImageList(context.Background(), types.ImageListOptions{}) | |
| 38 | 49 | if err != nil { | |
| @@ -178,3 +189,14 @@ func GetImageSizeFromReader(imageID string) (int64, error) { | |||
| 178 | 189 | ||
| 179 | 190 | return actualSize, nil | |
| 180 | 191 | } | |
| 192 | + | ||
| 193 | + | // list all images | |
| 194 | + | func GetAllImages() ([]types.ImageSummary, error) { | |
| 195 | + | // List images using the Docker client | |
| 196 | + | images, err := dockerCli.ImageList(context.Background(), types.ImageListOptions{}) | |
| 197 | + | if err != nil { | |
| 198 | + | return nil, err | |
| 199 | + | } | |
| 200 | + | ||
| 201 | + | return images, nil | |
| 202 | + | } | |
| @@ -32,7 +32,18 @@ func DeleteContainerImage(imageID string) error { | |||||
| 32 | return nil | 32 | return nil | ||
| 33 | } | 33 | } | ||
| 34 | 34 | ||||
| 35 | - | func GetImageID(imageName string) (string, error) { | 35 | + | // CheckIfImageExists checks if an image exists in the Docker engine |
| 36 | + | func CheckIfImageExists(imageID string) (bool, error) { | |||
| 37 | + | // Get the image information using the Docker client | |||
| 38 | + | _, err := GetImageInfo(imageID) | |||
| 39 | + | if err != nil { | |||
| 40 | + | return false, nil | |||
| 41 | + | } | |||
| 42 | + | ||||
| 43 | + | return true, nil | |||
| 44 | + | } | |||
| 45 | + | ||||
| 46 | + | func GetImageIDByName(imageName string) (string, error) { | |||
| 36 | 47 | ||||
| 37 | images, err := dockerCli.ImageList(context.Background(), types.ImageListOptions{}) | 48 | images, err := dockerCli.ImageList(context.Background(), types.ImageListOptions{}) | ||
| 38 | if err != nil { | 49 | if err != nil { | ||
| @@ -178,3 +189,14 @@ func GetImageSizeFromReader(imageID string) (int64, error) { | |||||
| 178 | 189 | ||||
| 179 | return actualSize, nil | 190 | return actualSize, nil | ||
| 180 | } | 191 | } | ||
| 192 | + | ||||
| 193 | + | // list all images | |||
| 194 | + | func GetAllImages() ([]types.ImageSummary, error) { | |||
| 195 | + | // List images using the Docker client | |||
| 196 | + | images, err := dockerCli.ImageList(context.Background(), types.ImageListOptions{}) | |||
| 197 | + | if err != nil { | |||
| 198 | + | return nil, err | |||
| 199 | + | } | |||
| 200 | + | ||||
| 201 | + | return images, nil | |||
| 202 | + | } | |||