Skip to content
Permalink
Browse files

Add function to get the docker image ID

  • Loading branch information...
aojea committed Jul 3, 2019
1 parent 6264959 commit ca723ddc5a9b874b925fc4b9cdb471917dae978b
Showing with 14 additions and 5 deletions.
  1. +1 −5 cmd/kind/load/docker-image/docker-image.go
  2. +13 −0 pkg/container/docker/image.go
@@ -72,14 +72,10 @@ func NewCommand() *cobra.Command {
func runE(flags *flagpole, cmd *cobra.Command, args []string) error {
imageName := args[0]
// Check that the image exists locally and gets its ID, if not return error
lines, err := docker.ImageInspect(imageName, "{{ .Id }}")
imageID, err := docker.ImageID(imageName)
if err != nil {
return errors.Errorf("Image: %q not present locally", imageName)
}
if len(lines) != 1 {
return errors.Errorf("Docker image ID should only be one line, got %d lines", len(lines))
}
imageID := lines[0]
// Check if the cluster name exists
known, err := cluster.IsKnown(flags.Name)
if err != nil {
@@ -17,6 +17,7 @@ limitations under the License.
package docker

import (
"github.com/pkg/errors"
"sigs.k8s.io/kind/pkg/exec"
)

@@ -29,3 +30,15 @@ func ImageInspect(containerNameOrID, format string) ([]string, error) {

return exec.CombinedOutputLines(cmd)
}

// ImageID return the Id of the container image
func ImageID(containerNameOrID string) (string, error) {
lines, err := ImageInspect(containerNameOrID, "{{ .Id }}")
if err != nil {
return "", err
}
if len(lines) != 1 {
return "", errors.Errorf("Docker image ID should only be one line, got %d lines", len(lines))
}
return lines[0], nil
}

0 comments on commit ca723dd

Please sign in to comment.
You can’t perform that action at this time.