mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
build: fix push-by-digest for multi-node
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
0398fa337b
commit
38889013af
@ -3,6 +3,7 @@ package build
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -547,31 +548,6 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
|
|||||||
|
|
||||||
var pushNames string
|
var pushNames string
|
||||||
|
|
||||||
if multiDriver {
|
|
||||||
for i, e := range opt.Exports {
|
|
||||||
switch e.Type {
|
|
||||||
case "oci", "tar":
|
|
||||||
return errors.Errorf("%s for multi-node builds currently not supported", e.Type)
|
|
||||||
case "image":
|
|
||||||
if e.Attrs["push"] != "" {
|
|
||||||
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok {
|
|
||||||
pushNames = e.Attrs["name"]
|
|
||||||
if pushNames == "" {
|
|
||||||
return errors.Errorf("tag is needed when pushing to registry")
|
|
||||||
}
|
|
||||||
names, err := toRepoOnly(e.Attrs["name"])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
e.Attrs["name"] = names
|
|
||||||
e.Attrs["push-by-digest"] = "true"
|
|
||||||
opt.Exports[i].Attrs = e.Attrs
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
pw := mw.WithPrefix("default", false)
|
pw := mw.WithPrefix("default", false)
|
||||||
defer close(pw.Status())
|
defer close(pw.Status())
|
||||||
@ -593,7 +569,7 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pushNames != "" {
|
if pushNames != "" {
|
||||||
progress.Write(pw, "merging manifest list", func() error {
|
progress.Write(pw, fmt.Sprintf("merging manifest list %s", pushNames), func() error {
|
||||||
descs := make([]specs.Descriptor, 0, len(res))
|
descs := make([]specs.Descriptor, 0, len(res))
|
||||||
|
|
||||||
for _, r := range res {
|
for _, r := range res {
|
||||||
@ -649,7 +625,34 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
|
|||||||
})
|
})
|
||||||
|
|
||||||
for i, dp := range dps {
|
for i, dp := range dps {
|
||||||
func(i int, dp driverPair) {
|
so := *dp.so
|
||||||
|
|
||||||
|
if multiDriver {
|
||||||
|
for i, e := range so.Exports {
|
||||||
|
switch e.Type {
|
||||||
|
case "oci", "tar":
|
||||||
|
return errors.Errorf("%s for multi-node builds currently not supported", e.Type)
|
||||||
|
case "image":
|
||||||
|
if pushNames == "" && e.Attrs["push"] != "" {
|
||||||
|
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok {
|
||||||
|
pushNames = e.Attrs["name"]
|
||||||
|
if pushNames == "" {
|
||||||
|
return errors.Errorf("tag is needed when pushing to registry")
|
||||||
|
}
|
||||||
|
names, err := toRepoOnly(e.Attrs["name"])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
e.Attrs["name"] = names
|
||||||
|
e.Attrs["push-by-digest"] = "true"
|
||||||
|
so.Exports[i].Attrs = e.Attrs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func(i int, dp driverPair, so client.SolveOpt) {
|
||||||
pw := mw.WithPrefix(k, multiTarget)
|
pw := mw.WithPrefix(k, multiTarget)
|
||||||
|
|
||||||
c := clients[dp.driverIndex]
|
c := clients[dp.driverIndex]
|
||||||
@ -666,7 +669,7 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
|
|||||||
|
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
rr, err := c.Solve(ctx, nil, *dp.so, statusCh)
|
rr, err := c.Solve(ctx, nil, so, statusCh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -674,7 +677,7 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
}(i, dp)
|
}(i, dp, so)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -147,6 +147,8 @@ func (r *Resolver) Combine(ctx context.Context, in string, descs []ocispec.Descr
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resolver) Push(ctx context.Context, ref reference.Named, desc ocispec.Descriptor, dt []byte) error {
|
func (r *Resolver) Push(ctx context.Context, ref reference.Named, desc ocispec.Descriptor, dt []byte) error {
|
||||||
|
ref = reference.TagNameOnly(ref)
|
||||||
|
|
||||||
p, err := r.r.Pusher(ctx, ref.String())
|
p, err := r.r.Pusher(ctx, ref.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user