8
8
"sort"
9
9
"strings"
10
10
11
+ "github.com/docker-library/go-dockerlibrary/architecture"
11
12
"github.com/docker-library/go-dockerlibrary/pkg/stripper"
12
13
13
14
"pault.ag/go/debian/control"
@@ -364,11 +365,15 @@ func (manifest *Manifest2822) AddEntry(entry Manifest2822Entry) error {
364
365
return fmt .Errorf ("Tags %q missing one of GitRepo, GitFetch, or GitCommit" , entry .TagsString ())
365
366
}
366
367
if invalidMaintainers := entry .InvalidMaintainers (); len (invalidMaintainers ) > 0 {
367
- return fmt .Errorf ("Tags %q has invalid Maintainers: %q (expected format %q)" , strings .Join (invalidMaintainers , ", " ), MaintainersFormat )
368
+ return fmt .Errorf ("Tags %q has invalid Maintainers: %q (expected format %q)" , entry . TagsString (), strings .Join (invalidMaintainers , ", " ), MaintainersFormat )
368
369
}
369
370
370
371
entry .DeduplicateSharedTags ()
371
372
373
+ if invalidArchitectures := entry .InvalidArchitectures (); len (invalidArchitectures ) > 0 {
374
+ return fmt .Errorf ("Tags %q has invalid Architectures: %q" , entry .TagsString (), strings .Join (invalidArchitectures , ", " ))
375
+ }
376
+
372
377
seenTag := map [string ]bool {}
373
378
for _ , tag := range entry .Tags {
374
379
if otherEntry := manifest .GetTag (tag ); otherEntry != nil {
@@ -428,6 +433,16 @@ func (entry Manifest2822Entry) InvalidMaintainers() []string {
428
433
return invalid
429
434
}
430
435
436
+ func (entry Manifest2822Entry ) InvalidArchitectures () []string {
437
+ invalid := []string {}
438
+ for _ , arch := range entry .Architectures {
439
+ if _ , ok := architecture .SupportedArches [arch ]; ! ok {
440
+ invalid = append (invalid , arch )
441
+ }
442
+ }
443
+ return invalid
444
+ }
445
+
431
446
// DeduplicateSharedTags will remove duplicate values from entry.SharedTags, preserving order.
432
447
func (entry * Manifest2822Entry ) DeduplicateSharedTags () {
433
448
aggregate := []string {}
@@ -442,6 +457,21 @@ func (entry *Manifest2822Entry) DeduplicateSharedTags() {
442
457
entry .SharedTags = aggregate
443
458
}
444
459
460
+ // DeduplicateArchitectures will remove duplicate values from entry.Architectures and sort the result.
461
+ func (entry * Manifest2822Entry ) DeduplicateArchitectures () {
462
+ aggregate := []string {}
463
+ seen := map [string ]bool {}
464
+ for _ , arch := range entry .Architectures {
465
+ if seen [arch ] {
466
+ continue
467
+ }
468
+ seen [arch ] = true
469
+ aggregate = append (aggregate , arch )
470
+ }
471
+ sort .Strings (aggregate )
472
+ entry .Architectures = aggregate
473
+ }
474
+
445
475
type decoderWrapper struct {
446
476
* control.Decoder
447
477
}
@@ -471,6 +501,7 @@ func (decoder *decoderWrapper) Decode(entry *Manifest2822Entry) error {
471
501
if len (entry .Architectures ) == 0 {
472
502
entry .Architectures = arches
473
503
}
504
+ entry .DeduplicateArchitectures ()
474
505
475
506
// pull out any new architecture-specific values from Paragraph.Values
476
507
entry .SeedArchValues ()
@@ -504,6 +535,9 @@ func Parse2822(readerIn io.Reader) (*Manifest2822, error) {
504
535
if len (manifest .Global .Tags ) > 0 {
505
536
return nil , fmt .Errorf ("global Tags not permitted" )
506
537
}
538
+ if invalidArchitectures := manifest .Global .InvalidArchitectures (); len (invalidArchitectures ) > 0 {
539
+ return nil , fmt .Errorf ("invalid global Architectures: %q" , strings .Join (invalidArchitectures , ", " ))
540
+ }
507
541
508
542
for {
509
543
entry := manifest .Global .Clone ()
0 commit comments