Skip to content

Commit

Permalink
馃敡 Don't pull socat image if already exists (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPCardenas committed Mar 22, 2024
1 parent 980304c commit 6073abb
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions cmd/portforward/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
dockerclient "github.com/docker/docker/client"
"github.com/docker/go-connections/nat"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -147,12 +148,22 @@ func runPortForward(ctx context.Context, cli cliutil.CLI, opts *options) error {
return err
}

// TODO: Pull only if not present locally.
cli.PrintAux("Pulling forwarder image...\n")
if err := client.ImagePullEx(ctx, forwarderImage, types.ImagePullOptions{
// Platform: ... TODO: Test if an arm64 sidecar can be attached to an amd64 target and vice versa.
}); err != nil {
return fmt.Errorf("cannot pull forwarder image %q: %w", forwarderImage, err)
// Find existing forwarder image.
images, err := client.ImageList(ctx, types.ImageListOptions{
All: true,
Filters: filters.NewArgs(
filters.Arg("reference", forwarderImage),
),
})
if err != nil || len(images) == 0 {
cli.PrintAux("Pulling forwarder image...\n")
if err := client.ImagePullEx(ctx, forwarderImage, types.ImagePullOptions{
// Platform: ... TODO: Test if an arm64 sidecar can be attached to an amd64 target and vice versa.
}); err != nil {
return fmt.Errorf("cannot pull forwarder image %q: %w", forwarderImage, err)
}
} else {
cli.PrintAux("Using existing forwarder image...\n")
}

ctx, cancel := context.WithCancel(signalutil.InterruptibleContext(ctx))
Expand Down

0 comments on commit 6073abb

Please sign in to comment.