当前位置: 首页>>代码示例>>Golang>>正文


Golang Node.Type方法代码示例

本文整理汇总了Golang中github.com/drone/drone-exec/parser.Node.Type方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.Type方法的具体用法?Golang Node.Type怎么用?Golang Node.Type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/drone/drone-exec/parser.Node的用法示例。


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

示例1: walk

func (b *Build) walk(node parser.Node, state *State) (err error) {

	switch node := node.(type) {
	case *parser.ListNode:
		for _, node := range node.Nodes {
			err = b.walk(node, state)
			if err != nil {
				break
			}
		}

	case *parser.FilterNode:
		if isMatch(node, state) {
			b.walk(node.Node, state)
		}

	case *parser.DockerNode:
		if shouldSkip(b.flags, node.NodeType) {
			break
		}
		if len(node.Image) == 0 {
			break
		}

		switch node.Type() {

		case parser.NodeBuild:
			// run setup
			// node.Vargs = map[string]interface{}{}
			// node.Vargs["commands"] = node.Commands

			// conf := toContainerConfig(node)
			// conf.Cmd = toCommand(state, node)
			// conf.Image = "plugins/drone-build"
			// info, err := docker.Run(state.Client, conf, node.Pull)
			// if err != nil {
			// 	state.Exit(255)
			// } else if info.State.ExitCode != 0 {
			// 	state.Exit(info.State.ExitCode)
			// }

			// run build
			// conf := toContainerConfig(node)
			// conf.Entrypoint = []string{"/bin/sh", "-e"}
			// conf.Cmd = []string{"/drone/bin/build.sh"}

			conf := toContainerConfig(node)
			conf.Env = append(conf.Env, toEnv(state)...)
			conf.WorkingDir = state.Workspace.Path
			// conf.User = "root"
			if state.Repo.IsPrivate {
				script.Encode(state.Workspace, conf, node)
			} else {
				script.Encode(nil, conf, node)
			}

			info, err := docker.Run(state.Client, conf, node.Pull)
			if err != nil {
				state.Exit(255)
			} else if info.State.ExitCode != 0 {
				state.Exit(info.State.ExitCode)
			}

		case parser.NodeCompose:
			conf := toContainerConfig(node)
			_, err := docker.Start(state.Client, conf, node.Pull)
			if err != nil {
				state.Exit(255)
			}

		default:
			conf := toContainerConfig(node)
			conf.Cmd = toCommand(state, node)
			info, err := docker.Run(state.Client, conf, node.Pull)
			if err != nil {
				state.Exit(255)
			} else if info.State.ExitCode != 0 {
				state.Exit(info.State.ExitCode)
			}
		}
	}

	return nil
}
开发者ID:sourcegraph,项目名称:drone-exec,代码行数:84,代码来源:build.go

示例2: walk

func (b *Build) walk(node parser.Node, state *State) (err error) {

	switch node := node.(type) {
	case *parser.ListNode:
		for _, node := range node.Nodes {
			err = b.walk(node, state)
			if err != nil {
				break
			}
		}

	case *parser.FilterNode:
		if isMatch(node, state) {
			b.walk(node.Node, state)
		}

	case *parser.DockerNode:
		if shouldSkip(b.flags, node.NodeType) {
			break
		}
		if len(node.Image) == 0 {
			break
		}
		// auth for accessing private docker registries
		var auth *dockerclient.AuthConfig
		// auth to nil if password or token not set
		if len(node.AuthConfig.Password) != 0 || len(node.AuthConfig.RegistryToken) != 0 {
			auth = &dockerclient.AuthConfig{
				Username:      node.AuthConfig.Username,
				Password:      node.AuthConfig.Password,
				Email:         node.AuthConfig.Email,
				RegistryToken: node.AuthConfig.RegistryToken,
			}
		}
		switch node.Type() {

		case parser.NodeBuild:
			// TODO(bradrydzewski) this should be handled by the when block
			// by defaulting the build steps to run when not failure. This is
			// required now that we support multi-build steps.
			if state.Failed() {
				return
			}

			conf := toContainerConfig(node)
			conf.Env = append(conf.Env, toEnv(state)...)
			conf.WorkingDir = state.Workspace.Path
			if state.Repo.IsPrivate {
				script.Encode(state.Workspace, conf, node)
			} else {
				script.Encode(nil, conf, node)
			}

			info, err := docker.Run(state.Client, conf, auth, node.Pull, state.Stdout, state.Stderr)
			if err != nil {
				state.Exit(255)
			} else if info.State.ExitCode != 0 {
				state.Exit(info.State.ExitCode)
			}

		case parser.NodeCompose:
			conf := toContainerConfig(node)
			_, err := docker.Start(state.Client, conf, auth, node.Pull)
			if err != nil {
				state.Exit(255)
			}

		default:
			conf := toContainerConfig(node)
			conf.Cmd = toCommand(state, node)
			info, err := docker.Run(state.Client, conf, auth, node.Pull, state.Stdout, state.Stderr)
			if err != nil {
				state.Exit(255)
			} else if info.State.ExitCode != 0 {
				state.Exit(info.State.ExitCode)
			}
		}
	}

	return nil
}
开发者ID:objectpartners,项目名称:drone-exec,代码行数:81,代码来源:build.go

示例3: walk

