// BuildGo builds and installs a binary tenet. It assumes go is installed and // the we are in the root of the tenet package. func (cfg *binaryBuildCfg) BuildGo() error { cfg.DW.Start.Done() defer cfg.DW.Bar.Increment() bin, err := util.LingoBin() if err != nil { return errors.Trace(err) } tenetPath := filepath.Join(bin, cfg.Owner, cfg.Name) util.Printf("Building Go binary: %s\n", tenetPath) cmd := exec.Command("go", "get", "-v") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Dir = cfg.dir if err := cmd.Run(); err != nil { return errors.Trace(err) } cmd2 := exec.Command("go", "build", "-o", tenetPath) cmd2.Stdout = os.Stdout cmd2.Stderr = os.Stderr cmd2.Dir = cfg.dir // TODO(waigani) capture this return as build error at end. cmd2.Stderr = os.Stderr return cmd2.Run() }
// BuildGo builds and installs a binary tenet. It assumes go is installed. func (cfg *dockerBuildCfg) BuildGo() error { cfg.DW.Start.Done() defer cfg.DW.Bar.Increment() dockerfile := filepath.Join(cfg.dir, "Dockerfile") var exists bool // Write a Dockerfile if one does not exist. if n, err := os.Stat(dockerfile); err != nil && !os.IsNotExist(err) { return errors.Trace(err) } else if n != nil { exists = true } if cfg.OverwriteDockerfile || !exists { err := cfg.writeDockerFile(dockerfile) if err != nil { return errors.Trace(err) } } c, err := cfg.client() if err != nil { return errors.Trace(err) } // TODO(waigani) remove when dev is published _, relDockerPath, lrRootDir, err := cfg.hackedPaths() if err != nil { return errors.Trace(err) } imageName := cfg.Owner + "/" + cfg.Name util.Printf("Building Docker image: %s\n", imageName) opts := goDocker.BuildImageOptions{ Name: imageName, Dockerfile: relDockerPath, //dockerfile, ContextDir: lrRootDir, // "~/go/src/github.com/lingo-reviews/tenets/simpleseed", // "~/go/src/github.com/lingo-reviews/tenets/simpleseed/", // TODO(waigani) when dev is published ContextDir = cfg.dir OutputStream: os.Stdout, } return c.BuildImage(opts) }
func push(ctx *cli.Context) { // TODO(waigani) a lot of this code is to support multiple drivers. It's // copied from build. It's left so we can easily add remote. We just hard // code to docker for now. if len(ctx.Args()) > 0 { oserrf("push takes no arguments") } // drivers := ctx.Args() // if len(drivers) == 0 { // drivers = allDrivers // } drivers := []string{"docker"} lingofiles, err := getLingofiles(ctx) if err != nil { oserrf(err.Error()) return } fn := len(lingofiles) if fn == 0 { util.Printf("WARNING tenet not built. No %s found.\n", lingofile) return } // set up drivers, waitgroups and progress bars allErrsc := make(chan error) allWaits := sync.WaitGroup{} dn := len(drivers) allWaits.Add(dn) driverWaits := make(map[string]*driverWait, dn) for _, driver := range drivers { bar := pb.New(fn) bar.Prefix(driver + " ") start := &sync.WaitGroup{} start.Add(fn) end := &sync.WaitGroup{} end.Add(fn) driverWaits[driver] = &driverWait{ start: start, end: end, bar: bar, } errsc := make(chan error) go func(wg *sync.WaitGroup, errc chan error) { wg.Wait() bar.FinishPrint("Success! All " + driver + " tenets built.") close(errsc) allWaits.Done() }(end, errsc) go func(errsc chan error) { for err := range errsc { allErrsc <- err } }(errsc) } // print progress bars to user for driver, dw := range driverWaits { go func(dw *driverWait) { dw.start.Wait() msg := "The %s tenet is being pushed ..." if fn > 0 { msg = "All %s tenets are being pushed ..." } util.Printf(msg, driver) dw.bar.Start() }(dw) } // start building all tenets for _, f := range lingofiles { go func(f string) { errs := pushTenet(f, driverWaits) for _, err := range errs { allErrsc <- err } }(f) } // wait for all results and print errors at the end go func() { allWaits.Wait() close(allErrsc) }() var errs []error for err := range allErrsc { errs = append(errs, err) } // util.NoPrint = false for _, err := range errs { util.Printf("push error: %v\n", err) } }
// Run builds each tenet for each lingofile from source for each driver // specified in drivers. func Run(drivers []string, lingofiles ...string) error { // set up drivers, waitgroups and progress bars allErrsc := make(chan error) allWaits := sync.WaitGroup{} dn := len(drivers) allWaits.Add(dn) driverWaits := make(map[string]*DriverWait, dn) fn := len(lingofiles) for _, driver := range drivers { bar := pb.New(fn) bar.Prefix(driver + " ") start := &sync.WaitGroup{} start.Add(fn) end := &sync.WaitGroup{} end.Add(fn) driverWaits[driver] = &DriverWait{ Start: start, End: end, Bar: bar, } errsc := make(chan error) go func(wg *sync.WaitGroup, errc chan error) { wg.Wait() bar.FinishPrint("Success! All " + driver + " tenets built.") close(errsc) allWaits.Done() }(end, errsc) go func(errsc chan error) { for err := range errsc { allErrsc <- err } }(errsc) } // print progress bars to user for driver, dw := range driverWaits { go func(dw *DriverWait) { dw.Start.Wait() msg := "The %s tenet has started to build ..." if fn > 0 { msg = "All %s tenets have started to build ..." } util.Printf(msg, driver) dw.Bar.Start() }(dw) } // start building all tenets for _, f := range lingofiles { go func(f string) { errs := buildTenet(f, driverWaits) for _, err := range errs { allErrsc <- err } }(f) } // wait for all results and print errors at the end go func() { allWaits.Wait() close(allErrsc) }() var errs []error for err := range allErrsc { errs = append(errs, err) } // util.NoPrint = false for _, err := range errs { util.Printf("build error: %v\n", err) } return nil }
// TODO(waigani) add more user output func build(ctx *cli.Context) { drivers := ctx.Args() if len(drivers) == 0 { drivers = allDrivers } lingofiles, err := getLingofiles(ctx) if err != nil { oserrf(err.Error()) return } fn := len(lingofiles) if fn == 0 { util.Printf("WARNING tenet not built. No %s found.\n", lingofile) return } // set up drivers, waitgroups and progress bars allErrsc := make(chan error) allWaits := sync.WaitGroup{} dn := len(drivers) allWaits.Add(dn) driverWaits := make(map[string]*driverWait, dn) for _, driver := range drivers { bar := pb.New(fn) bar.Prefix(driver + " ") start := &sync.WaitGroup{} start.Add(fn) end := &sync.WaitGroup{} end.Add(fn) driverWaits[driver] = &driverWait{ start: start, end: end, bar: bar, } errsc := make(chan error) go func(wg *sync.WaitGroup, errc chan error) { wg.Wait() bar.FinishPrint("Success! All " + driver + " tenets built.") close(errsc) allWaits.Done() }(end, errsc) go func(errsc chan error) { for err := range errsc { allErrsc <- err } }(errsc) } // print progress bars to user for driver, dw := range driverWaits { go func(dw *driverWait) { dw.start.Wait() msg := "The %s tenet has started to build ..." if fn > 0 { msg = "All %s tenets have started to build ..." } util.Printf(msg, driver) dw.bar.Start() }(dw) } // start building all tenets for _, f := range lingofiles { go func(f string) { errs := buildTenet(f, driverWaits) for _, err := range errs { allErrsc <- err } }(f) } // wait for all results and print errors at the end go func() { allWaits.Wait() close(allErrsc) }() var errs []error for err := range allErrsc { errs = append(errs, err) } // util.NoPrint = false for _, err := range errs { util.Printf("build error: %v\n", err) } }