@@ -15,110 +15,6 @@ const (
15
15
serviceLabel = labelPrefix + ".service"
16
16
)
17
17
18
- var (
19
- errNoContainersMatchingFilters = errors .New ("no containers matching filters" )
20
- errInvalidDockerFilter = errors .New ("invalid docker filter" )
21
- errFailedToListContainers = errors .New ("failed to list containers" )
22
- )
23
-
24
- func parseFilter (filter string ) (key , value string , err error ) {
25
- parts := strings .SplitN (filter , "=" , 2 )
26
- if len (parts ) != 2 {
27
- return "" , "" , errInvalidDockerFilter
28
- }
29
- return parts [0 ], parts [1 ], nil
30
- }
31
-
32
- func getLabels (d * docker.Client , filterFlags []string ) (map [string ]map [string ]string , error ) {
33
- // sleep before querying containers
34
- // because docker not always propagating labels in time
35
- // so ofelia app can't find it's own container
36
- if IsDockerEnv {
37
- time .Sleep (1 * time .Second )
38
- }
39
-
40
- var filters = map [string ][]string {
41
- "label" : {requiredLabelFilter },
42
- }
43
- for _ , f := range filterFlags {
44
- key , value , err := parseFilter (f )
45
- if err != nil {
46
- return nil , fmt .Errorf ("%w: %s" , err , f )
47
- }
48
- filters [key ] = append (filters [key ], value )
49
- }
50
-
51
- conts , err := d .ListContainers (docker.ListContainersOptions {Filters : filters })
52
- if err != nil {
53
- return nil , fmt .Errorf ("%w: %w" , errFailedToListContainers , err )
54
- } else if len (conts ) == 0 {
55
- return nil , fmt .Errorf ("%w: %v" , errNoContainersMatchingFilters , filters )
56
- }
57
-
58
- var labels = make (map [string ]map [string ]string )
59
-
60
- for _ , c := range conts {
61
- if len (c .Names ) > 0 && len (c .Labels ) > 0 {
62
- name := strings .TrimPrefix (c .Names [0 ], "/" )
63
- for k := range c .Labels {
64
- // remove all not relevant labels
65
- if ! strings .HasPrefix (k , labelPrefix ) {
66
- delete (c .Labels , k )
67
- continue
68
- }
69
- }
70
-
71
- labels [name ] = c .Labels
72
- }
73
- }
74
-
75
- return labels , nil
76
- }
77
-
78
- || || || | parent of 992 b1a2 (Applied changes )
79
- func getLabels (d * docker.Client ) (map [string ]map [string ]string , error ) {
80
- // sleep before querying containers
81
- // because docker not always propagating labels in time
82
- // so ofelia app can't find it's own container
83
- if IsDockerEnv {
84
- time .Sleep (1 * time .Second )
85
- }
86
-
87
- conts , err := d .ListContainers (docker.ListContainersOptions {
88
- Filters : map [string ][]string {
89
- "label" : {requiredLabelFilter },
90
- },
91
- })
92
- if err != nil {
93
- return nil , err
94
- }
95
-
96
- if len (conts ) == 0 {
97
- return nil , errors .New ("Couldn't find containers with label 'ofelia.enabled=true'" )
98
- }
99
-
100
- var labels = make (map [string ]map [string ]string )
101
-
102
- for _ , c := range conts {
103
- if len (c .Names ) > 0 && len (c .Labels ) > 0 {
104
- name := strings .TrimPrefix (c .Names [0 ], "/" )
105
- for k := range c .Labels {
106
- // remove all not relevant labels
107
- if ! strings .HasPrefix (k , labelPrefix ) {
108
- delete (c .Labels , k )
109
- continue
110
- }
111
- }
112
-
113
- labels [name ] = c .Labels
114
- }
115
- }
116
-
117
- return labels , nil
118
- }
119
-
120
- == == == =
121
- >> >> >> > 992 b1a2 (Applied changes )
122
18
func (c * Config ) buildFromDockerLabels (labels map [string ]map [string ]string ) error {
123
19
execJobs := make (map [string ]map [string ]interface {})
124
20
localJobs := make (map [string ]map [string ]interface {})
0 commit comments