diff --git a/builder/build/build.go b/builder/build/build.go index 50c881e878..7658c74683 100644 --- a/builder/build/build.go +++ b/builder/build/build.go @@ -113,6 +113,7 @@ type Request struct { HostAlias []HostAlias Ctx context.Context Arch string + BRVersion string } // HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the diff --git a/builder/build/code_build.go b/builder/build/code_build.go index de1014f098..e421a7b0c7 100644 --- a/builder/build/code_build.go +++ b/builder/build/code_build.go @@ -138,7 +138,7 @@ func (s *slugBuild) buildRunnerImage(slugPackage string) (string, error) { return "", fmt.Errorf("write default runtime dockerfile error:%s", err.Error()) } //build runtime image - if err := s.re.ImageClient.ImagesPullAndPush(builder.RUNNERIMAGENAME, builder.ONLINERUNNERIMAGENAME, "", "", s.re.Logger); err != nil { + if err := s.re.ImageClient.ImagesPullAndPush(builder.RUNNERIMAGENAME, builder.GetRunnerImage(s.re.BRVersion), "", "", s.re.Logger); err != nil { return "", fmt.Errorf("pull image %s: %v", builder.RUNNERIMAGENAME, err) } logrus.Infof("pull image %s successfully.", builder.RUNNERIMAGENAME) @@ -472,7 +472,7 @@ func (s *slugBuild) runBuildJob(re *Request) error { defer cancel() // Get builder image at build time - if err := s.re.ImageClient.ImagesPullAndPush(builder.BUILDERIMAGENAME, builder.ONLINEBUILDERIMAGENAME, "", "", re.Logger); err != nil { + if err := s.re.ImageClient.ImagesPullAndPush(builder.BUILDERIMAGENAME, builder.GetBuilderImage(s.re.BRVersion), "", "", re.Logger); err != nil { return err } diff --git a/builder/exector/build_from_sourcecode_run.go b/builder/exector/build_from_sourcecode_run.go index b7b43879d1..9c2c06cd00 100644 --- a/builder/exector/build_from_sourcecode_run.go +++ b/builder/exector/build_from_sourcecode_run.go @@ -79,6 +79,7 @@ type SourceCodeBuildItem struct { Configs map[string]gjson.Result `json:"configs"` Ctx context.Context FailCause string + BRVersion string } // Commit code Commit @@ -365,6 +366,7 @@ func (i *SourceCodeBuildItem) codeBuild() (*build.Response, error) { CacheMode: i.CacheMode, CachePath: i.CachePath, Arch: i.Arch, + BRVersion: i.BRVersion, } res, err := codeBuild.Build(buildReq) return res, err diff --git a/builder/exector/exector.go b/builder/exector/exector.go index 5a5be9a46c..ac50778b6b 100644 --- a/builder/exector/exector.go +++ b/builder/exector/exector.go @@ -362,6 +362,7 @@ func (e *exectorManager) buildFromSourceCode(task *pb.TaskMessage) { i.GRDataPVCName = e.cfg.GRDataPVCName i.CacheMode = e.cfg.CacheMode i.CachePath = e.cfg.CachePath + i.BRVersion = e.cfg.BRVersion i.Logger.Info("Build app version from source code start", map[string]string{"step": "builder-exector", "status": "starting"}) start := time.Now() defer event.GetManager().ReleaseLogger(i.Logger) diff --git a/builder/repostory.go b/builder/repostory.go index 6c50c36029..af34cc9753 100644 --- a/builder/repostory.go +++ b/builder/repostory.go @@ -53,8 +53,13 @@ func init() { if os.Getenv("ABROAD") != "" { ONLINEREGISTRYDOMAIN = "docker.io/rainbond" } - ONLINEBUILDERIMAGENAME = fmt.Sprintf("%s:%s-%s", path.Join(ONLINEREGISTRYDOMAIN, "builder"), CIVERSION, arch) - ONLINERUNNERIMAGENAME = fmt.Sprintf("%s:%s-%s", path.Join(ONLINEREGISTRYDOMAIN, "runner"), CIVERSION, arch) + if release := os.Getenv("RELEASE_DESC"); release != "" { + releaseList := strings.Split(release, "-") + if len(releaseList) > 0 { + CIVERSION = fmt.Sprintf("%v-%v", releaseList[0], releaseList[1]) + } + } + } // GetImageUserInfoV2 - @@ -68,7 +73,7 @@ func GetImageUserInfoV2(domain, user, pass string) (string, string) { return "", "" } -//GetImageRepo - +// GetImageRepo - func GetImageRepo(imageRepo string) string { if imageRepo == "" { return REGISTRYDOMAIN @@ -76,29 +81,41 @@ func GetImageRepo(imageRepo string) string { return imageRepo } -//REGISTRYDOMAIN REGISTRY_DOMAIN +// REGISTRYDOMAIN REGISTRY_DOMAIN var REGISTRYDOMAIN = constants.DefImageRepository -//REGISTRYUSER REGISTRY USER NAME +// REGISTRYUSER REGISTRY USER NAME var REGISTRYUSER = "" -//REGISTRYPASS REGISTRY PASSWORD +// REGISTRYPASS REGISTRY PASSWORD var REGISTRYPASS = "" -//RUNNERIMAGENAME runner image name +// RUNNERIMAGENAME runner image name var RUNNERIMAGENAME string -//BUILDERIMAGENAME builder image name +// BUILDERIMAGENAME builder image name var BUILDERIMAGENAME string // ONLINEREGISTRYDOMAIN online REGISTRY_DOMAIN var ONLINEREGISTRYDOMAIN = constants.DefOnlineImageRepository -// ONLINEBUILDERIMAGENAME online builder image name -var ONLINEBUILDERIMAGENAME string +// GetBuilderImage GetBuilderImage +func GetBuilderImage(brVersion string) string { + arch := runtime.GOARCH + if brVersion == "" { + brVersion = CIVERSION + } + return fmt.Sprintf("%s:%s-%s", path.Join(ONLINEREGISTRYDOMAIN, "builder"), brVersion, arch) +} -// ONLINERUNNERIMAGENAME online runner image name -var ONLINERUNNERIMAGENAME string +// GetRunnerImage GetRunnerImage +func GetRunnerImage(brVersion string) string { + arch := runtime.GOARCH + if brVersion == "" { + brVersion = CIVERSION + } + return fmt.Sprintf("%s:%s-%s", path.Join(ONLINEREGISTRYDOMAIN, "runner"), brVersion, arch) +} // CIVERSION - -var CIVERSION = "v5.14.0-release" +var CIVERSION = "v5.16.0-release" diff --git a/cmd/builder/option/option.go b/cmd/builder/option/option.go index 409a803626..2c57dbca85 100644 --- a/cmd/builder/option/option.go +++ b/cmd/builder/option/option.go @@ -62,6 +62,7 @@ type Config struct { RuntimeEndpoint string KeepCount int CleanInterval int + BRVersion string } // Builder builder server @@ -112,7 +113,7 @@ func (a *Builder) AddFlags(fs *pflag.FlagSet) { fs.BoolVar(&a.BuildKitCache, "buildkit-cache", false, "whether to enable the buildkit image cache") fs.IntVar(&a.KeepCount, "keep-count", 5, "default number of reserved copies for images") fs.IntVar(&a.CleanInterval, "clean-interval", 60, "clean image interval,default 60 minute") - + fs.StringVar(&a.BRVersion, "br-version", "v5.16.0-release", "builder and runner version") } // SetLog 设置log diff --git a/worker/appm/conversion/version.go b/worker/appm/conversion/version.go index 399a00fd36..9e56278339 100644 --- a/worker/appm/conversion/version.go +++ b/worker/appm/conversion/version.go @@ -299,7 +299,7 @@ func getMainContainer(as *v1.AppService, version *dbmodel.VersionInfo, dv *volum if imagename == "" { if version.DeliveredType == "slug" { imagename = builder.RUNNERIMAGENAME - if err := sources.ImagesPullAndPush(builder.RUNNERIMAGENAME, builder.ONLINERUNNERIMAGENAME, "", "", nil); err != nil { + if err := sources.ImagesPullAndPush(builder.RUNNERIMAGENAME, builder.GetRunnerImage(""), "", "", nil); err != nil { logrus.Errorf("[getMainContainer] get runner image failed: %v", err) } } else {