mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 09:17:49 +08:00
build: handle --add-host
Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
parent
dc07613bd2
commit
77ed999572
@ -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
|
||||
}
|
||||
|
@ -31,9 +31,9 @@ type buildOptions struct {
|
||||
ssh []string
|
||||
outputs []string
|
||||
imageIDFile string
|
||||
extraHosts []string
|
||||
|
||||
// unimplemented
|
||||
extraHosts []string
|
||||
squash bool
|
||||
quiet bool
|
||||
networkMode string
|
||||
@ -62,9 +62,6 @@ type commonOptions struct {
|
||||
}
|
||||
|
||||
func runBuild(dockerCli command.Cli, in buildOptions) error {
|
||||
if len(in.extraHosts) > 0 {
|
||||
return errors.Errorf("extra hosts currently not implemented")
|
||||
}
|
||||
if in.squash {
|
||||
return errors.Errorf("squash currently not implemented")
|
||||
}
|
||||
@ -90,6 +87,7 @@ func runBuild(dockerCli command.Cli, in buildOptions) error {
|
||||
NoCache: in.noCache,
|
||||
Target: in.target,
|
||||
ImageIDFile: in.imageIDFile,
|
||||
ExtraHosts: in.extraHosts,
|
||||
}
|
||||
|
||||
platforms, err := build.ParsePlatformSpecs(in.platforms)
|
||||
@ -169,7 +167,6 @@ func buildCmd(dockerCli command.Cli) *cobra.Command {
|
||||
flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer")
|
||||
flags.MarkHidden("quiet")
|
||||
flags.MarkHidden("network")
|
||||
flags.MarkHidden("add-host")
|
||||
flags.MarkHidden("squash")
|
||||
|
||||
// hidden flags
|
||||
|
Loading…
x
Reference in New Issue
Block a user