This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 115
/
container_spec.go
113 lines (91 loc) · 2.61 KB
/
container_spec.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
package worker
import (
"fmt"
"strings"
"code.cloudfoundry.org/garden"
"github.com/concourse/atc"
"github.com/concourse/atc/creds"
)
type WorkerSpec struct {
Platform string
ResourceType string
Tags []string
TeamID int
}
type ContainerSpec struct {
Platform string
Tags []string
TeamID int
ImageSpec ImageSpec
Env []string
// Working directory for processes run in the container.
Dir string
// Inputs to provide to the container. Inputs with a volume local to the
// selected worker will be made available via a COW volume; others will be
// streamed.
Inputs []InputSource
// Outputs for which volumes should be created and mounted into the container.
Outputs OutputPaths
// Resource limits to be set on the container when creating in garden.
Limits ContainerLimits
// Local volumes to bind mount directly to the container when creating in garden.
BindMounts []BindMountSource
// Optional user to run processes as. Overwrites the one specified in the docker image.
User string
}
// OutputPaths is a mapping from output name to its path in the container.
type OutputPaths map[string]string
type ImageSpec struct {
ResourceType string
ImageURL string
ImageResource *ImageResource
ImageArtifactSource ArtifactSource
ImageArtifactName ArtifactName
Privileged bool
}
type ImageResource struct {
Type string
Source creds.Source
Params *atc.Params
Version *atc.Version
}
type ContainerLimits struct {
CPU *uint64
Memory *uint64
}
var GardenLimitDefault = uint64(0)
func (cl ContainerLimits) ToGardenLimits() garden.Limits {
gardenLimits := garden.Limits{}
if cl.CPU == nil {
gardenLimits.CPU = garden.CPULimits{LimitInShares: GardenLimitDefault}
} else {
gardenLimits.CPU = garden.CPULimits{LimitInShares: *cl.CPU}
}
if cl.Memory == nil {
gardenLimits.Memory = garden.MemoryLimits{LimitInBytes: GardenLimitDefault}
} else {
gardenLimits.Memory = garden.MemoryLimits{LimitInBytes: *cl.Memory}
}
return gardenLimits
}
func (spec ContainerSpec) WorkerSpec() WorkerSpec {
return WorkerSpec{
ResourceType: spec.ImageSpec.ResourceType,
Platform: spec.Platform,
Tags: spec.Tags,
TeamID: spec.TeamID,
}
}
func (spec WorkerSpec) Description() string {
var attrs []string
if spec.ResourceType != "" {
attrs = append(attrs, fmt.Sprintf("resource type '%s'", spec.ResourceType))
}
if spec.Platform != "" {
attrs = append(attrs, fmt.Sprintf("platform '%s'", spec.Platform))
}
for _, tag := range spec.Tags {
attrs = append(attrs, fmt.Sprintf("tag '%s'", tag))
}
return strings.Join(attrs, ", ")
}