• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang core.Sous类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/opentable/sous/core.Sous的典型用法代码示例。如果您正苦于以下问题:Golang Sous类的具体用法?Golang Sous怎么用?Golang Sous使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Sous类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Stamp

func Stamp(sous *core.Sous, args []string) {
	target := "app"
	if len(args) == 0 {
		cli.Fatalf("sous stamp requires at least one argument (a docker label)")
	}
	_, context := sous.AssembleTargetContext(target)
	if context.BuildNumber() == 0 {
		cli.Fatalf("no builds yet; sous stamp operates on your last successful build of the app target")
	}

	tag := context.DockerTag()
	run := docker.NewRun(tag)
	run.AddLabels(parseLabels(args))
	run.StdoutFile = "/dev/null"
	run.StderrFile = "/dev/null"
	container, err := run.Background().Start()
	if err != nil {
		cli.Fatalf("Failed to start container for labeling: %s", err)
	}
	if err := container.KillIfRunning(); err != nil {
		cli.Fatalf("Failed to kill labelling container %s: %s", container, err)
	}
	cid := container.CID()
	if err := docker.Commit(cid, tag); err != nil {
		cli.Fatalf("Failed to commit labelled container %s: %s", container, err)
	}
	cli.Successf("Successfully added labels to %s; remember to push.", tag)
}
开发者ID:liamjbennett,项目名称:sous,代码行数:28,代码来源:stamp.go


示例2: Contracts

func Contracts(sous *core.Sous, args []string) {
	contractsFlags.Parse(args)
	args = contractsFlags.Args()
	timeout := *timeoutFlag
	targetName := "app"
	if len(args) != 0 {
		targetName = args[0]
	}
	core.RequireGit()
	core.RequireDocker()

	if *dockerImage != "" {
		cli.Fatalf("-image flag not yet implemented")
	}

	target, context := sous.AssembleTargetContext(targetName)

	sous.RunTarget(target, context)

	cli.Logf("=> Running Contracts")
	cli.Logf(`=> **TIP:** Open another terminal in this directory and type **sous logs -f**`)

	taskHost := core.DivineTaskHost()
	port0, err := ports.GetFreePort()
	if err != nil {
		cli.Fatalf("Unable to get free port: %s", err)
	}

	dr := docker.NewRun(context.DockerTag())
	dr.AddEnv("PORT0", strconv.Itoa(port0))
	dr.AddEnv("TASK_HOST", taskHost)
	dr.StdoutFile = context.FilePath("stdout")
	dr.StderrFile = context.FilePath("stderr")
	container, err := dr.Background().Start()
	if err != nil {
		cli.Fatalf("Unable to start container: %s", err)
	}
	cli.AddCleanupTask(func() error {
		return container.KillIfRunning()
	})

	failed := 0
	for _, c := range theContracts {
		cli.Logf(`===> CHECKING CONTRACT: "%s"`, c.Name)
		cli.Logf(`===> Description: %s`, c.Desc(dr))
		if c.Tips != nil {
			cli.Logf("===> **TIPS for this contract:**")
			cli.LogBulletList("     -", c.Tips(dr))
		}
		failed += within(timeout, func() bool {
			return c.Premise(dr)
		})
	}

	if failed != 0 {
		cli.Fatalf("%d contracts failed.", failed)
	}

	cli.Success()
}
开发者ID:liamjbennett,项目名称:sous,代码行数:60,代码来源:_contracts.go


示例3: BuildPath

func BuildPath(sous *core.Sous, args []string) {
	target := "app"
	if len(args) != 0 {
		target = args[0]
	}
	_, context := sous.AssembleTargetContext(target)
	fmt.Println(path.Resolve(path.BaseDir(context.BaseDir())))
	cli.Success()
}
开发者ID:liamjbennett,项目名称:sous,代码行数:9,代码来源:buildpath.go


示例4: Dockerfile

func Dockerfile(sous *core.Sous, args []string) {
	targetName := "app"
	if len(args) != 0 {
		targetName = args[0]
	}
	target, context := sous.AssembleTargetContext(targetName)
	cli.Outf(sous.Dockerfile(target, context).Render())
	cli.Success()
}
开发者ID:liamjbennett,项目名称:sous,代码行数:9,代码来源:dockerfile.go


示例5: Clean

func Clean(sous *core.Sous, args []string) {
	_, context := sous.AssembleTargetContext("app")
	cleanContainersSucceeded := cleanContainers(sous, context)
	cleanImagesSucceeded := cleanImages(sous, context)
	if cleanContainersSucceeded && cleanImagesSucceeded {
		cli.Success()
	}
	cli.Fatal()
}
开发者ID:liamjbennett,项目名称:sous,代码行数:9,代码来源:clean.go


示例6: Image

func Image(sous *core.Sous, args []string) {
	target := "app"
	if len(args) != 0 {
		target = args[0]
	}
	_, context := sous.AssembleTargetContext(target)
	if context.BuildNumber() == 0 {
		cli.Fatalf("no builds yet")
	}
	cli.Outf(context.DockerTag())
	cli.Success()
}
开发者ID:liamjbennett,项目名称:sous,代码行数:12,代码来源:image.go


示例7: cleanContainers

func cleanContainers(sous *core.Sous, context *core.Context) bool {
	success := true
	for _, c := range sous.LsContainers(context) {
		if err := c.ForceRemove(); err != nil {
			cli.Logf("Failed to remove container %s (%s)", c.Name(), c.CID())
			success = false
		} else {
			cli.Logf("Removed container %s (%s)", c.Name(), c.CID())
		}
	}
	return success
}
开发者ID:liamjbennett,项目名称:sous,代码行数:12,代码来源:clean.go


