forked from donny-dont/drone-exec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
129 lines (111 loc) · 2.73 KB
/
node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package parser
import "github.com/drone/drone-exec/yaml"
// NodeType identifies the type of a parse tree node.
type NodeType uint
// Type returns itself and provides an easy default
// implementation for embedding in a Node. Embedded
// in all non-trivial Nodes.
func (t NodeType) Type() NodeType {
return t
}
const (
NodeList NodeType = 1 << iota
NodeFilter
NodeBuild
NodeCache
NodeClone
NodeDeploy
NodeCompose
NodeNotify
NodePublish
)
// Nodes.
type Node interface {
Type() NodeType
}
// ListNode holds a sequence of nodes.
type ListNode struct {
NodeType
Nodes []Node // nodes executed in lexical order.
}
// Append appends a node to the list.
func (l *ListNode) append(n ...Node) {
l.Nodes = append(l.Nodes, n...)
}
func newListNode() *ListNode {
return &ListNode{NodeType: NodeList}
}
// DockerNode represents a Docker container that
// should be launched as part of the build process.
type DockerNode struct {
NodeType
Image string
Pull bool
Privileged bool
Environment []string
Entrypoint []string
Command []string
Commands []string
Volumes []string
ExtraHosts []string
Net string
AuthConfig yaml.AuthConfig
Memory int64
CPUSetCPUs string
OomKillDisable bool
Vargs map[string]interface{}
}
func newDockerNode(typ NodeType, c yaml.Container) *DockerNode {
return &DockerNode{
NodeType: typ,
Image: c.Image,
Pull: c.Pull,
Privileged: c.Privileged,
Environment: c.Environment.Slice(),
Entrypoint: c.Entrypoint.Slice(),
Command: c.Command.Slice(),
Volumes: c.Volumes,
ExtraHosts: c.ExtraHosts,
Net: c.Net,
AuthConfig: c.AuthConfig,
Memory: c.Memory,
CPUSetCPUs: c.CPUSetCPUs,
OomKillDisable: c.OomKillDisable,
}
}
func newPluginNode(typ NodeType, p yaml.Plugin) *DockerNode {
node := newDockerNode(typ, p.Container)
node.Vargs = p.Vargs
return node
}
func newBuildNode(typ NodeType, b yaml.Build) *DockerNode {
node := newDockerNode(typ, b.Container)
node.Commands = b.Commands
return node
}
// FilterNode represents a conditional step used to
// filter nodes. If conditions are met the child
// node is executed.
type FilterNode struct {
NodeType
Repo string
Branch []string
Event []string
Success string
Failure string
Change string
Matrix map[string]string
Node Node // Node to execution if conditions met
}
func newFilterNode(filter yaml.Filter) *FilterNode {
return &FilterNode{
NodeType: NodeFilter,
Repo: filter.Repo,
Branch: filter.Branch.Slice(),
Event: filter.Event.Slice(),
Matrix: filter.Matrix,
Success: filter.Success,
Failure: filter.Failure,
Change: filter.Change,
}
}