Skip to content

Commit

Permalink
cmd/create, pkg/skopeo: Make the 'skopeo inspect' invocation cancellable
Browse files Browse the repository at this point in the history
A subsequent commit will use this to ensure that the user can still
interact with the image download prompt while 'skopeo inspect' fetches
the image size from the remote registry.  Initially, the prompt will be
shown without the image size.  If the user responds before the size is
fetched, then the pending 'skopeo inspect' will be cancelled.

#752
#1263
  • Loading branch information
debarshiray committed Dec 6, 2023
1 parent 1748688 commit 8401092
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package cmd

import (
"context"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -576,7 +577,8 @@ func getFullyQualifiedImageFromRepoTags(image string) (string, error) {
}

func getImageSizeFromRegistry(imageFull string) (string, error) {
image, err := skopeo.Inspect(imageFull)
ctx := context.Background()
image, err := skopeo.Inspect(ctx, imageFull)
if err != nil {
return "", err
}
Expand Down
5 changes: 3 additions & 2 deletions src/pkg/skopeo/skopeo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package skopeo

import (
"bytes"
"context"
"encoding/json"

"github.com/containers/toolbox/pkg/shell"
Expand All @@ -30,13 +31,13 @@ type Image struct {
LayersData []Layer
}

func Inspect(target string) (*Image, error) {
func Inspect(ctx context.Context, target string) (*Image, error) {
var stdout bytes.Buffer

targetWithTransport := "docker://" + target
args := []string{"inspect", "--format", "json", targetWithTransport}

if err := shell.Run("skopeo", nil, &stdout, nil, args...); err != nil {
if err := shell.RunContext(ctx, "skopeo", nil, &stdout, nil, args...); err != nil {
return nil, err
}

Expand Down

0 comments on commit 8401092

Please sign in to comment.