forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container.go
95 lines (79 loc) · 2.07 KB
/
container.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
package db
import (
"fmt"
"time"
"github.com/concourse/atc"
)
type ContainerIdentifier struct {
// if it's a resource check container
ResourceID int
ResourceTypeVersion atc.Version
CheckType string
CheckSource atc.Source
// if it's a step container
BuildID int
PlanID atc.PlanID
// for the check + get stages of a container with a resource backed image
ImageResourceType string
ImageResourceSource atc.Source
Stage ContainerStage
}
// ContainerStage is used to distinguish between the 3 potential containers in use by a
// step, as we'll need to run a 'check' and 'get' for the image used by the
// container, which themselves correspond to containers.
type ContainerStage string
const (
ContainerStageCheck = "check"
ContainerStageGet = "get"
ContainerStageRun = "run"
)
type ContainerMetadata struct {
Handle string
WorkerName string
BuildName string
ResourceName string
PipelineID int
PipelineName string
TeamID int
JobName string
StepName string
Type ContainerType
WorkingDirectory string
EnvironmentVariables []string
Attempts []int
User string
}
type Container struct {
ContainerIdentifier
ContainerMetadata
}
type SavedContainer struct {
Container
TTL time.Duration
ExpiresIn time.Duration
ID int
}
type ContainerType string
func (containerType ContainerType) String() string {
return string(containerType)
}
func ContainerTypeFromString(containerType string) (ContainerType, error) {
switch containerType {
case "check":
return ContainerTypeCheck, nil
case "get":
return ContainerTypeGet, nil
case "put":
return ContainerTypePut, nil
case "task":
return ContainerTypeTask, nil
default:
return "", fmt.Errorf("Unrecognized containerType: %s", containerType)
}
}
const (
ContainerTypeCheck ContainerType = "check"
ContainerTypeGet ContainerType = "get"
ContainerTypePut ContainerType = "put"
ContainerTypeTask ContainerType = "task"
)