feat: add download extension store image prefix (#532)

This commit is contained in:
SamYSF 2024-09-14 19:54:58 +08:00 committed by GitHub
parent 96d3b4452c
commit 4aadd0611c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 3 deletions

View File

@ -35,6 +35,7 @@ type extensionOption struct {
os string
arch string
timeout time.Duration
imagePrefix string
}
func createExtensionCommand(ociDownloader downloader.PlatformAwareOCIDownloader) (c *cobra.Command) {
@ -55,6 +56,7 @@ 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
}
@ -62,6 +64,7 @@ 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())

View File

@ -44,6 +44,7 @@ type PlatformAwareOCIDownloader interface {
WithOS(string)
WithArch(string)
GetTargetFile() string
WithImagePrefix(string)
}
type defaultOCIDownloader struct {

View File

@ -27,8 +27,9 @@ import (
type storeDownloader struct {
OCIDownloader
os, arch string
extFile string
os, arch string
extFile string
imagePrefix string
}
func NewStoreDownloader() PlatformAwareOCIDownloader {
@ -37,6 +38,7 @@ func NewStoreDownloader() PlatformAwareOCIDownloader {
}
ociDownloader.WithOS(runtime.GOOS)
ociDownloader.WithArch(runtime.GOARCH)
ociDownloader.WithImagePrefix("linuxsuren")
return ociDownloader
}
@ -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
}
@ -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" {

View File

@ -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
}