Skip to content

Commit 9f95f29

Browse files
authored
Merge pull request #17 from infosiftr/go-dockerlibrary
Merge github.com/docker-library/go-dockerlibrary into bashbrew
2 parents 818df5f + 143301c commit 9f95f29

33 files changed

+1723
-18
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
**
2+
!architecture/
23
!bashbrew.sh
34
!cmd/
45
!go.mod
56
!go.sum
7+
!manifest/
8+
!pkg/
69
!scripts/

.github/workflows/ci.yml

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ jobs:
2727
bin/bashbrew list --uniq "$image"
2828
bin/bashbrew cat "$image"
2929
bin/bashbrew from --uniq "$image"
30+
go-test:
31+
name: Go Test
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v2
35+
- name: Go Test
36+
run: |
37+
docker build --pull --file Dockerfile.test .
3038
dockerfile:
3139
name: Test Dockerfile
3240
runs-on: ubuntu-latest

Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ WORKDIR /usr/src/bashbrew
1414
COPY go.mod go.sum ./
1515
RUN go mod download; go mod verify
1616

17-
COPY bashbrew.sh ./
18-
COPY cmd cmd
17+
COPY . .
1918
RUN export CGO_ENABLED=0; \
2019
bash -x ./bashbrew.sh --version; \
2120
rm -r ~/.cache/go-build; \

Dockerfile.test

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM golang:1.13-buster
2+
3+
SHELL ["bash", "-Eeuo", "pipefail", "-xc"]
4+
5+
WORKDIR /usr/src/bashbrew
6+
7+
COPY go.mod go.sum ./
8+
RUN go mod download; go mod verify
9+
10+
COPY . .
11+
12+
RUN go test -v -race -coverprofile=coverage.out ./...
13+
14+
RUN go tool cover -func=coverage.out

architecture/oci-platform.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package architecture
2+
3+
// https://github.com/opencontainers/image-spec/blob/v1.0.1/image-index.md#image-index-property-descriptions
4+
// see "platform" (under "manifests")
5+
type OCIPlatform struct {
6+
OS string `json:"os"`
7+
Architecture string `json:"architecture"`
8+
Variant string `json:"variant,omitempty"`
9+
10+
//OSVersion string `json:"os.version,omitempty"`
11+
//OSFeatures []string `json:"os.features,omitempty"`
12+
}
13+
14+
var SupportedArches = map[string]OCIPlatform{
15+
"amd64": {OS: "linux", Architecture: "amd64"},
16+
"arm32v5": {OS: "linux", Architecture: "arm", Variant: "v5"},
17+
"arm32v6": {OS: "linux", Architecture: "arm", Variant: "v6"},
18+
"arm32v7": {OS: "linux", Architecture: "arm", Variant: "v7"},
19+
"arm64v8": {OS: "linux", Architecture: "arm64", Variant: "v8"},
20+
"i386": {OS: "linux", Architecture: "386"},
21+
"mips64le": {OS: "linux", Architecture: "mips64le"},
22+
"ppc64le": {OS: "linux", Architecture: "ppc64le"},
23+
"s390x": {OS: "linux", Architecture: "s390x"},
24+
25+
"windows-amd64": {OS: "windows", Architecture: "amd64"},
26+
}

cmd/bashbrew/cmd-cat.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"text/template"
99

1010
"github.com/codegangsta/cli"
11-
"github.com/docker-library/go-dockerlibrary/manifest"
12-
"github.com/docker-library/go-dockerlibrary/pkg/templatelib"
11+
"github.com/docker-library/bashbrew/manifest"
12+
"github.com/docker-library/bashbrew/pkg/templatelib"
1313
)
1414

1515
var DefaultCatFormat = `

cmd/bashbrew/cmd-deps.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/codegangsta/cli"
99
"pault.ag/go/topsort"
1010

11-
"github.com/docker-library/go-dockerlibrary/manifest"
11+
"github.com/docker-library/bashbrew/manifest"
1212
)
1313

1414
func cmdOffspring(c *cli.Context) error {

cmd/bashbrew/cmd-list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"path"
66

77
"github.com/codegangsta/cli"
8-
"github.com/docker-library/go-dockerlibrary/manifest"
8+
"github.com/docker-library/bashbrew/manifest"
99
)
1010

1111
func cmdList(c *cli.Context) error {

cmd/bashbrew/cmd-put-shared.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
"github.com/codegangsta/cli"
1111

12-
"github.com/docker-library/go-dockerlibrary/architecture"
13-
"github.com/docker-library/go-dockerlibrary/manifest"
12+
"github.com/docker-library/bashbrew/architecture"
13+
"github.com/docker-library/bashbrew/manifest"
1414
)
1515

1616
func entriesToManifestToolYaml(singleArch bool, r Repo, entries ...*manifest.Manifest2822Entry) (string, time.Time, int, error) {

cmd/bashbrew/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010

1111
"github.com/codegangsta/cli"
12-
"github.com/docker-library/go-dockerlibrary/pkg/stripper"
12+
"github.com/docker-library/bashbrew/pkg/stripper"
1313
"pault.ag/go/debian/control"
1414
)
1515

cmd/bashbrew/docker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"strings"
1515

1616
"github.com/codegangsta/cli"
17-
"github.com/docker-library/go-dockerlibrary/manifest"
17+
"github.com/docker-library/bashbrew/manifest"
1818
)
1919

2020
type dockerfileMetadata struct {

cmd/bashbrew/git.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313

1414
"github.com/codegangsta/cli"
1515

16-
"github.com/docker-library/go-dockerlibrary/manifest"
17-
"github.com/docker-library/go-dockerlibrary/pkg/execpipe"
16+
"github.com/docker-library/bashbrew/manifest"
17+
"github.com/docker-library/bashbrew/pkg/execpipe"
1818

1919
goGit "github.com/go-git/go-git/v5"
2020
goGitConfig "github.com/go-git/go-git/v5/config"

cmd/bashbrew/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/codegangsta/cli"
1010

11-
"github.com/docker-library/go-dockerlibrary/manifest"
11+
"github.com/docker-library/bashbrew/manifest"
1212
)
1313

1414
// TODO somewhere, ensure that the Docker engine we're talking to is API version 1.22+ (Docker 1.10+)

cmd/bashbrew/repo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"sort"
99
"strings"
1010

11-
"github.com/docker-library/go-dockerlibrary/manifest"
11+
"github.com/docker-library/bashbrew/manifest"
1212
)
1313

1414
func repos(all bool, args ...string) ([]string, error) {

cmd/bashbrew/sort.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
"github.com/docker-library/go-dockerlibrary/manifest"
4+
"github.com/docker-library/bashbrew/manifest"
55
"pault.ag/go/topsort"
66
)
77

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.11
44

55
require (
66
github.com/codegangsta/cli v1.20.0
7-
github.com/docker-library/go-dockerlibrary v0.0.0-20200415185511-8f28c0fe22db
87
github.com/go-git/go-git/v5 v5.1.0
98
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect
109
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f // indirect

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
1010
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1111
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1212
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13-
github.com/docker-library/go-dockerlibrary v0.0.0-20200415185511-8f28c0fe22db h1:qxSDuZDqrt7X9gU75CD3GliYYSMLbHcO69VP7XWmoxk=
14-
github.com/docker-library/go-dockerlibrary v0.0.0-20200415185511-8f28c0fe22db/go.mod h1:ijRhN3WM71dD8TfohKoUdX46BT2uz/Ek5O+5PINI880=
1513
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
1614
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
1715
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=

manifest/example_test.go

+209
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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

Comments
 (0)