mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-01 03:07:51 +08:00
Merge branch 'V5.2' into V5.2
This commit is contained in:
commit
96c080b770
@ -77,8 +77,8 @@ type Request struct {
|
||||
RbdNamespace string
|
||||
GRDataPVCName string
|
||||
CachePVCName string
|
||||
CacheSource string
|
||||
BuilderInNode string
|
||||
CacheMode string
|
||||
CachePath string
|
||||
TenantID string
|
||||
SourceDir string
|
||||
CacheDir string
|
||||
@ -102,11 +102,11 @@ type Request struct {
|
||||
}
|
||||
|
||||
func (r *Request) CacheVolumeSource() corev1.VolumeSource {
|
||||
if r.CacheSource == "hostpath" {
|
||||
if r.CacheMode == "hostpath" {
|
||||
hostPathType := corev1.HostPathDirectoryOrCreate
|
||||
return corev1.VolumeSource{
|
||||
HostPath: &corev1.HostPathVolumeSource{
|
||||
Path: "/cache",
|
||||
Path: r.CachePath,
|
||||
Type: &hostPathType,
|
||||
},
|
||||
}
|
||||
|
@ -146,6 +146,11 @@ func (s *slugBuild) buildRunnerImage(slugPackage string) (string, error) {
|
||||
} else {
|
||||
runbuildOptions.NoCache = false
|
||||
}
|
||||
// pull image runner
|
||||
if _, err := sources.ImagePull(s.re.DockerClient, builder.RUNNERIMAGENAME, builder.REGISTRYUSER, builder.REGISTRYPASS, s.re.Logger, 30); err != nil {
|
||||
return "", fmt.Errorf("pull image %s: %v", builder.RUNNERIMAGENAME, err)
|
||||
}
|
||||
logrus.Infof("pull image %s successfully.", builder.RUNNERIMAGENAME)
|
||||
err := sources.ImageBuild(s.re.DockerClient, cacheDir, runbuildOptions, s.re.Logger, 30)
|
||||
if err != nil {
|
||||
s.re.Logger.Error(fmt.Sprintf("build image %s of new version failure", imageName), map[string]string{"step": "builder-exector", "status": "failure"})
|
||||
@ -302,16 +307,20 @@ func (s *slugBuild) runBuildJob(re *Request) error {
|
||||
|
||||
podSpec := corev1.PodSpec{RestartPolicy: corev1.RestartPolicyOnFailure} // only support never and onfailure
|
||||
// schedule builder
|
||||
if re.BuilderInNode != "" {
|
||||
logrus.Debugf("builder schedule to node: %s", re.BuilderInNode)
|
||||
podSpec.NodeSelector = map[string]string{
|
||||
"kubernetes.io/hostname": re.BuilderInNode,
|
||||
}
|
||||
podSpec.Tolerations = []corev1.Toleration{
|
||||
{
|
||||
Operator: "Exists",
|
||||
},
|
||||
if re.CacheMode == "hostpath" {
|
||||
logrus.Debugf("builder cache mode using hostpath, schedule job into current node")
|
||||
hostIP := os.Getenv("HOST_IP")
|
||||
if hostIP != "" {
|
||||
podSpec.NodeSelector = map[string]string{
|
||||
"kubernetes.io/hostname": hostIP,
|
||||
}
|
||||
podSpec.Tolerations = []corev1.Toleration{
|
||||
{
|
||||
Operator: "Exists",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
logrus.Debugf("request is: %+v", re)
|
||||
podSpec.Volumes = []corev1.Volume{
|
||||
|
@ -51,8 +51,8 @@ type SourceCodeBuildItem struct {
|
||||
TenantName string `json:"tenant_name"`
|
||||
GRDataPVCName string `json:"gr_data_pvc_name"`
|
||||
CachePVCName string `json:"cache_pvc_name"`
|
||||
CacheSource string `json:"cache_source"`
|
||||
BuilderInNode string `json:"builder_in_node"`
|
||||
CacheMode string `json:"cache_mode"`
|
||||
CachePath string `json:"cache_path"`
|
||||
ServiceAlias string `json:"service_alias"`
|
||||
Action string `json:"action"`
|
||||
DestImage string `json:"dest_image"`
|
||||
@ -258,8 +258,8 @@ func (i *SourceCodeBuildItem) codeBuild() (*build.Response, error) {
|
||||
Ctx: i.Ctx,
|
||||
GRDataPVCName: i.GRDataPVCName,
|
||||
CachePVCName: i.CachePVCName,
|
||||
CacheSource: i.CacheSource,
|
||||
BuilderInNode: i.BuilderInNode,
|
||||
CacheMode: i.CacheMode,
|
||||
CachePath: i.CachePath,
|
||||
}
|
||||
res, err := codeBuild.Build(buildReq)
|
||||
return res, err
|
||||
|
@ -326,8 +326,8 @@ func (e *exectorManager) buildFromSourceCode(task *pb.TaskMessage) {
|
||||
i.Ctx = e.ctx
|
||||
i.CachePVCName = e.cfg.CachePVCName
|
||||
i.GRDataPVCName = e.cfg.GRDataPVCName
|
||||
i.CacheSource = e.cfg.CacheSource
|
||||
i.BuilderInNode = e.cfg.BuilderInNode
|
||||
i.CacheMode = e.cfg.CacheMode
|
||||
i.CachePath = e.cfg.CachePath
|
||||
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)
|
||||
|
@ -366,12 +366,6 @@ func ImageBuild(dockerCli *client.Client, contextDir string, options types.Image
|
||||
return err
|
||||
}
|
||||
|
||||
// pull image runner
|
||||
if _, err := ImagePull(dockerCli, builder.RUNNERIMAGENAME, builder.REGISTRYUSER, builder.REGISTRYPASS, logger, timeout); err != nil {
|
||||
return fmt.Errorf("pull image %s: %v", builder.RUNNERIMAGENAME, err)
|
||||
}
|
||||
logrus.Infof("pull image %s successfully.", builder.RUNNERIMAGENAME)
|
||||
|
||||
rc, err := dockerCli.ImageBuild(ctx, buildCtx, options)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -53,8 +53,8 @@ type Config struct {
|
||||
RbdRepoName string
|
||||
GRDataPVCName string
|
||||
CachePVCName string
|
||||
CacheSource string
|
||||
BuilderInNode string
|
||||
CacheMode string
|
||||
CachePath string
|
||||
}
|
||||
|
||||
//Builder builder server
|
||||
@ -96,9 +96,8 @@ func (a *Builder) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&a.RbdRepoName, "rbd-repo", "rbd-repo", "rbd component repo's name")
|
||||
fs.StringVar(&a.GRDataPVCName, "pvc-grdata-name", "grdata", "pvc name of grdata")
|
||||
fs.StringVar(&a.CachePVCName, "pvc-cache-name", "cache", "pvc name of cache")
|
||||
fs.StringVar(&a.CacheSource, "cache-source", "pvc", "volume type for cache path, default set pvc")
|
||||
fs.StringVar(&a.BuilderInNode, "job-node", "", "where builder job running")
|
||||
|
||||
fs.StringVar(&a.CacheMode, "cache-mode", "sharefile", "volume cache mount type, can be hostpath and sharefile, default is sharefile, which mount using pvc")
|
||||
fs.StringVar(&a.CachePath, "cache-path", "/cache", "volume cache mount path, when cache-mode using hostpath, default path is /cache")
|
||||
}
|
||||
|
||||
//SetLog 设置log
|
||||
|
@ -125,6 +125,7 @@ type Conf struct {
|
||||
// Namespace for Rainbond application.
|
||||
RbdNamespace string
|
||||
ImageRepositoryHost string
|
||||
GatewayVIP string
|
||||
HostsFile string
|
||||
}
|
||||
|
||||
@ -188,6 +189,7 @@ func (a *Conf) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.Int32Var(&a.ImageGCLowThresholdPercent, "image-gc-low-threshold", 75, "The percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to. Values must be within the range [0, 100] and should not be larger than that of --image-gc-high-threshold.")
|
||||
fs.StringVar(&a.RbdNamespace, "rbd-ns", "rbd-system", "The namespace of rainbond applications.")
|
||||
fs.StringVar(&a.ImageRepositoryHost, "image-repo-host", "goodrain.me", "The host of image repository")
|
||||
fs.StringVar(&a.GatewayVIP, "gateway-vip", "", "The vip of gateway")
|
||||
fs.StringVar(&a.HostsFile, "hostsfile", "/newetc/hosts", "/etc/hosts mapped path in the container. eg. /etc/hosts:/tmp/hosts. Do not set hostsfile to /etc/hosts")
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,24 @@ func (h *hostManager) Start() {
|
||||
// no need to write hosts file
|
||||
return
|
||||
}
|
||||
if h.cfg.GatewayVIP != "" {
|
||||
if err := h.hostCallback.hosts.Cleanup(); err != nil {
|
||||
logrus.Warningf("cleanup hosts file: %v", err)
|
||||
return
|
||||
}
|
||||
logrus.Infof("set hosts %s to %s", h.cfg.ImageRepositoryHost, h.cfg.GatewayVIP)
|
||||
lines := []string{
|
||||
util.StartOfSection,
|
||||
h.cfg.GatewayVIP + " " + h.cfg.ImageRepositoryHost,
|
||||
h.cfg.GatewayVIP + " " + "region.goodrain.me",
|
||||
util.EndOfSection,
|
||||
}
|
||||
h.hostCallback.hosts.AddLines(lines...)
|
||||
if err := h.hostCallback.hosts.Flush(); err != nil {
|
||||
logrus.Warningf("flush hosts file: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
h.discover.AddProject("rbd-gateway", h.hostCallback)
|
||||
}
|
||||
|
||||
@ -78,6 +96,7 @@ type hostCallback struct {
|
||||
hosts util.Hosts
|
||||
}
|
||||
|
||||
// TODO HA error
|
||||
func (h *hostCallback) UpdateEndpoints(endpoints ...*config.Endpoint) {
|
||||
logrus.Info("hostCallback; update endpoints")
|
||||
if err := h.hosts.Cleanup(); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user