func (b *Build) walk(node parser.Node, state *State) (err error) {

	switch node := node.(type) {
	case *parser.ListNode:
		for _, node := range node.Nodes {
			err = b.walk(node, state)
			if err != nil {
				break
			}
		}

	case *parser.FilterNode:
		if isMatch(node, state) {
			b.walk(node.Node, state)
		}

	case *parser.DockerNode:
		if shouldSkip(b.flags, node.NodeType) {
			break
		}
		if len(node.Image) == 0 {
			break
		}
		// auth for accessing private docker registries
		var auth *dockerclient.AuthConfig
		// auth to nil if password or token not set
		if len(node.AuthConfig.Password) != 0 || len(node.AuthConfig.RegistryToken) != 0 {
			auth = &dockerclient.AuthConfig{
				Username:      node.AuthConfig.Username,
				Password:      node.AuthConfig.Password,
				Email:         node.AuthConfig.Email,
				RegistryToken: node.AuthConfig.RegistryToken,
			}
		}
		switch node.Type() {

		case parser.NodeBuild:
			// run setup
			// node.Vargs = map[string]interface{}{}
			// node.Vargs["commands"] = node.Commands

			// conf := toContainerConfig(node)
			// conf.Cmd = toCommand(state, node)
			// conf.Image = "plugins/drone-build"
			// info, err := docker.Run(state.Client, conf, node.Pull)
			// if err != nil {
			// 	state.Exit(255)
			// } else if info.State.ExitCode != 0 {
			// 	state.Exit(info.State.ExitCode)
			// }

			// run build
			// conf := toContainerConfig(node)
			// conf.Entrypoint = []string{"/bin/sh", "-e"}
			// conf.Cmd = []string{"/drone/bin/build.sh"}

			conf := toContainerConfig(node)
			conf.Env = append(conf.Env, toEnv(state)...)
			conf.WorkingDir = state.Workspace.Path
			// conf.User = "root"
			if state.Repo.IsPrivate {
				script.Encode(state.Workspace, conf, node)
			} else {
				script.Encode(nil, conf, node)
			}

			info, err := docker.Run(state.Client, conf, auth, node.Pull, state.Stdout, state.Stderr)
			if err != nil {
				state.Exit(255)
			} else if info.State.ExitCode != 0 {
				state.Exit(info.State.ExitCode)
			}

		case parser.NodeCompose:
			conf := toContainerConfig(node)
			_, err := docker.Start(state.Client, conf, auth, node.Pull)
			if err != nil {
				state.Exit(255)
			}

		default:
			conf := toContainerConfig(node)
			conf.Cmd = toCommand(state, node)
			info, err := docker.Run(state.Client, conf, auth, node.Pull, state.Stdout, state.Stderr)
			if err != nil {
				state.Exit(255)
			} else if info.State.ExitCode != 0 {
				state.Exit(info.State.ExitCode)
			}
		}
	}

	return nil
}
开发者ID:msteinert,项目名称:drone-exec,代码行数:94,代码来源:build.go

示例4: walk

func (b *Build) walk(node parser.Node, state *State) (err error) {

	switch node := node.(type) {
	case *parser.ListNode:
		for _, node := range node.Nodes {
			err = b.walk(node, state)
			if err != nil {
				break
			}
		}

	case *parser.FilterNode:
		if isMatch(node, state) {
			b.walk(node.Node, state)
		}

	case *parser.DockerNode:
		if shouldSkip(b.flags, node.NodeType) {
			break
		}
		if len(node.Image) == 0 {
			break
		}
		// auth for accessing private docker registries
		var auth *dockerclient.AuthConfig
		// auth to nil if password or token not set
		if len(node.AuthConfig.Password) != 0 || len(node.AuthConfig.RegistryToken) != 0 {
			auth = &dockerclient.AuthConfig{
				Username:      node.AuthConfig.Username,
				Password:      node.AuthConfig.Password,
				Email:         node.AuthConfig.Email,
				RegistryToken: node.AuthConfig.RegistryToken,
			}
		}
		switch node.Type() {

		case parser.NodeBuild:
			// TODO(bradrydzewski) this should be handled by the when block
			// by defaulting the build steps to run when not failure. This is
			// required now that we support multi-build steps.
			if state.Failed() {
				return
			}

			conf := toContainerConfig(node)
			conf.Env = append(conf.Env, toEnv(state)...)
			conf.WorkingDir = state.Workspace.Path
			if state.Repo.IsPrivate {
				script.Encode(state.Workspace, conf, node)
			} else {
				script.Encode(nil, conf, node)
			}

			info, err := docker.Run(state.Client, conf, auth, node.Pull, state.Stdout, state.Stderr)
			if err != nil {
				state.Exit(255)
			} else if info.State.ExitCode != 0 {
				state.Exit(info.State.ExitCode)
			} else if info.State.OOMKilled && !node.OomKillDisable {
				// NOTE: we suppress this message if OomKillDisable is enabled
				// because older versions of Docker 1.7 are firing false positivies.
				log.Errorln("OOMKill received. Exiting Build")
				state.Exit(1)
			} else if info.State.Running {
				log.Errorln("Error decoding Docker logs. Exiting Build.")
				state.Exit(1)
			}

		case parser.NodeCompose:
			conf := toContainerConfig(node)
			_, err := docker.Start(state.Client, conf, auth, node.Pull)
			if err != nil {
				state.Exit(255)
			}

		default:
			// TODO(bradrydzewski) this should be handled by the when block
			// by defaulting the build steps to run when not failure. This is
			// required now that we support multi-build steps.
			//
			// Note we should always send notifications regardless of the
			// build status, since people typically want failure notifications.
			if state.Failed() && node.Type() != parser.NodeNotify {
				return
			}

			conf := toContainerConfig(node)
			conf.Cmd = toCommand(state, node)
			info, err := docker.Run(state.Client, conf, auth, node.Pull, state.Stdout, state.Stderr)
			if err != nil {
				state.Exit(255)
			} else if info.State.ExitCode != 0 {
				state.Exit(info.State.ExitCode)
			}
		}
	}

	return nil
}
开发者ID:jackspirou,项目名称:drone-exec,代码行数:99,代码来源:build.go


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