Skip to content

Commit de22c5a

Browse files
zreigztest-cli-e2e-aws
andauthored
fix: plural edge download command (#624)
* fix plural edge download command * replace containerd library --------- Co-authored-by: test-cli-e2e-aws <test-cli-e2e-aws@srv.plural.sh>
1 parent 3f670d3 commit de22c5a

5 files changed

Lines changed: 196 additions & 210 deletions

File tree

cmd/command/edge/edge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func Commands(clients client.Plural, helmConfiguration *action.Configuration) []
143143
Usage: "pull and extract the edge image",
144144
Flags: []cli.Flag{
145145
cli.StringFlag{
146-
Name: "url",
146+
Name: "oci-url",
147147
Usage: "the url of the image to download",
148148
Required: true,
149149
},

cmd/command/edge/image.go

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ package edge
33
import (
44
"bytes"
55
"fmt"
6+
"io"
67
"net/http"
78
"os"
89
"path/filepath"
910
"strings"
11+
"time"
1012

13+
"github.com/google/go-containerregistry/pkg/authn"
14+
"github.com/google/go-containerregistry/pkg/name"
15+
"github.com/google/go-containerregistry/pkg/v1/mutate"
16+
"github.com/google/go-containerregistry/pkg/v1/remote"
1117
gqlclient "github.com/pluralsh/console/go/client"
1218
"github.com/pluralsh/plural-cli/pkg/console"
1319
"github.com/pluralsh/plural-cli/pkg/utils"
@@ -269,7 +275,7 @@ func (p *Plural) handleEdgeDownload(c *cli.Context) error {
269275
var err error
270276

271277
outputDir := c.String("to")
272-
url := c.String("url")
278+
url := c.String("oci-url")
273279

274280
if outputDir == "" {
275281
outputDir, err = os.Getwd()
@@ -278,11 +284,51 @@ func (p *Plural) handleEdgeDownload(c *cli.Context) error {
278284
}
279285
}
280286

281-
utils.Highlight("unpacking image contents\n")
282-
if err := utils.Exec("docker", "run", "-i", "--rm", "--privileged", "-v", fmt.Sprintf("%s:/image", outputDir),
283-
"quay.io/luet/base", "util", "unpack", url, "/image"); err != nil {
287+
return unpackImage(outputDir, url)
288+
}
289+
290+
func unpackImage(outputDir, ociUrl string) error {
291+
done := make(chan struct{})
292+
defer close(done)
293+
294+
utils.Highlight("unpacking image contents to %s ", outputDir)
295+
imageDir := filepath.Join(outputDir, "build")
296+
if !utils.IsDir(imageDir) {
297+
if err := os.MkdirAll(outputDir, os.ModePerm); err != nil {
298+
return err
299+
}
300+
}
301+
302+
ref, err := name.ParseReference(ociUrl)
303+
if err != nil {
284304
return err
285305
}
306+
img, err := remote.Image(ref, remote.WithAuthFromKeychain(authn.DefaultKeychain))
307+
if err != nil {
308+
return err
309+
}
310+
reader := mutate.Extract(img)
311+
defer func(reader io.ReadCloser) {
312+
err := reader.Close()
313+
if err != nil {
314+
utils.Error("%s", err.Error())
315+
}
316+
}(reader)
317+
go progress(done)
318+
return utils.Untar(outputDir, reader)
319+
}
286320

287-
return nil
321+
func progress(done <-chan struct{}) {
322+
frames := []rune{'|', '/', '-', '\\'}
323+
i := 0
324+
for {
325+
select {
326+
case <-done:
327+
return
328+
default:
329+
fmt.Printf("\b%c", frames[i%len(frames)])
330+
time.Sleep(500 * time.Millisecond)
331+
i++
332+
}
333+
}
288334
}

go.mod

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ require (
2727
github.com/fatih/color v1.18.0
2828
github.com/go-git/go-git/v5 v5.13.1
2929
github.com/gofrs/flock v0.12.1
30+
github.com/google/go-containerregistry v0.20.3
3031
github.com/google/go-github/v45 v45.2.0
3132
github.com/hashicorp/go-bexpr v0.1.14
3233
github.com/ktrysmt/go-bitbucket v0.9.81
@@ -46,7 +47,7 @@ require (
4647
github.com/urfave/cli v1.22.16
4748
github.com/yuin/gopher-lua v1.1.1
4849
gitlab.com/gitlab-org/api/client-go v0.118.0
49-
golang.org/x/crypto v0.32.0
50+
golang.org/x/crypto v0.35.0
5051
golang.org/x/oauth2 v0.25.0
5152
gopkg.in/yaml.v2 v2.4.0
5253
gopkg.in/yaml.v3 v3.0.1
@@ -95,8 +96,9 @@ require (
9596
github.com/containerd/errdefs v1.0.0 // indirect
9697
github.com/containerd/log v0.1.0 // indirect
9798
github.com/containerd/platforms v0.2.1 // indirect
99+
github.com/containerd/stargz-snapshotter/estargz v0.16.3 // indirect
98100
github.com/distribution/reference v0.6.0 // indirect
99-
github.com/docker/cli v27.4.1+incompatible // indirect
101+
github.com/docker/cli v27.5.0+incompatible // indirect
100102
github.com/docker/distribution v2.8.3+incompatible // indirect
101103
github.com/docker/docker v27.5.0+incompatible // indirect
102104
github.com/docker/docker-credential-helpers v0.8.2 // indirect
@@ -134,6 +136,7 @@ require (
134136
github.com/skeema/knownhosts v1.3.0 // indirect
135137
github.com/sosodev/duration v1.3.1 // indirect
136138
github.com/stretchr/objx v0.5.2 // indirect
139+
github.com/vbatts/tar-split v0.11.6 // indirect
137140
github.com/vektah/gqlparser/v2 v2.5.21 // indirect
138141
github.com/x448/float16 v0.8.4 // indirect
139142
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
@@ -261,14 +264,14 @@ require (
261264
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
262265
github.com/xlab/treeprint v1.2.0 // indirect
263266
golang.org/x/net v0.34.0 // indirect
264-
golang.org/x/sync v0.10.0 // indirect
265-
golang.org/x/sys v0.29.0 // indirect
266-
golang.org/x/term v0.28.0
267-
golang.org/x/text v0.21.0
267+
golang.org/x/sync v0.11.0 // indirect
268+
golang.org/x/sys v0.30.0 // indirect
269+
golang.org/x/term v0.29.0
270+
golang.org/x/text v0.22.0
268271
golang.org/x/time v0.9.0 // indirect
269272
google.golang.org/api v0.215.0
270273
google.golang.org/grpc v1.69.2 // indirect
271-
google.golang.org/protobuf v1.36.2 // indirect
274+
google.golang.org/protobuf v1.36.3 // indirect
272275
gopkg.in/inf.v0 v0.9.1 // indirect
273276
gopkg.in/warnings.v0 v0.1.2 // indirect
274277
k8s.io/apiextensions-apiserver v0.32.0 // indirect
@@ -285,3 +288,12 @@ require (
285288
sigs.k8s.io/kustomize/kyaml v0.18.1 // indirect
286289
sigs.k8s.io/structured-merge-diff/v4 v4.5.0 // indirect
287290
)
291+
292+
replace (
293+
// CVE-2024-40635
294+
github.com/containerd/containerd => github.com/containerd/containerd v1.7.27
295+
// CVE-2025-30204
296+
github.com/golang-jwt/jwt/v5 => github.com/golang-jwt/jwt/v5 v5.2.2
297+
// CVE-2025-22870
298+
golang.org/x/net => golang.org/x/net v0.36.0
299+
)

0 commit comments

Comments
 (0)