|
| 1 | +package manifest_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "bufio" |
| 5 | + "fmt" |
| 6 | + "strings" |
| 7 | + |
| 8 | + "github.com/docker-library/bashbrew/manifest" |
| 9 | +) |
| 10 | + |
| 11 | +func Example() { |
| 12 | + man, err := manifest.Parse(bufio.NewReader(strings.NewReader(`# RFC 2822 |
| 13 | +
|
| 14 | + # I LOVE CAKE |
| 15 | +
|
| 16 | +Maintainers: InfoSiftr <[email protected]> (@infosiftr), |
| 17 | + Johan Euphrosine <[email protected]> (@proppy) |
| 18 | +GitFetch: refs/heads/master |
| 19 | +GitRepo: https://github.com/docker-library/golang.git |
| 20 | +SharedTags: latest |
| 21 | +arm64v8-GitRepo: https://github.com/docker-library/golang.git |
| 22 | +Architectures: amd64, amd64 |
| 23 | +
|
| 24 | +
|
| 25 | + # hi |
| 26 | +
|
| 27 | +
|
| 28 | + # blasphemer |
| 29 | +
|
| 30 | +
|
| 31 | +# Go 1.6 |
| 32 | +Tags: 1.6.1, 1.6, 1 |
| 33 | +arm64v8-GitRepo: https://github.com/docker-library/golang.git |
| 34 | +Directory: 1.6 |
| 35 | +GitCommit: 0ce80411b9f41e9c3a21fc0a1bffba6ae761825a |
| 36 | +Constraints: some-random-build-server |
| 37 | +
|
| 38 | +
|
| 39 | +# Go 1.5 |
| 40 | +Tags: 1.5.3 |
| 41 | +GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19 |
| 42 | +SharedTags: 1.5.3-debian, 1.5-debian |
| 43 | +Directory: 1.5 |
| 44 | +s390x-GitCommit: b6c460e7cd79b595267870a98013ec3078b490df |
| 45 | +i386-GitFetch: refs/heads/i386 |
| 46 | +ppc64le-Directory: 1.5/ppc64le/ |
| 47 | +
|
| 48 | +
|
| 49 | +Tags: 1.5 |
| 50 | +SharedTags: 1.5-debian |
| 51 | +GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19 |
| 52 | +Directory: 1.5 |
| 53 | +s390x-GitCommit: b6c460e7cd79b595267870a98013ec3078b490df |
| 54 | +i386-GitFetch: refs/heads/i386 |
| 55 | +ppc64le-Directory: 1.5/ppc64le |
| 56 | +
|
| 57 | +Tags: 1.5-alpine |
| 58 | +GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19 |
| 59 | +Directory: 1.5 |
| 60 | +File: Dockerfile.alpine |
| 61 | +s390x-File: Dockerfile.alpine.s390x.bad-boy |
| 62 | +
|
| 63 | +SharedTags: raspbian |
| 64 | +GitCommit: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef |
| 65 | +Tags: raspbian-s390x |
| 66 | +Architectures: s390x, i386 |
| 67 | +File: Dockerfile-raspbian |
| 68 | +s390x-File: Dockerfile |
| 69 | +
|
| 70 | +
|
| 71 | +`))) |
| 72 | + if err != nil { |
| 73 | + panic(err) |
| 74 | + } |
| 75 | + fmt.Printf("-------------\n2822:\n%s\n", man) |
| 76 | + |
| 77 | + fmt.Printf("\nShared Tag Groups:\n") |
| 78 | + for _, group := range man.GetSharedTagGroups() { |
| 79 | + fmt.Printf("\n - %s\n", strings.Join(group.SharedTags, ", ")) |
| 80 | + for _, entry := range group.Entries { |
| 81 | + fmt.Printf(" - %s\n", entry.TagsString()) |
| 82 | + } |
| 83 | + } |
| 84 | + fmt.Printf("\n") |
| 85 | + |
| 86 | + man, err = manifest.Parse(bufio.NewReader(strings.NewReader(` |
| 87 | +# maintainer: InfoSiftr <[email protected]> (@infosiftr) |
| 88 | +# maintainer: John Smith <[email protected]> (@example-jsmith) |
| 89 | +
|
| 90 | +# first set |
| 91 | +a: b@c d |
| 92 | +e: b@c d |
| 93 | +
|
| 94 | + # second set |
| 95 | +f: g@h |
| 96 | +i: g@h j |
| 97 | +`))) |
| 98 | + if err != nil { |
| 99 | + panic(err) |
| 100 | + } |
| 101 | + fmt.Printf("-------------\nline-based:\n%v\n", man) |
| 102 | + |
| 103 | + // Output: |
| 104 | + // ------------- |
| 105 | + // 2822: |
| 106 | + // Maintainers: InfoSiftr <[email protected]> (@infosiftr), Johan Euphrosine <[email protected]> (@proppy) |
| 107 | + // SharedTags: latest |
| 108 | + // GitRepo: https://github.com/docker-library/golang.git |
| 109 | + // arm64v8-GitRepo: https://github.com/docker-library/golang.git |
| 110 | + // |
| 111 | + // Tags: 1.6.1, 1.6, 1 |
| 112 | + // GitCommit: 0ce80411b9f41e9c3a21fc0a1bffba6ae761825a |
| 113 | + // Directory: 1.6 |
| 114 | + // Constraints: some-random-build-server |
| 115 | + // |
| 116 | + // Tags: 1.5.3, 1.5 |
| 117 | + // SharedTags: 1.5.3-debian, 1.5-debian |
| 118 | + // GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19 |
| 119 | + // Directory: 1.5 |
| 120 | + // i386-GitFetch: refs/heads/i386 |
| 121 | + // ppc64le-Directory: 1.5/ppc64le |
| 122 | + // s390x-GitCommit: b6c460e7cd79b595267870a98013ec3078b490df |
| 123 | + // |
| 124 | + // Tags: 1.5-alpine |
| 125 | + // GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19 |
| 126 | + // Directory: 1.5 |
| 127 | + // File: Dockerfile.alpine |
| 128 | + // s390x-File: Dockerfile.alpine.s390x.bad-boy |
| 129 | + // |
| 130 | + // Tags: raspbian-s390x |
| 131 | + // SharedTags: raspbian |
| 132 | + // Architectures: i386, s390x |
| 133 | + // GitCommit: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef |
| 134 | + // File: Dockerfile-raspbian |
| 135 | + // s390x-File: Dockerfile |
| 136 | + // |
| 137 | + // Shared Tag Groups: |
| 138 | + // |
| 139 | + // - latest |
| 140 | + // - 1.6.1, 1.6, 1 |
| 141 | + // - 1.5-alpine |
| 142 | + // |
| 143 | + // - 1.5.3-debian, 1.5-debian |
| 144 | + // - 1.5.3, 1.5 |
| 145 | + // |
| 146 | + // - raspbian |
| 147 | + // - raspbian-s390x |
| 148 | + // |
| 149 | + // ------------- |
| 150 | + // line-based: |
| 151 | + // Maintainers: InfoSiftr <[email protected]> (@infosiftr), John Smith <[email protected]> (@example-jsmith) |
| 152 | + // GitFetch: refs/heads/* |
| 153 | + // |
| 154 | + // Tags: a, e |
| 155 | + // GitRepo: b |
| 156 | + // GitCommit: c |
| 157 | + // Directory: d |
| 158 | + // |
| 159 | + // Tags: f |
| 160 | + // GitRepo: g |
| 161 | + // GitFetch: refs/tags/h |
| 162 | + // GitCommit: FETCH_HEAD |
| 163 | + // |
| 164 | + // Tags: i |
| 165 | + // GitRepo: g |
| 166 | + // GitFetch: refs/tags/h |
| 167 | + // GitCommit: FETCH_HEAD |
| 168 | + // Directory: j |
| 169 | +} |
| 170 | + |
| 171 | +func ExampleFetch_local() { |
| 172 | + repoName, tagName, man, err := manifest.Fetch("testdata", "bash:4.4") |
| 173 | + if err != nil { |
| 174 | + panic(err) |
| 175 | + } |
| 176 | + |
| 177 | + fmt.Printf("%s:%s\n\n", repoName, tagName) |
| 178 | + |
| 179 | + fmt.Println(man.GetTag(tagName).ClearDefaults(manifest.DefaultManifestEntry).String()) |
| 180 | + |
| 181 | + // Output: |
| 182 | + // bash:4.4 |
| 183 | + // |
| 184 | + // Maintainers: Tianon Gravi <[email protected]> (@tianon) |
| 185 | + // Tags: 4.4.12, 4.4, 4, latest |
| 186 | + // GitRepo: https://github.com/tianon/docker-bash.git |
| 187 | + // GitCommit: 1cbb5cf49b4c53bd5a986abf7a1afeb9a80eac1e |
| 188 | + // Directory: 4.4 |
| 189 | +} |
| 190 | + |
| 191 | +func ExampleFetch_remote() { |
| 192 | + repoName, tagName, man, err := manifest.Fetch("/home/jsmith/docker/official-images/library", "https://github.com/docker-library/official-images/raw/1a3c4cd6d5cd53bd538a6f56a69f94c5b35325a7/library/bash:4.4") |
| 193 | + if err != nil { |
| 194 | + panic(err) |
| 195 | + } |
| 196 | + |
| 197 | + fmt.Printf("%s:%s\n\n", repoName, tagName) |
| 198 | + |
| 199 | + fmt.Println(man.GetTag(tagName).ClearDefaults(manifest.DefaultManifestEntry).String()) |
| 200 | + |
| 201 | + // Output: |
| 202 | + // bash:4.4 |
| 203 | + // |
| 204 | + // Maintainers: Tianon Gravi <[email protected]> (@tianon) |
| 205 | + // Tags: 4.4.12, 4.4, 4, latest |
| 206 | + // GitRepo: https://github.com/tianon/docker-bash.git |
| 207 | + // GitCommit: 1cbb5cf49b4c53bd5a986abf7a1afeb9a80eac1e |
| 208 | + // Directory: 4.4 |
| 209 | +} |
0 commit comments