Skip to content

Commit

Permalink
feat: add download extension store image prefix (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamYSF authored Sep 14, 2024
1 parent 96d3b44 commit 4aadd06
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
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, "image-prefix", "", "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
12 changes: 9 additions & 3 deletions pkg/downloader/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import (

type storeDownloader struct {
OCIDownloader
os, arch string
extFile string
os, arch string
extFile string
imagePrefix string
}

func NewStoreDownloader() PlatformAwareOCIDownloader {
Expand All @@ -37,6 +38,7 @@ func NewStoreDownloader() PlatformAwareOCIDownloader {
}
ociDownloader.WithOS(runtime.GOOS)
ociDownloader.WithArch(runtime.GOARCH)
ociDownloader.WithImagePrefix("linuxsuren")
return ociDownloader
}

Expand All @@ -46,7 +48,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/atest-ext-store-%s", d.imagePrefix, name)
reader, err = d.OCIDownloader.Download(image, tag, d.extFile)
return
}
Expand All @@ -70,6 +72,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
3 changes: 3 additions & 0 deletions pkg/server/store_ext_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ func (n *nonDownloader) WithRegistry(string) {
// Do nothing because this is an empty implementation
}

func (n *nonDownloader) WithImagePrefix(imagePrefix string) {
// Do nothing because this is an empty implementation
}
func (d *nonDownloader) WithRoundTripper(rt http.RoundTripper) {
// Do nothing because this is an empty implementation
}
Expand Down

0 comments on commit 4aadd06

Please sign in to comment.