forked from vmware-archive/fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builds.go
130 lines (109 loc) · 2.61 KB
/
builds.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
130
package executehelpers
import (
"time"
"github.com/concourse/atc"
"github.com/concourse/fly/rc"
"github.com/concourse/go-concourse/concourse"
)
func CreateBuild(
client concourse.Client,
privileged bool,
inputs []Input,
outputs []Output,
config atc.TaskConfig,
tags []string,
targetName rc.TargetName,
) (atc.Build, error) {
fact := atc.NewPlanFactory(time.Now().Unix())
if err := config.Validate(); err != nil {
return atc.Build{}, err
}
target, err := rc.LoadTarget(targetName)
if err != nil {
return atc.Build{}, err
}
buildInputs := atc.AggregatePlan{}
for _, input := range inputs {
var getPlan atc.GetPlan
if input.Path != "" {
source := atc.Source{
"uri": input.Pipe.ReadURL,
}
if target.CACert() != "" {
source["ca_cert"] = target.CACert()
}
tlsconfig := target.TLSConfig()
if tlsconfig != nil && tlsconfig.InsecureSkipVerify {
source["skip_ssl_validation"] = true
}
if auth, ok := target.TokenAuthorization(); ok {
source["authorization"] = auth
}
getPlan = atc.GetPlan{
Name: input.Name,
Type: "archive",
Source: source,
}
} else {
version := input.BuildInput.Version
getPlan = atc.GetPlan{
Name: input.Name,
Type: input.BuildInput.Type,
Source: input.BuildInput.Source,
Version: &version,
Params: input.BuildInput.Params,
Tags: input.BuildInput.Tags,
}
}
buildInputs = append(buildInputs, fact.NewPlan(getPlan))
}
taskPlan := fact.NewPlan(atc.TaskPlan{
Name: "one-off",
Privileged: privileged,
Config: &atc.LoadTaskConfig{TaskConfig: &config},
})
if len(tags) != 0 {
taskPlan.Task.Tags = tags
}
buildOutputs := atc.AggregatePlan{}
for _, output := range outputs {
source := atc.Source{
"uri": output.Pipe.ReadURL,
}
params := atc.Params{
"directory": output.Name,
}
if target.CACert() != "" {
source["ca_cert"] = target.CACert()
}
tlsconfig := target.TLSConfig()
if tlsconfig != nil && tlsconfig.InsecureSkipVerify {
source["skip_ssl_validation"] = true
}
if auth, ok := target.TokenAuthorization(); ok {
source["authorization"] = auth
}
buildOutputs = append(buildOutputs, fact.NewPlan(atc.PutPlan{
Name: output.Name,
Type: "archive",
Source: source,
Params: params,
}))
}
var plan atc.Plan
if len(buildOutputs) == 0 {
plan = fact.NewPlan(atc.DoPlan{
fact.NewPlan(buildInputs),
taskPlan,
})
} else {
plan = fact.NewPlan(atc.EnsurePlan{
Step: fact.NewPlan(atc.DoPlan{
fact.NewPlan(buildInputs),
taskPlan,
}),
Next: fact.NewPlan(buildOutputs),
})
}
return client.CreateBuild(plan)
}