當前位置: 首頁>>代碼示例>>Golang>>正文


Golang parser.Node類代碼示例

本文整理匯總了Golang中github.com/drone/drone-exec/parser.Node的典型用法代碼示例。如果您正苦於以下問題:Golang Node類的具體用法?Golang Node怎麽用?Golang Node使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Node類的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類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。