示例8: cleanImages

func cleanImages(sous *core.Sous, context *core.Context) bool {
	success := true
	for _, i := range sous.LsImages(context) {
		if err := i.Remove(); err != nil {
			cli.Logf("Failed to remove image %s:%s", i.Name, i.Tag)
			success = false
		} else {
			cli.Logf("Removed image %s:%s", i.Name, i.Tag)
		}
	}
	return success
}
开发者ID:liamjbennett,项目名称:sous,代码行数:12,代码来源:clean.go


示例9: Logs

func Logs(sous *core.Sous, args []string) {
	logsFlags.Parse(args)
	args = logsFlags.Args()
	target := "app"
	if len(args) != 0 {
		target = args[0]
	}
	_, context := sous.AssembleTargetContext(target)

	out := makeTail(context.FilePath("stdout"), *follow, *lines, os.Stdout)
	err := makeTail(context.FilePath("stderr"), *follow, *lines, os.Stderr)

	if err := out.Start(); err != nil {
		cli.Fatalf("Unable to begin tailing %s", context.FilePath("stdout"))
	}
	if err := err.Start(); err != nil {
		cli.Fatalf("Unable to begin tailing %s", context.FilePath("stderr"))
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, syscall.SIGTERM)

	if *follow {
		<-c
		out.Process.Signal(os.Interrupt)
		err.Process.Signal(os.Interrupt)
	}

	errs := []string{}
	if err := out.Wait(); err != nil {
		errs = append(errs, err.Error())
	}
	if err := err.Wait(); err != nil {
		errs = append(errs, err.Error())
	}
	if !*follow {
		if len(errs) != 0 {
			cli.Fatalf("Done with errors: %s", strings.Join(errs, ", "))
		}
	}
	cli.Success()
}
开发者ID:liamjbennett,项目名称:sous,代码行数:42,代码来源:logs.go


示例10: Push

func Push(sous *core.Sous, args []string) {
	target := "app"
	if len(args) != 0 {
		target = args[0]
	}
	core.RequireGit()
	core.RequireDocker()
	if err := git.AssertCleanWorkingTree(); err != nil {
		cli.Warn("Dirty working tree: %s", err)
	}

	_, context := sous.AssembleTargetContext(target)

	tag := context.DockerTag()
	if !docker.ImageExists(tag) {
		cli.Fatalf("No built image available; try building first")
	}
	docker.Push(tag)
	name := context.CanonicalPackageName()
	cli.Successf("Successfully pushed %s v%s as %s", name, context.BuildVersion, context.DockerTag())
}
开发者ID:liamjbennett,项目名称:sous,代码行数:21,代码来源:push.go


示例11: Ls

func Ls(sous *core.Sous, args []string) {
	//globalFlag := lsFlags.Bool("g", false, "global: list files in all projects sous has built")
	//lsFlags.Parse(args)
	//global := *globalFlag
	args = lsFlags.Args()
	if len(args) != 0 {
		cli.Fatalf("sous ls does not accept any arguments")
	}
	_, context := sous.AssembleTargetContext("app")
	cli.Outf(" ===> Images")
	images := sous.LsImages(context)
	if len(images) == 0 {
		cli.Logf("  no images for this project")
	}
	for _, image := range images {
		cli.Logf("  %s:%s", image.Name, image.Tag)
	}
	cli.Outf(" ===> Containers")
	containers := sous.LsContainers(context)
	if len(containers) == 0 {
		cli.Logf("  no containers for this project")
	}
	for _, container := range containers {
		cli.Logf("  %s (%s)", container.Name(), container.CID())
	}
	cli.Success()
}
开发者ID:liamjbennett,项目名称:sous,代码行数:27,代码来源:ls.go


示例12: Build

func Build(sous *core.Sous, args []string) {
	targetName := "app"
	if len(args) != 0 {
		targetName = args[0]
	}
	core.RequireGit()
	core.RequireDocker()
	if err := git.AssertCleanWorkingTree(); err != nil {
		cli.Warn("Dirty working tree: %s", err)
	}

	target, context := sous.AssembleTargetContext(targetName)

	built, _ := sous.RunTarget(target, context)

	if !built {
		cli.Successf("Already built: %s", context.DockerTag())
	}

	name := context.CanonicalPackageName()
	cli.Successf("Successfully built %s v%s as %s", name, context.BuildVersion, context.DockerTag())
}
开发者ID:liamjbennett,项目名称:sous,代码行数:22,代码来源:build.go


示例13: Run

func Run(sous *core.Sous, args []string) {
	targetName := "app"
	if len(args) != 0 {
		targetName = args[0]
	}
	core.RequireGit()
	core.RequireDocker()

	target, context := sous.AssembleTargetContext(targetName)
	runner, ok := target.(core.ContainerTarget)
	if !ok {
		cli.Fatalf("Target %s does not support running.", target.Name())
	}

	rebuilt, _ := sous.RunTarget(target, context)
	dr, _ := sous.RunContainerTarget(runner, context, rebuilt)
	if exitCode := dr.ExitCode(); exitCode != 0 {
		cli.Logf("Docker container exited with code %d", exitCode)
		cli.Exit(exitCode)
	}
	cli.Success()
}
开发者ID:liamjbennett,项目名称:sous,代码行数:22,代码来源:run.go



注:本文中的github.com/opentable/sous/core.Sous类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang cli.Fatalf函数代码示例发布时间:2022-05-28
下一篇:
Golang core.Context类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap