Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: optimize builder and runner image acquisition logic #1789

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions builder/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions builder/build/code_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions builder/exector/build_from_sourcecode_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type SourceCodeBuildItem struct {
Configs map[string]gjson.Result `json:"configs"`
Ctx context.Context
FailCause string
BRVersion string
}

// Commit code Commit
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions builder/exector/exector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 30 additions & 13 deletions builder/repostory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand All @@ -68,37 +73,49 @@ func GetImageUserInfoV2(domain, user, pass string) (string, string) {
return "", ""
}

//GetImageRepo -
// GetImageRepo -
func GetImageRepo(imageRepo string) string {
if imageRepo == "" {
return REGISTRYDOMAIN
}
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"
3 changes: 2 additions & 1 deletion cmd/builder/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Config struct {
RuntimeEndpoint string
KeepCount int
CleanInterval int
BRVersion string
}

// Builder builder server
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion worker/appm/conversion/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading