forked from vmware-archive/fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builds.go
111 lines (94 loc) · 2.14 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
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 auth, ok := target.TokenAuthorization(); ok {
source["authorization"] = auth
}
getPlan = atc.GetPlan{
Name: input.Name,
Type: "archive",
Source: source,
}
} else {
getPlan = atc.GetPlan{
Name: input.Name,
Type: input.BuildInput.Type,
Source: input.BuildInput.Source,
Version: input.BuildInput.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: &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 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)
}