Skip to content

Commit

Permalink
feat: add download extension store image prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
SamYSF committed Sep 13, 2024
1 parent e68c996 commit aedc6a8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type extensionOption struct {
os string
arch string
timeout time.Duration
imagePrefix string
}

func createExtensionCommand(ociDownloader downloader.PlatformAwareOCIDownloader) (c *cobra.Command) {
Expand All @@ -55,13 +56,15 @@ func createExtensionCommand(ociDownloader downloader.PlatformAwareOCIDownloader)
flags.StringVarP(&opt.os, "os", "", runtime.GOOS, "The OS")
flags.StringVarP(&opt.arch, "arch", "", runtime.GOARCH, "The architecture")
flags.DurationVarP(&opt.timeout, "timeout", "", time.Minute, "The timeout of downloading")
flags.StringVarP(&opt.imagePrefix, "imagePrefix", "", "linuxsuren", "The prefix for the image address")
return
}

func (o *extensionOption) runE(cmd *cobra.Command, args []string) (err error) {
o.ociDownloader.WithOS(o.os)
o.ociDownloader.WithArch(o.arch)
o.ociDownloader.WithRegistry(o.registry)
o.ociDownloader.WithImagePrefix(o.imagePrefix)
o.ociDownloader.WithTimeout(o.timeout)
o.ociDownloader.WithContext(cmd.Context())

Expand Down
1 change: 1 addition & 0 deletions pkg/downloader/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type PlatformAwareOCIDownloader interface {
WithOS(string)
WithArch(string)
GetTargetFile() string
WithImagePrefix(string)
}

type defaultOCIDownloader struct {
Expand Down
7 changes: 6 additions & 1 deletion pkg/downloader/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type storeDownloader struct {
OCIDownloader
os, arch string
extFile string
imagePrefix string
}

func NewStoreDownloader() PlatformAwareOCIDownloader {
Expand All @@ -46,7 +47,7 @@ func (d *storeDownloader) Download(name, tag, _ string) (reader io.Reader, err e
if d.os == "windows" {
d.extFile = fmt.Sprintf("%s.exe", d.extFile)
}
image := fmt.Sprintf("linuxsuren/atest-ext-store-%s", name)
image := fmt.Sprintf("%s/extension-store-%s", d.imagePrefix, name)
reader, err = d.OCIDownloader.Download(image, tag, d.extFile)
return
}
Expand All @@ -70,6 +71,10 @@ func (d *storeDownloader) WithOS(os string) {
d.os = os
}

func (d *storeDownloader) WithImagePrefix(imagePrefix string) {
d.imagePrefix = imagePrefix
}

func (d *storeDownloader) WithArch(arch string) {
d.arch = arch
if d.arch == "amd64" {
Expand Down

0 comments on commit aedc6a8

Please sign in to comment.