mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-31 23:58:03 +08:00
@@ -36,6 +36,7 @@ type Options struct {
|
||||
BuildArgs map[string]string
|
||||
Pull bool
|
||||
ImageIDFile string
|
||||
ExtraHosts []string
|
||||
|
||||
NoCache bool
|
||||
Target string
|
||||
@@ -227,6 +228,12 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, pw
|
||||
so.FrontendAttrs["platform"] = strings.Join(pp, ",")
|
||||
}
|
||||
|
||||
extraHosts, err := toBuildkitExtraHosts(opt.ExtraHosts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
so.FrontendAttrs["add-hosts"] = extraHosts
|
||||
|
||||
var statusCh chan *client.SolveStatus
|
||||
if pw != nil {
|
||||
statusCh = pw.Status()
|
||||
|
@@ -3,7 +3,11 @@ package build
|
||||
import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// archiveHeaderSize is the number of bytes in an archive header
|
||||
@@ -32,3 +36,20 @@ func isArchive(header []byte) bool {
|
||||
_, err := r.Next()
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// toBuildkitExtraHosts converts hosts from docker key:value format to buildkit's csv format
|
||||
func toBuildkitExtraHosts(inp []string) (string, error) {
|
||||
if len(inp) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
hosts := make([]string, 0, len(inp))
|
||||
for _, h := range inp {
|
||||
parts := strings.Split(h, ":")
|
||||
|
||||
if len(parts) != 2 || parts[0] == "" || net.ParseIP(parts[1]) == nil {
|
||||
return "", errors.Errorf("invalid host %s", h)
|
||||
}
|
||||
hosts = append(hosts, parts[0]+"="+parts[1])
|
||||
}
|
||||
return strings.Join(hosts, ","), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user