Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
| ... | ... |
@@ -6,6 +6,7 @@ import ( |
| 6 | 6 |
"path/filepath" |
| 7 | 7 |
|
| 8 | 8 |
"github.com/containerd/containerd/content/local" |
| 9 |
+ "github.com/containerd/containerd/platforms" |
|
| 9 | 10 |
"github.com/docker/docker/api/types" |
| 10 | 11 |
"github.com/docker/docker/builder/builder-next/adapters/containerimage" |
| 11 | 12 |
"github.com/docker/docker/builder/builder-next/adapters/localinlinecache" |
| ... | ... |
@@ -28,7 +29,9 @@ import ( |
| 28 | 28 |
"github.com/moby/buildkit/frontend/gateway/forwarder" |
| 29 | 29 |
"github.com/moby/buildkit/snapshot/blobmapping" |
| 30 | 30 |
"github.com/moby/buildkit/solver/bboltcachestorage" |
| 31 |
+ "github.com/moby/buildkit/util/binfmt_misc" |
|
| 31 | 32 |
"github.com/moby/buildkit/worker" |
| 33 |
+ specs "github.com/opencontainers/image-spec/specs-go/v1" |
|
| 32 | 34 |
"github.com/pkg/errors" |
| 33 | 35 |
) |
| 34 | 36 |
|
| ... | ... |
@@ -141,6 +144,11 @@ func newController(rt http.RoundTripper, opt Opt) (*control.Controller, error) {
|
| 141 | 141 |
return nil, errors.Errorf("snapshotter doesn't support differ")
|
| 142 | 142 |
} |
| 143 | 143 |
|
| 144 |
+ p, err := parsePlatforms(binfmt_misc.SupportedPlatforms()) |
|
| 145 |
+ if err != nil {
|
|
| 146 |
+ return nil, err |
|
| 147 |
+ } |
|
| 148 |
+ |
|
| 144 | 149 |
wopt := mobyworker.Opt{
|
| 145 | 150 |
ID: "moby", |
| 146 | 151 |
MetadataStore: md, |
| ... | ... |
@@ -155,6 +163,7 @@ func newController(rt http.RoundTripper, opt Opt) (*control.Controller, error) {
|
| 155 | 155 |
Exporter: exp, |
| 156 | 156 |
Transport: rt, |
| 157 | 157 |
Layers: layers, |
| 158 |
+ Platforms: p, |
|
| 158 | 159 |
} |
| 159 | 160 |
|
| 160 | 161 |
wc := &worker.Controller{}
|
| ... | ... |
@@ -223,3 +232,15 @@ func getGCPolicy(conf config.BuilderConfig, root string) ([]client.PruneInfo, er |
| 223 | 223 |
} |
| 224 | 224 |
return gcPolicy, nil |
| 225 | 225 |
} |
| 226 |
+ |
|
| 227 |
+func parsePlatforms(platformsStr []string) ([]specs.Platform, error) {
|
|
| 228 |
+ out := make([]specs.Platform, 0, len(platformsStr)) |
|
| 229 |
+ for _, s := range platformsStr {
|
|
| 230 |
+ p, err := platforms.Parse(s) |
|
| 231 |
+ if err != nil {
|
|
| 232 |
+ return nil, err |
|
| 233 |
+ } |
|
| 234 |
+ out = append(out, platforms.Normalize(p)) |
|
| 235 |
+ } |
|
| 236 |
+ return out, nil |
|
| 237 |
+} |
| ... | ... |
@@ -68,6 +68,7 @@ type Opt struct {
|
| 68 | 68 |
Transport nethttp.RoundTripper |
| 69 | 69 |
Exporter exporter.Exporter |
| 70 | 70 |
Layers LayerAccess |
| 71 |
+ Platforms []ocispec.Platform |
|
| 71 | 72 |
} |
| 72 | 73 |
|
| 73 | 74 |
// Worker is a local worker instance with dedicated snapshotter, cache, and so on. |
| ... | ... |
@@ -136,8 +137,10 @@ func (w *Worker) Labels() map[string]string {
|
| 136 | 136 |
|
| 137 | 137 |
// Platforms returns one or more platforms supported by the image. |
| 138 | 138 |
func (w *Worker) Platforms() []ocispec.Platform {
|
| 139 |
- // does not handle lcow |
|
| 140 |
- return []ocispec.Platform{platforms.DefaultSpec()}
|
|
| 139 |
+ if len(w.Opt.Platforms) == 0 {
|
|
| 140 |
+ return []ocispec.Platform{platforms.DefaultSpec()}
|
|
| 141 |
+ } |
|
| 142 |
+ return w.Opt.Platforms |
|
| 141 | 143 |
} |
| 142 | 144 |
|
| 143 | 145 |
// GCPolicy returns automatic GC Policy |
| 144 | 146 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,8 @@ |
| 0 |
+// +build !amd64 |
|
| 1 |
+ |
|
| 2 |
+package binfmt_misc |
|
| 3 |
+ |
|
| 4 |
+// This file is generated by running make inside the binfmt_misc package. |
|
| 5 |
+// Do not edit manually. |
|
| 6 |
+ |
|
| 7 |
+const Binaryamd64 = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xaa\x77\xf5\x71\x63\x62\x64\x64\x80\x01\x26\x06\x3b\x06\x30\x4f\xc0\x01\xcc\x77\x80\x8a\x1b\x08\xc0\x95\x30\x38\x30\x58\x30\x30\x33\x38\x30\xb0\x30\x30\x83\xd5\xb2\x30\x20\x03\x07\x14\x9a\x03\x6a\x34\x8c\x66\x80\x9a\x03\xe2\xb2\x22\xf1\x61\xf6\xc1\x68\x1e\xa8\x30\x8c\x86\xa9\x63\x81\xe2\x17\x50\xe1\x17\x50\x7b\x60\xb4\x02\x54\x1c\x46\x73\x30\x20\xf4\x09\x40\xed\x74\xf7\x0b\x05\xd9\x7f\x80\x05\xea\x8e\x51\x30\x0a\x46\xc1\x28\x18\x05\xa3\x60\x14\x8c\x82\x51\x30\x0a\x46\xc1\x28\x18\x05\xa3\x60\xb8\x03\x8f\xe3\x07\x6c\x40\x94\xe1\x7f\x7e\x56\x06\xbd\xe2\x8c\xe2\x92\xa2\x92\xc4\x24\x06\xbd\xbc\xfc\x92\x54\xbd\xf4\xbc\x52\xbd\x82\xa2\xfc\x82\xd4\xa2\x92\x4a\x06\xbd\x92\xd4\x8a\x12\x8a\xed\xe3\x66\x60\x60\x60\x07\x8f\x33\xa0\xf7\xdf\x51\xfb\xed\x0c\x68\xfd\x77\x18\x90\x83\xf6\xd9\xd9\x18\xd0\xc7\x0d\xd0\xc6\x0b\x18\x10\xe3\x0c\xe8\x7c\x66\x2c\xee\xe2\x81\xea\x57\x21\xa0\x1f\x10\x00\x00\xff\xff\x8a\x1b\xd7\x73\x30\x11\x00\x00" |
| 0 | 7 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,8 @@ |
| 0 |
+// +build !arm64 |
|
| 1 |
+ |
|
| 2 |
+package binfmt_misc |
|
| 3 |
+ |
|
| 4 |
+// This file is generated by running make inside the binfmt_misc package. |
|
| 5 |
+// Do not edit manually. |
|
| 6 |
+ |
|
| 7 |
+const Binaryarm64 = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xaa\x77\xf5\x71\x63\x62\x64\x64\x80\x01\x26\x86\xed\x0c\x20\x5e\x05\x83\x03\x98\xef\x00\x15\x9f\xc1\x80\x00\x0e\x0c\x16\x0c\x8c\x0c\x0e\x0c\xcc\x0c\x4c\x60\xb5\xac\x0c\x0c\x28\xb2\xc8\x74\x0b\x94\xd7\x02\x97\x87\xd9\xd5\x70\x69\x05\x77\xc3\x25\x46\x06\x86\x2b\x0c\x7a\xc5\x19\xc5\x25\x45\x25\x89\x49\x0c\x7a\x25\xa9\x15\x25\x0c\x54\x00\xdc\x50\x9b\xd8\xa0\x7c\x98\x7f\x2a\xa0\x7c\x1e\x34\xf5\x2c\x68\x7c\x90\x5e\x66\x2c\xe6\xc2\xfc\x21\x88\x45\x3d\x32\x00\x04\x00\x00\xff\xff\xe7\x30\x54\x02\x58\x01\x00\x00" |
| 0 | 7 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,8 @@ |
| 0 |
+// +build !arm |
|
| 1 |
+ |
|
| 2 |
+package binfmt_misc |
|
| 3 |
+ |
|
| 4 |
+// This file is generated by running make inside the binfmt_misc package. |
|
| 5 |
+// Do not edit manually. |
|
| 6 |
+ |
|
| 7 |
+const Binaryarm = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\x8c\x8e\x31\x0e\x82\x40\x14\x44\xdf\x17\x50\x13\x6d\xf4\x04\xda\x51\x6d\xc5\x05\x28\xb4\xd2\xc6\x70\x00\x97\x84\x44\x3a\x02\xdf\xc4\xce\x4b\x78\x00\xee\xc6\x01\xbc\x82\x01\x17\xdd\xc2\xc2\x49\x26\x93\x7d\x3b\xc9\x9f\xfb\xee\xb0\x17\x11\x46\x4d\x88\xe9\x5f\x19\x42\x02\x3c\xde\x30\x4a\xd8\x20\xc4\x84\x04\x7c\xdb\x32\xf8\x0c\x83\xa3\x0f\x6b\x3b\xa9\xda\x0e\x78\xa6\x2b\xc0\x16\x36\x2f\x91\x19\x30\x17\x4c\x73\x69\xb4\x56\x9b\x63\xb4\xb8\x29\x26\x3d\x1d\x8d\x55\xad\xcb\xfc\xaa\x45\xc3\xdf\x5a\xb8\x6b\x53\xb7\x37\x03\x96\xde\x7f\xe8\xb2\x9f\x10\x40\x35\xf2\x7e\xeb\xda\xeb\x89\x97\x81\xc7\x6b\x60\xfb\xa3\xf7\x0a\x00\x00\xff\xff\x73\x8f\xca\xf1\x34\x01\x00\x00" |
| 0 | 7 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,39 @@ |
| 0 |
+package binfmt_misc |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "bytes" |
|
| 4 |
+ "compress/gzip" |
|
| 5 |
+ "io" |
|
| 6 |
+ "io/ioutil" |
|
| 7 |
+ "os" |
|
| 8 |
+ "os/exec" |
|
| 9 |
+ "path/filepath" |
|
| 10 |
+) |
|
| 11 |
+ |
|
| 12 |
+func check(bin string) error {
|
|
| 13 |
+ tmpdir, err := ioutil.TempDir("", "qemu-check")
|
|
| 14 |
+ if err != nil {
|
|
| 15 |
+ return err |
|
| 16 |
+ } |
|
| 17 |
+ defer os.RemoveAll(tmpdir) |
|
| 18 |
+ pp := filepath.Join(tmpdir, "check") |
|
| 19 |
+ |
|
| 20 |
+ r, err := gzip.NewReader(bytes.NewReader([]byte(bin))) |
|
| 21 |
+ if err != nil {
|
|
| 22 |
+ return err |
|
| 23 |
+ } |
|
| 24 |
+ defer r.Close() |
|
| 25 |
+ |
|
| 26 |
+ f, err := os.OpenFile(pp, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0700) |
|
| 27 |
+ if err != nil {
|
|
| 28 |
+ return err |
|
| 29 |
+ } |
|
| 30 |
+ |
|
| 31 |
+ if _, err := io.Copy(f, r); err != nil {
|
|
| 32 |
+ f.Close() |
|
| 33 |
+ return err |
|
| 34 |
+ } |
|
| 35 |
+ f.Close() |
|
| 36 |
+ |
|
| 37 |
+ return exec.Command(pp).Run() |
|
| 38 |
+} |
| 0 | 39 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,32 @@ |
| 0 |
+package binfmt_misc |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "strings" |
|
| 4 |
+ "sync" |
|
| 5 |
+ |
|
| 6 |
+ "github.com/containerd/containerd/platforms" |
|
| 7 |
+) |
|
| 8 |
+ |
|
| 9 |
+var once sync.Once |
|
| 10 |
+var arr []string |
|
| 11 |
+ |
|
| 12 |
+func SupportedPlatforms() []string {
|
|
| 13 |
+ once.Do(func() {
|
|
| 14 |
+ def := platforms.DefaultString() |
|
| 15 |
+ arr = append(arr, def) |
|
| 16 |
+ |
|
| 17 |
+ if p := "linux/amd64"; def != p && amd64Supported() {
|
|
| 18 |
+ arr = append(arr, p) |
|
| 19 |
+ } |
|
| 20 |
+ if p := "linux/arm64"; def != p && arm64Supported() {
|
|
| 21 |
+ arr = append(arr, p) |
|
| 22 |
+ } |
|
| 23 |
+ if !strings.HasPrefix(def, "linux/arm/") && armSupported() {
|
|
| 24 |
+ arr = append(arr, "linux/arm/v7", "linux/arm/v6") |
|
| 25 |
+ } else if def == "linux/arm/v7" {
|
|
| 26 |
+ arr = append(arr, "linux/arm/v6") |
|
| 27 |
+ } |
|
| 28 |
+ }) |
|
| 29 |
+ |
|
| 30 |
+ return arr |
|
| 31 |
+} |