@@ -27,7 +27,8 @@ type Manifest2822Entry struct {
27
27
28
28
Maintainers []string `delim:"," strip:"\n\r\t "`
29
29
30
- Tags []string `delim:"," strip:"\n\r\t "`
30
+ Tags []string `delim:"," strip:"\n\r\t "`
31
+ SharedTags []string `delim:"," strip:"\n\r\t "`
31
32
32
33
GitRepo string
33
34
GitFetch string
@@ -46,6 +47,7 @@ func (entry Manifest2822Entry) Clone() Manifest2822Entry {
46
47
// SLICES! grr
47
48
entry .Maintainers = append ([]string {}, entry .Maintainers ... )
48
49
entry .Tags = append ([]string {}, entry .Tags ... )
50
+ entry .SharedTags = append ([]string {}, entry .SharedTags ... )
49
51
entry .Constraints = append ([]string {}, entry .Constraints ... )
50
52
return entry
51
53
}
@@ -60,6 +62,10 @@ func (entry Manifest2822Entry) TagsString() string {
60
62
return strings .Join (entry .Tags , StringSeparator2822 )
61
63
}
62
64
65
+ func (entry Manifest2822Entry ) SharedTagsString () string {
66
+ return strings .Join (entry .SharedTags , StringSeparator2822 )
67
+ }
68
+
63
69
func (entry Manifest2822Entry ) ConstraintsString () string {
64
70
return strings .Join (entry .Constraints , StringSeparator2822 )
65
71
}
@@ -77,6 +83,9 @@ func (entry Manifest2822Entry) ClearDefaults(defaults Manifest2822Entry) Manifes
77
83
if entry .TagsString () == defaults .TagsString () {
78
84
entry .Tags = nil
79
85
}
86
+ if entry .SharedTagsString () == defaults .SharedTagsString () {
87
+ entry .SharedTags = nil
88
+ }
80
89
if entry .GitRepo == defaults .GitRepo {
81
90
entry .GitRepo = ""
82
91
}
@@ -103,6 +112,9 @@ func (entry Manifest2822Entry) String() string {
103
112
if str := entry .TagsString (); str != "" {
104
113
ret = append (ret , "Tags: " + str )
105
114
}
115
+ if str := entry .SharedTagsString (); str != "" {
116
+ ret = append (ret , "SharedTags: " + str )
117
+ }
106
118
if str := entry .GitRepo ; str != "" {
107
119
ret = append (ret , "GitRepo: " + str )
108
120
}
@@ -145,6 +157,16 @@ func (entry Manifest2822Entry) HasTag(tag string) bool {
145
157
return false
146
158
}
147
159
160
+ // HasSharedTag returns true if the given tag exists in entry.SharedTags.
161
+ func (entry Manifest2822Entry ) HasSharedTag (tag string ) bool {
162
+ for _ , existingTag := range entry .SharedTags {
163
+ if tag == existingTag {
164
+ return true
165
+ }
166
+ }
167
+ return false
168
+ }
169
+
148
170
func (manifest Manifest2822 ) GetTag (tag string ) * Manifest2822Entry {
149
171
for _ , entry := range manifest .Entries {
150
172
if entry .HasTag (tag ) {
@@ -154,6 +176,27 @@ func (manifest Manifest2822) GetTag(tag string) *Manifest2822Entry {
154
176
return nil
155
177
}
156
178
179
+ // GetSharedTag returns a list of entries with the given tag in entry.SharedTags (or the empty list if there are no entries with the given tag).
180
+ func (manifest Manifest2822 ) GetSharedTag (tag string ) []Manifest2822Entry {
181
+ ret := []Manifest2822Entry {}
182
+ for _ , entry := range manifest .Entries {
183
+ if entry .HasSharedTag (tag ) {
184
+ ret = append (ret , entry )
185
+ }
186
+ }
187
+ return ret
188
+ }
189
+
190
+ // GetAllSharedTags returns a list of the sum of all SharedTags in all entries of this image manifest (in the order they appear in the file).
191
+ func (manifest Manifest2822 ) GetAllSharedTags () []string {
192
+ fakeEntry := Manifest2822Entry {}
193
+ for _ , entry := range manifest .Entries {
194
+ fakeEntry .SharedTags = append (fakeEntry .SharedTags , entry .SharedTags ... )
195
+ }
196
+ fakeEntry .DeduplicateSharedTags ()
197
+ return fakeEntry .SharedTags
198
+ }
199
+
157
200
func (manifest * Manifest2822 ) AddEntry (entry Manifest2822Entry ) error {
158
201
if len (entry .Tags ) < 1 {
159
202
return fmt .Errorf ("missing Tags" )
@@ -165,20 +208,36 @@ func (manifest *Manifest2822) AddEntry(entry Manifest2822Entry) error {
165
208
return fmt .Errorf ("Tags %q has invalid Maintainers: %q (expected format %q)" , strings .Join (invalidMaintainers , ", " ), MaintainersFormat )
166
209
}
167
210
211
+ entry .DeduplicateSharedTags ()
212
+
168
213
seenTag := map [string ]bool {}
169
214
for _ , tag := range entry .Tags {
170
215
if otherEntry := manifest .GetTag (tag ); otherEntry != nil {
171
216
return fmt .Errorf ("Tags %q includes duplicate tag: %q (duplicated in %q)" , entry .TagsString (), tag , otherEntry .TagsString ())
172
217
}
218
+ if otherEntries := manifest .GetSharedTag (tag ); len (otherEntries ) > 0 {
219
+ return fmt .Errorf ("Tags %q includes tag conflicting with a shared tag: %q (shared tag in %q)" , entry .TagsString (), tag , otherEntries [0 ].TagsString ())
220
+ }
173
221
if seenTag [tag ] {
174
222
return fmt .Errorf ("Tags %q includes duplicate tag: %q" , entry .TagsString (), tag )
175
223
}
176
224
seenTag [tag ] = true
177
225
}
226
+ for _ , tag := range entry .SharedTags {
227
+ if otherEntry := manifest .GetTag (tag ); otherEntry != nil {
228
+ return fmt .Errorf ("Tags %q includes conflicting shared tag: %q (duplicated in %q)" , entry .TagsString (), tag , otherEntry .TagsString ())
229
+ }
230
+ if seenTag [tag ] {
231
+ return fmt .Errorf ("Tags %q includes duplicate tag: %q (in SharedTags)" , entry .TagsString (), tag )
232
+ }
233
+ seenTag [tag ] = true
234
+ }
178
235
179
236
for i , existingEntry := range manifest .Entries {
180
237
if existingEntry .SameBuildArtifacts (entry ) {
181
238
manifest .Entries [i ].Tags = append (existingEntry .Tags , entry .Tags ... )
239
+ manifest .Entries [i ].SharedTags = append (existingEntry .SharedTags , entry .SharedTags ... )
240
+ manifest .Entries [i ].DeduplicateSharedTags ()
182
241
return nil
183
242
}
184
243
}
@@ -210,6 +269,20 @@ func (entry Manifest2822Entry) InvalidMaintainers() []string {
210
269
return invalid
211
270
}
212
271
272
+ // DeduplicateSharedTags will remove duplicate values from entry.SharedTags, preserving order.
273
+ func (entry * Manifest2822Entry ) DeduplicateSharedTags () {
274
+ aggregate := []string {}
275
+ seen := map [string ]bool {}
276
+ for _ , tag := range entry .SharedTags {
277
+ if seen [tag ] {
278
+ continue
279
+ }
280
+ seen [tag ] = true
281
+ aggregate = append (aggregate , tag )
282
+ }
283
+ entry .SharedTags = aggregate
284
+ }
285
+
213
286
type decoderWrapper struct {
214
287
* control.Decoder
215
288
}
0 commit comments