Skip to content

Commit 235f7e4

Browse files
authored
Merge pull request #10 from infosiftr/arches
Add new "Architectures" field
2 parents 61055e4 + d84bfcc commit 235f7e4

File tree

2 files changed

+121
-10
lines changed

2 files changed

+121
-10
lines changed

manifest/example_test.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ func Example() {
1515
1616
Maintainers: InfoSiftr <[email protected]> (@infosiftr),
1717
Johan Euphrosine <[email protected]> (@proppy)
18-
GitRepo: https://github.com/docker-library/golang.git
1918
GitFetch: refs/heads/master
19+
GitRepo: https://github.com/docker-library/golang.git
2020
SharedTags: latest
21+
arm64v8-GitRepo: https://github.com/docker-library/golang.git
2122
2223
2324
# hi
@@ -28,22 +29,34 @@ SharedTags: latest
2829
2930
# Go 1.6
3031
Tags: 1.6.1, 1.6, 1
31-
GitCommit: 0ce80411b9f41e9c3a21fc0a1bffba6ae761825a
32+
arm64v8-GitRepo: https://github.com/docker-library/golang.git
3233
Directory: 1.6
34+
GitCommit: 0ce80411b9f41e9c3a21fc0a1bffba6ae761825a
3335
Constraints: some-random-build-server
3436
3537
3638
# Go 1.5
3739
Tags: 1.5.3
38-
SharedTags: 1.5.3-debian, 1.5-debian
3940
GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
41+
SharedTags: 1.5.3-debian, 1.5-debian
4042
Directory: 1.5
43+
s390x-GitCommit: b6c460e7cd79b595267870a98013ec3078b490df
44+
i386-GitFetch: refs/heads/i386
45+
ppc64le-Directory: 1.5/ppc64le
4146
4247
4348
Tags: 1.5
4449
SharedTags: 1.5-debian
4550
GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
4651
Directory: 1.5
52+
s390x-GitCommit: b6c460e7cd79b595267870a98013ec3078b490df
53+
i386-GitFetch: refs/heads/i386
54+
ppc64le-Directory: 1.5/ppc64le
55+
56+
SharedTags: raspbian
57+
GitCommit: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
58+
Tags: raspbian-s390x
59+
Architectures: s390x
4760
4861
4962
`)))
@@ -84,26 +97,37 @@ i: g@h j
8497
// Maintainers: InfoSiftr <[email protected]> (@infosiftr), Johan Euphrosine <[email protected]> (@proppy)
8598
// SharedTags: latest
8699
// GitRepo: https://github.com/docker-library/golang.git
100+
// arm64v8-GitRepo: https://github.com/docker-library/golang.git
87101
//
88102
// Tags: 1.6.1, 1.6, 1
89103
// GitCommit: 0ce80411b9f41e9c3a21fc0a1bffba6ae761825a
90104
// Directory: 1.6
91105
// Constraints: some-random-build-server
92106
//
93107
// Tags: 1.5.3, 1.5
94-
// SharedTags: latest, 1.5.3-debian, 1.5-debian
108+
// SharedTags: 1.5.3-debian, 1.5-debian
95109
// GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
96110
// Directory: 1.5
111+
// i386-GitFetch: refs/heads/i386
112+
// ppc64le-Directory: 1.5/ppc64le
113+
// s390x-GitCommit: b6c460e7cd79b595267870a98013ec3078b490df
114+
//
115+
// Tags: raspbian-s390x
116+
// SharedTags: raspbian
117+
// Architectures: s390x
118+
// GitCommit: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
97119
//
98120
// Shared Tag Groups:
99121
//
100122
// - latest
101123
// - 1.6.1, 1.6, 1
102-
// - 1.5.3, 1.5
103124
//
104125
// - 1.5.3-debian, 1.5-debian
105126
// - 1.5.3, 1.5
106127
//
128+
// - raspbian
129+
// - raspbian-s390x
130+
//
107131
// -------------
108132
// line-based:
109133
// Maintainers: InfoSiftr <[email protected]> (@infosiftr), John Smith <[email protected]> (@example-jsmith)
@@ -134,15 +158,14 @@ func ExampleFetch_local() {
134158

135159
fmt.Printf("%s:%s\n\n", repoName, tagName)
136160

137-
fmt.Println(man.GetTag(tagName))
161+
fmt.Println(man.GetTag(tagName).ClearDefaults(manifest.DefaultManifestEntry).String())
138162

139163
// Output:
140164
// bash:4.4
141165
//
142166
// Maintainers: Tianon Gravi <[email protected]> (@tianon)
143167
// Tags: 4.4.12, 4.4, 4, latest
144168
// GitRepo: https://github.com/tianon/docker-bash.git
145-
// GitFetch: refs/heads/master
146169
// GitCommit: 1cbb5cf49b4c53bd5a986abf7a1afeb9a80eac1e
147170
// Directory: 4.4
148171
}
@@ -155,15 +178,14 @@ func ExampleFetch_remote() {
155178

156179
fmt.Printf("%s:%s\n\n", repoName, tagName)
157180

158-
fmt.Println(man.GetTag(tagName))
181+
fmt.Println(man.GetTag(tagName).ClearDefaults(manifest.DefaultManifestEntry).String())
159182

160183
// Output:
161184
// bash:4.4
162185
//
163186
// Maintainers: Tianon Gravi <[email protected]> (@tianon)
164187
// Tags: 4.4.12, 4.4, 4, latest
165188
// GitRepo: https://github.com/tianon/docker-bash.git
166-
// GitFetch: refs/heads/master
167189
// GitCommit: 1cbb5cf49b4c53bd5a986abf7a1afeb9a80eac1e
168190
// Directory: 4.4
169191
}

manifest/rfc2822.go

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"regexp"
8+
"sort"
89
"strings"
910

1011
"github.com/docker-library/go-dockerlibrary/pkg/stripper"
@@ -30,15 +31,20 @@ type Manifest2822Entry struct {
3031
Tags []string `delim:"," strip:"\n\r\t "`
3132
SharedTags []string `delim:"," strip:"\n\r\t "`
3233

34+
Architectures []string `delim:"," strip:"\n\r\t "`
35+
3336
GitRepo string
3437
GitFetch string
3538
GitCommit string
3639
Directory string
40+
// architecture-specific versions of the above fields are in Paragraph.Values as ARCH-Field, ala s390x-Directory
3741

3842
Constraints []string `delim:"," strip:"\n\r\t "`
3943
}
4044

4145
var DefaultManifestEntry = Manifest2822Entry{
46+
Architectures: []string{"amd64"},
47+
4248
GitFetch: "refs/heads/master",
4349
Directory: ".",
4450
}
@@ -48,6 +54,7 @@ func (entry Manifest2822Entry) Clone() Manifest2822Entry {
4854
entry.Maintainers = append([]string{}, entry.Maintainers...)
4955
entry.Tags = append([]string{}, entry.Tags...)
5056
entry.SharedTags = append([]string{}, entry.SharedTags...)
57+
entry.Architectures = append([]string{}, entry.Architectures...)
5158
entry.Constraints = append([]string{}, entry.Constraints...)
5259
return entry
5360
}
@@ -66,17 +73,44 @@ func (entry Manifest2822Entry) SharedTagsString() string {
6673
return strings.Join(entry.SharedTags, StringSeparator2822)
6774
}
6875

76+
func (entry Manifest2822Entry) ArchitecturesString() string {
77+
return strings.Join(entry.Architectures, StringSeparator2822)
78+
}
79+
6980
func (entry Manifest2822Entry) ConstraintsString() string {
7081
return strings.Join(entry.Constraints, StringSeparator2822)
7182
}
7283

7384
// if this method returns "true", then a.Tags and b.Tags can safely be combined (for the purposes of building)
7485
func (a Manifest2822Entry) SameBuildArtifacts(b Manifest2822Entry) bool {
75-
return a.GitRepo == b.GitRepo && a.GitFetch == b.GitFetch && a.GitCommit == b.GitCommit && a.Directory == b.Directory && a.ConstraintsString() == b.ConstraintsString()
86+
// check xxxarch-GitRepo, etc. fields for sameness first
87+
for _, key := range append(a.archFields(), b.archFields()...) {
88+
if a.Paragraph.Values[key] != b.Paragraph.Values[key] {
89+
return false
90+
}
91+
}
92+
93+
return a.ArchitecturesString() == b.ArchitecturesString() && a.GitRepo == b.GitRepo && a.GitFetch == b.GitFetch && a.GitCommit == b.GitCommit && a.Directory == b.Directory && a.ConstraintsString() == b.ConstraintsString()
94+
}
95+
96+
func isArchField(field string) bool {
97+
return strings.HasSuffix(field, "-GitRepo") || strings.HasSuffix(field, "-GitFetch") || strings.HasSuffix(field, "-GitCommit") || strings.HasSuffix(field, "-Directory")
98+
}
99+
100+
// returns a list of architecture-specific fields in an Entry
101+
func (entry Manifest2822Entry) archFields() []string {
102+
ret := []string{}
103+
for key, val := range entry.Paragraph.Values {
104+
if isArchField(key) && val != "" {
105+
ret = append(ret, key)
106+
}
107+
}
108+
return ret
76109
}
77110

78111
// returns a new Entry with any of the values that are equal to the values in "defaults" cleared
79112
func (entry Manifest2822Entry) ClearDefaults(defaults Manifest2822Entry) Manifest2822Entry {
113+
entry = entry.Clone() // make absolutely certain we have a deep clone
80114
if entry.MaintainersString() == defaults.MaintainersString() {
81115
entry.Maintainers = nil
82116
}
@@ -86,6 +120,9 @@ func (entry Manifest2822Entry) ClearDefaults(defaults Manifest2822Entry) Manifes
86120
if entry.SharedTagsString() == defaults.SharedTagsString() {
87121
entry.SharedTags = nil
88122
}
123+
if entry.ArchitecturesString() == defaults.ArchitecturesString() {
124+
entry.Architectures = nil
125+
}
89126
if entry.GitRepo == defaults.GitRepo {
90127
entry.GitRepo = ""
91128
}
@@ -98,6 +135,11 @@ func (entry Manifest2822Entry) ClearDefaults(defaults Manifest2822Entry) Manifes
98135
if entry.Directory == defaults.Directory {
99136
entry.Directory = ""
100137
}
138+
for _, key := range defaults.archFields() {
139+
if defaults.Paragraph.Values[key] == entry.Paragraph.Values[key] {
140+
delete(entry.Paragraph.Values, key)
141+
}
142+
}
101143
if entry.ConstraintsString() == defaults.ConstraintsString() {
102144
entry.Constraints = nil
103145
}
@@ -115,6 +157,9 @@ func (entry Manifest2822Entry) String() string {
115157
if str := entry.SharedTagsString(); str != "" {
116158
ret = append(ret, "SharedTags: "+str)
117159
}
160+
if str := entry.ArchitecturesString(); str != "" {
161+
ret = append(ret, "Architectures: "+str)
162+
}
118163
if str := entry.GitRepo; str != "" {
119164
ret = append(ret, "GitRepo: "+str)
120165
}
@@ -127,6 +172,11 @@ func (entry Manifest2822Entry) String() string {
127172
if str := entry.Directory; str != "" {
128173
ret = append(ret, "Directory: "+str)
129174
}
175+
archFields := entry.archFields()
176+
sort.Strings(archFields) // consistent ordering
177+
for _, key := range archFields {
178+
ret = append(ret, key+": "+entry.Paragraph.Values[key])
179+
}
130180
if str := entry.ConstraintsString(); str != "" {
131181
ret = append(ret, "Constraints: "+str)
132182
}
@@ -148,6 +198,34 @@ func (manifest Manifest2822) String() string {
148198
return strings.Join(ret, "\n\n")
149199
}
150200

201+
func (entry Manifest2822Entry) ArchGitRepo(arch string) string {
202+
if val, ok := entry.Paragraph.Values[arch+"-GitRepo"]; ok && val != "" {
203+
return val
204+
}
205+
return entry.GitRepo
206+
}
207+
208+
func (entry Manifest2822Entry) ArchGitFetch(arch string) string {
209+
if val, ok := entry.Paragraph.Values[arch+"-GitFetch"]; ok && val != "" {
210+
return val
211+
}
212+
return entry.GitFetch
213+
}
214+
215+
func (entry Manifest2822Entry) ArchGitCommit(arch string) string {
216+
if val, ok := entry.Paragraph.Values[arch+"-GitCommit"]; ok && val != "" {
217+
return val
218+
}
219+
return entry.GitCommit
220+
}
221+
222+
func (entry Manifest2822Entry) ArchDirectory(arch string) string {
223+
if val, ok := entry.Paragraph.Values[arch+"-Directory"]; ok && val != "" {
224+
return val
225+
}
226+
return entry.Directory
227+
}
228+
151229
func (entry Manifest2822Entry) HasTag(tag string) bool {
152230
for _, existingTag := range entry.Tags {
153231
if tag == existingTag {
@@ -364,6 +442,10 @@ func Parse2822(readerIn io.Reader) (*Manifest2822, error) {
364442
for {
365443
entry := manifest.Global.Clone()
366444

445+
// reset Architectures and SharedTags so that they can be either inherited or replaced, not additive
446+
entry.SharedTags = nil
447+
entry.Architectures = nil
448+
367449
err := decoder.Decode(&entry)
368450
if err == io.EOF {
369451
break
@@ -372,6 +454,13 @@ func Parse2822(readerIn io.Reader) (*Manifest2822, error) {
372454
return nil, err
373455
}
374456

457+
if len(entry.SharedTags) == 0 {
458+
entry.SharedTags = manifest.Global.SharedTags
459+
}
460+
if len(entry.Architectures) == 0 {
461+
entry.Architectures = manifest.Global.Architectures
462+
}
463+
375464
if !GitFetchRegex.MatchString(entry.GitFetch) {
376465
return nil, fmt.Errorf(`Tags %q has invalid GitFetch (must be "refs/heads/..." or "refs/tags/..."): %q`, entry.TagsString(), entry.GitFetch)
377466
}

0 commit comments

Comments
 (0)