github.com/naphatkrit/deis@v1.12.3/client/cmd/builds.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "os" 7 8 "gopkg.in/yaml.v2" 9 10 "github.com/deis/deis/client/controller/models/builds" 11 ) 12 13 // BuildsList lists an app's builds. 14 func BuildsList(appID string, results int) error { 15 c, appID, err := load(appID) 16 17 if err != nil { 18 return err 19 } 20 21 if results == defaultLimit { 22 results = c.ResponseLimit 23 } 24 25 builds, count, err := builds.List(c, appID, results) 26 27 if err != nil { 28 return err 29 } 30 31 fmt.Printf("=== %s Builds%s", appID, limitCount(len(builds), count)) 32 33 for _, build := range builds { 34 fmt.Println(build.UUID, build.Created) 35 } 36 return nil 37 } 38 39 // BuildsCreate creates a build for an app. 40 func BuildsCreate(appID, image, procfile string) error { 41 c, appID, err := load(appID) 42 43 if err != nil { 44 return err 45 } 46 47 procfileMap := make(map[string]string) 48 49 if procfile != "" { 50 if procfileMap, err = parseProcfile([]byte(procfile)); err != nil { 51 return err 52 } 53 } else if _, err := os.Stat("Procfile"); err == nil { 54 contents, err := ioutil.ReadFile("Procfile") 55 if err != nil { 56 return err 57 } 58 59 if procfileMap, err = parseProcfile(contents); err != nil { 60 return err 61 } 62 } 63 64 fmt.Print("Creating build... ") 65 quit := progress() 66 _, err = builds.New(c, appID, image, procfileMap) 67 quit <- true 68 <-quit 69 70 if err != nil { 71 return err 72 } 73 74 fmt.Println("done") 75 76 return nil 77 } 78 79 func parseProcfile(procfile []byte) (map[string]string, error) { 80 procfileMap := make(map[string]string) 81 return procfileMap, yaml.Unmarshal(procfile, &procfileMap) 82 }