[REV] read procfile and set image default memory 512M

This commit is contained in:
barnett 2019-04-03 18:58:58 +08:00
parent 0ad0e4f034
commit d7a541c125
4 changed files with 28 additions and 18 deletions

View File

@ -19,15 +19,17 @@
package code
import (
"io/ioutil"
"path"
"github.com/goodrain/rainbond/util"
)
//CheckProcfile check runtime with lang
func CheckProcfile(buildPath string, lang Lang) bool {
func CheckProcfile(buildPath string, lang Lang) (bool, string) {
if ok, _ := util.FileExists(path.Join(buildPath, "Procfile")); ok {
return true
body, _ := ioutil.ReadFile(path.Join(buildPath, "Procfile"))
return true, string(body)
}
return false
return false, ""
}

View File

@ -20,9 +20,10 @@ package parser
import (
"fmt"
"strconv"
"strings"
"k8s.io/apimachinery/pkg/api/resource"
"github.com/goodrain/rainbond/builder/parser/code"
"github.com/goodrain/rainbond/builder/parser/discovery"
)
@ -197,21 +198,15 @@ func GetPortProtocol(port int) string {
//10k 128
//10b 128
func readmemory(s string) int {
if strings.HasSuffix(s, "m") {
s, err := strconv.Atoi(s[0 : len(s)-1])
if err != nil {
return 128
}
return s
q, err := resource.ParseQuantity(strings.ToUpper(s))
if err != nil {
return 512
}
if strings.HasSuffix(s, "g") {
s, err := strconv.Atoi(s[0 : len(s)-1])
if err != nil {
return 128
}
return s * 1024
re, _ := q.AsInt64()
if re != 0 {
return int(re) / (1000 * 1000)
}
return 128
return 512
}
func parseImageName(s string) Image {

View File

@ -27,3 +27,9 @@ func TestParseImageName(t *testing.T) {
image := parseImageName("192.168.0.1:9090/asdasd/asdasd:asdad")
fmt.Println(image.Name, image.Tag)
}
func TestReadmemory(t *testing.T) {
t.Log(readmemory("10G"))
t.Log(readmemory("300m"))
t.Log(readmemory("300M"))
}

View File

@ -275,7 +275,14 @@ func (d *SourceCodeParse) Parse() ParseErrorList {
}
}
d.memory = getRecommendedMemory(lang)
d.Procfile = code.CheckProcfile(buildPath, lang)
var ProcfileLine string
d.Procfile, ProcfileLine = code.CheckProcfile(buildPath, lang)
if ProcfileLine != "" {
d.envs["BUILD_PROCFILE"] = &Env{
Name: "BUILD_PROCFILE",
Value: ProcfileLine,
}
}
if rbdfileConfig != nil {
//handle profile env
for k, v := range rbdfileConfig.Envs {