本文整理匯總了Golang中github.com/flynn/flynn/test/cluster.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
var err error
var res *check.Result
// defer exiting so it runs after all other defers
defer func() {
if err != nil || res != nil && !res.Passed() {
os.Exit(1)
}
}()
flynnrc = args.Flynnrc
routerIP = args.RouterIP
if flynnrc == "" {
var rootFS string
c := cluster.New(args.BootConfig, os.Stdout)
rootFS, err = c.BuildFlynn(args.RootFS, "origin/master", false)
if err != nil {
c.Shutdown()
log.Println("could not build flynn: ", err)
return
}
if args.KeepRootFS {
fmt.Println("Built Flynn in rootfs:", rootFS)
} else {
defer os.RemoveAll(rootFS)
}
if err = c.Boot(args.Backend, rootFS, 1); err != nil {
log.Println("could not boot cluster: ", err)
return
}
if args.Kill {
defer c.Shutdown()
}
if err = createFlynnrc(c); err != nil {
log.Println(err)
return
}
defer os.RemoveAll(flynnrc)
routerIP = c.RouterIP
}
defer func() {
if args.Debug && (err != nil || res != nil && !res.Passed()) {
dumpLogs()
}
}()
res = check.RunAll(&check.RunConf{
Filter: args.Run,
Stream: true,
Verbose: true,
KeepWorkDir: args.Debug,
})
fmt.Println(res)
}
示例2: build
func (r *Runner) build(b *Build) (err error) {
r.updateStatus(b, "pending", "")
<-r.buildCh
defer func() {
r.buildCh <- struct{}{}
}()
var buildLog bytes.Buffer
defer func() {
if err != nil {
fmt.Fprintf(&buildLog, "build error: %s\n", err)
}
url := r.uploadToS3(buildLog, b)
if err == nil {
r.updateStatus(b, "success", url)
} else {
r.updateStatus(b, "failure", url)
}
}()
log.Printf("building %s[%s]\n", b.Repo, b.Commit)
out := io.MultiWriter(os.Stdout, &buildLog)
bc := r.bc
bc.Network, err = r.allocateNet()
if err != nil {
return err
}
defer r.releaseNet(bc.Network)
c := cluster.New(bc, out)
rootFS, err := c.BuildFlynn(r.rootFS, b.Commit)
defer os.RemoveAll(rootFS)
if err != nil {
return fmt.Errorf("could not build flynn: %s", err)
}
if err := c.Boot(args.Backend, rootFS, 1); err != nil {
return fmt.Errorf("could not boot cluster: %s", err)
}
defer c.Shutdown()
config, err := c.CLIConfig()
if err != nil {
return fmt.Errorf("could not generate flynnrc: %s", err)
}
var script bytes.Buffer
testRunScript.Execute(&script, c)
return c.Run(script.String(), &cluster.Streams{
Stdin: bytes.NewBuffer(config.Marshal()),
Stdout: out,
Stderr: out,
})
}
示例3: main
func main() {
var res *check.Result
// defer exiting so it runs after all other defers
defer func() {
if res != nil && !res.Passed() {
os.Exit(1)
}
}()
flynnrc = args.Flynnrc
routerIP = args.RouterIP
if flynnrc == "" {
c := cluster.New(args.BootConfig, os.Stdout)
rootFS, err := c.BuildFlynn(args.RootFS, "origin/master")
if err != nil {
log.Fatal("could not build flynn:", err)
}
if args.KeepRootFS {
fmt.Println("Built Flynn in rootfs:", rootFS)
} else {
defer os.RemoveAll(rootFS)
}
if err := c.Boot(args.Backend, rootFS, 1); err != nil {
log.Fatal("could not boot cluster: ", err)
}
if args.Kill {
defer c.Shutdown()
}
if err := createFlynnrc(c); err != nil {
log.Fatal(err)
}
defer os.RemoveAll(flynnrc)
routerIP = c.RouterIP
}
ssh, err := genSSHKey()
if err != nil {
log.Fatal(err)
}
defer ssh.Cleanup()
gitEnv = ssh.Env
keyAdd := flynn("", "key", "add", ssh.Pub)
if keyAdd.Err != nil {
log.Fatalf("Error during `%s`:\n%s%s", strings.Join(keyAdd.Cmd, " "), keyAdd.Output, keyAdd.Err)
}
res = check.RunAll(&check.RunConf{
Stream: true,
Verbose: true,
KeepWorkDir: args.Debug,
})
fmt.Println(res)
}
示例4: main
func main() {
flynnrc = args.Flynnrc
if flynnrc == "" {
c := cluster.New(args.BootConfig, os.Stdout)
dockerfs := args.DockerFS
if dockerfs == "" {
var err error
if dockerfs, err = c.BuildFlynn("", util.Repos); err != nil {
log.Fatal("could not build flynn:", err)
}
if !args.KeepDockerFS {
defer os.RemoveAll(dockerfs)
}
}
if err := c.Boot(dockerfs, 1); err != nil {
log.Fatal("could not boot cluster: ", err)
}
if args.Kill {
defer c.Shutdown()
}
if err := createFlynnrc(c); err != nil {
log.Fatal(err)
}
defer os.RemoveAll(flynnrc)
}
ssh, err := genSSHKey()
if err != nil {
log.Fatal(err)
}
defer ssh.Cleanup()
gitEnv = ssh.Env
keyAdd := flynn("", "key-add", ssh.Pub)
if keyAdd.Err != nil {
log.Fatalf("Error during `%s`:\n%s%s", strings.Join(keyAdd.Cmd, " "), keyAdd.Output, keyAdd.Err)
}
res := check.RunAll(&check.RunConf{
Stream: true,
Verbose: true,
KeepWorkDir: args.Debug,
})
fmt.Println(res)
}
示例5: build
func (r *Runner) build(b *Build) (err error) {
logFile, err := ioutil.TempFile("", "build-log")
if err != nil {
return err
}
b.LogFile = logFile.Name()
buildLog := buildlog.NewLog(logFile)
mainLog, err := buildLog.NewFile("build.log")
if err != nil {
return err
}
r.updateStatus(b, "pending")
<-r.buildCh
defer func() {
r.buildCh <- struct{}{}
}()
start := time.Now()
fmt.Fprintf(mainLog, "Starting build of %s at %s\n", b.Commit, start.Format(time.RFC822))
var c *cluster.Cluster
defer func() {
b.Duration = time.Since(start)
b.DurationFormatted = formatDuration(b.Duration)
fmt.Fprintf(mainLog, "build finished in %s\n", b.DurationFormatted)
if err != nil {
fmt.Fprintf(mainLog, "build error: %s\n", err)
fmt.Fprintln(mainLog, "DUMPING LOGS")
c.DumpLogs(buildLog)
}
c.Shutdown()
buildLog.Close()
b.LogURL = r.uploadToS3(logFile, b, buildLog.Boundary())
logFile.Close()
os.RemoveAll(b.LogFile)
b.LogFile = ""
if err == nil {
log.Printf("build %s passed!\n", b.ID)
r.updateStatus(b, "success")
r.ircMsgs <- fmt.Sprintf("PASS: %s %s", b.Description, b.URL())
} else {
log.Printf("build %s failed: %s\n", b.ID, err)
r.updateStatus(b, "failure")
r.ircMsgs <- fmt.Sprintf("FAIL: %s %s", b.Description, b.URL())
}
}()
log.Printf("building %s\n", b.Commit)
out := &iotool.SafeWriter{W: io.MultiWriter(os.Stdout, mainLog)}
bc := r.bc
bc.Network = r.allocateNet()
defer r.releaseNet(bc.Network)
c = cluster.New(bc, out)
log.Println("created cluster with ID", c.ID)
r.clusters[c.ID] = c
defer func() {
delete(r.clusters, c.ID)
}()
rootFS, err := c.BuildFlynn(r.rootFS, b.Commit, b.Merge, true)
defer removeRootFS(rootFS)
if err != nil {
return fmt.Errorf("could not build flynn: %s", err)
}
if _, err := c.Boot(cluster.ClusterTypeDefault, 3, buildLog, false); err != nil {
return fmt.Errorf("could not boot cluster: %s", err)
}
config, err := c.CLIConfig()
if err != nil {
return fmt.Errorf("could not generate flynnrc: %s", err)
}
var script bytes.Buffer
testRunScript.Execute(&script, map[string]interface{}{"Cluster": c, "Config": config.Clusters[0], "ListenPort": listenPort})
return c.RunWithEnv(script.String(), &cluster.Streams{
Stdout: out,
Stderr: out,
}, map[string]string{"TEST_RUNNER_AUTH_KEY": r.authKey})
}
示例6: build
func (r *Runner) build(b *Build) (err error) {
r.updateStatus(b, "pending", "")
<-r.buildCh
defer func() {
r.buildCh <- struct{}{}
}()
var buildLog bytes.Buffer
start := time.Now()
fmt.Fprintf(&buildLog, "Starting build of %s at %s\n", b.Commit, start.Format(time.RFC822))
defer func() {
b.Duration = time.Since(start)
b.DurationFormatted = formatDuration(b.Duration)
fmt.Fprintf(&buildLog, "build finished in %s\n", b.DurationFormatted)
if err != nil {
fmt.Fprintf(&buildLog, "build error: %s\n", err)
}
url := r.uploadToS3(buildLog, b)
if err == nil {
r.updateStatus(b, "success", url)
} else {
r.updateStatus(b, "failure", url)
}
}()
log.Printf("building %s[%s]\n", b.Repo, b.Commit)
out := io.MultiWriter(os.Stdout, &buildLog)
bc := r.bc
bc.Network, err = r.allocateNet()
if err != nil {
return err
}
defer r.releaseNet(bc.Network)
c := cluster.New(bc, out)
log.Println("created cluster with ID", c.ID)
r.clusters[c.ID] = c
defer func() {
delete(r.clusters, c.ID)
c.Shutdown()
}()
rootFS, err := c.BuildFlynn(r.rootFS, b.Commit, b.Merge)
defer os.RemoveAll(rootFS)
if err != nil {
return fmt.Errorf("could not build flynn: %s", err)
}
if err := c.Boot(rootFS, 3); err != nil {
return fmt.Errorf("could not boot cluster: %s", err)
}
config, err := c.CLIConfig()
if err != nil {
return fmt.Errorf("could not generate flynnrc: %s", err)
}
var script bytes.Buffer
testRunScript.Execute(&script, map[string]interface{}{"Cluster": c, "ListenPort": listenPort, "AuthKey": r.authKey})
return c.Run(script.String(), &cluster.Streams{
Stdin: bytes.NewBuffer(config.Marshal()),
Stdout: out,
Stderr: out,
})
}
示例7: main
func main() {
var err error
var res *check.Result
// defer exiting here so it runs after all other defers
defer func() {
if err != nil || res != nil && !res.Passed() {
if args.Debug {
if args.Gist {
exec.Command("flynn-host", "upload-debug-info").Run()
} else {
dumpLogs()
}
}
os.Exit(1)
}
}()
flynnrc = args.Flynnrc
routerIP = args.RouterIP
if flynnrc == "" {
var rootFS string
testCluster = cluster.New(args.BootConfig, os.Stdout)
rootFS, err = testCluster.BuildFlynn(args.RootFS, "origin/master", false)
if err != nil {
testCluster.Shutdown()
log.Println("could not build flynn: ", err)
return
}
if args.KeepRootFS {
fmt.Println("Built Flynn in rootfs:", rootFS)
} else {
defer os.RemoveAll(rootFS)
}
if err = testCluster.Boot(rootFS, 3); err != nil {
log.Println("could not boot cluster: ", err)
return
}
if args.Kill {
defer testCluster.Shutdown()
}
if err = createFlynnrc(); err != nil {
log.Println(err)
return
}
defer os.RemoveAll(flynnrc)
routerIP = testCluster.RouterIP
}
if args.ClusterAPI != "" {
httpClient = &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{ServerName: "ci.flynn.io"}}}
res, err := httpClient.Get(args.ClusterAPI)
if err != nil {
log.Println(err)
return
}
testCluster = &cluster.Cluster{}
err = json.NewDecoder(res.Body).Decode(testCluster)
res.Body.Close()
if err != nil {
log.Println(err)
return
}
}
res = check.RunAll(&check.RunConf{
Filter: args.Run,
Stream: args.Stream,
Verbose: args.Debug,
KeepWorkDir: args.Debug,
ConcurrencyLevel: 5,
})
fmt.Println(res)
}
示例8: main
func main() {
defer shutdown.Exit()
var err error
if err = lookupImageURIs(); err != nil {
log.Fatalf("could not determine image ID: %s", err)
}
var res *check.Result
// defer exiting here so it runs after all other defers
defer func() {
if err != nil || res != nil && !res.Passed() {
os.Exit(1)
}
}()
flynnrc = args.Flynnrc
routerIP = args.RouterIP
if flynnrc == "" {
c := cluster.New(args.BootConfig, os.Stdout)
var rootFS string
rootFS, err = c.BuildFlynn(args.RootFS, "origin/master", false, false)
if err != nil {
if args.Kill {
c.Shutdown()
}
log.Println("could not build flynn: ", err)
if rootFS != "" {
os.RemoveAll(rootFS)
}
return
}
if args.BuildRootFS {
c.Shutdown()
fmt.Println("Built Flynn in rootfs:", rootFS)
return
} else {
defer os.RemoveAll(rootFS)
}
if _, err = c.Boot(cluster.ClusterTypeDefault, 3, nil, args.Kill); err != nil {
log.Println("could not boot cluster: ", err)
return
}
if args.Kill {
defer c.Shutdown()
}
if err = createFlynnrc(c); err != nil {
log.Println(err)
return
}
defer os.RemoveAll(flynnrc)
routerIP = c.RouterIP
}
if args.ClusterAPI != "" {
testCluster, err = testcluster.NewClient(args.ClusterAPI)
if err != nil {
log.Println(err)
return
}
}
res = check.RunAll(&check.RunConf{
Filter: args.Run,
Stream: args.Stream,
Verbose: args.Debug,
KeepWorkDir: args.Debug,
ConcurrencyLevel: args.Concurrency,
})
fmt.Println(res)
}