Repository navigation
Expand file tree
/
Copy pathconfig.go
More file actions
79 lines (69 loc) · 1.52 KB
/
Copy pathconfig.go
File metadata and controls
79 lines (69 loc) · 1.52 KB
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
package main
import (
"strings"
"gopkg.in/yaml.v2"
)
// Parse yml data to produce a Pipeline's Stages data structure
func Parse(source []byte) (Stages, error) {
i = 0
var stages Stages
err := yaml.Unmarshal(source, &stages)
if err != nil {
return nil, err
}
return stages, nil
}
// UnmarshalYAML implements yaml.v2 Unmarshaler interface to set Stage.Name reflecting map's key
func (p *Stages) UnmarshalYAML(unmarshal func(interface{}) error) error {
ps := map[string]Stage{}
if err := unmarshal(&ps); err != nil {
return err
}
for k, s := range ps {
s.Name = k
}
*p = ps
return nil
}
type stageSpec struct {
// Command
Image string
Env map[string]string
Commands []string
Shell string
Cached []string
Workdir string
// Build
Build string
Dockerfile string
ContextPath string
}
var i = 0
// UnmarshalYAML implements yaml.v2 Unmarshaler interface to inject an Order attribute
// while the docker-pipeline yaml file is parsed, as go map isn't ordered (by design).
func (s *Stage) UnmarshalYAML(unmarshal func(interface{}) error) error {
st := stageSpec{}
if err := unmarshal(&st); err != nil {
return err
}
if st.Image != "" {
s.Exec = Command{
Image: st.Image,
Commands: st.Commands,
Shell: st.Shell,
Cached: st.Cached,
Env: st.Env,
Workdir: st.Workdir,
}
}
if st.Build != "" {
s.Exec = Build{
Tags: strings.Split(st.Build, " "),
Dockerfile: st.Dockerfile,
ContextPath: st.ContextPath,
}
}
s.Order = i
i = i + 1
return nil
}