@@ -3,10 +3,12 @@ package build
33import (
44 "archive/tar"
55 "bytes"
6+ "context"
67 "net"
78 "os"
89 "strings"
910
11+ "github.com/docker/buildx/driver"
1012 "github.com/docker/cli/opts"
1113 "github.com/docker/docker/builder/remotecontext/urlutil"
1214 "github.com/moby/buildkit/util/gitutil"
@@ -57,7 +59,7 @@ func isArchive(header []byte) bool {
5759}
5860
5961// toBuildkitExtraHosts converts hosts from docker key:value format to buildkit's csv format
60- func toBuildkitExtraHosts (inp []string , mobyDriver bool ) (string , error ) {
62+ func toBuildkitExtraHosts (ctx context. Context , inp []string , nodeDriver * driver. DriverHandle ) (string , error ) {
6163 if len (inp ) == 0 {
6264 return "" , nil
6365 }
@@ -67,11 +69,16 @@ func toBuildkitExtraHosts(inp []string, mobyDriver bool) (string, error) {
6769 if ! ok || host == "" || ip == "" {
6870 return "" , errors .Errorf ("invalid host %s" , h )
6971 }
70- // Skip IP address validation for "host-gateway" string with moby driver
71- if ! mobyDriver || ip != mobyHostGatewayName {
72- if net .ParseIP (ip ) == nil {
73- return "" , errors .Errorf ("invalid host %s" , h )
72+ // If the IP Address is a "host-gateway", replace this value with the
73+ // IP address provided by the worker's label.
74+ if ip == mobyHostGatewayName {
75+ hgip , err := nodeDriver .HostGatewayIP (ctx )
76+ if err != nil {
77+ return "" , errors .Wrap (err , "unable to derive the IP value for host-gateway" )
7478 }
79+ ip = hgip .String ()
80+ } else if net .ParseIP (ip ) == nil {
81+ return "" , errors .Errorf ("invalid host %s" , h )
7582 }
7683 hosts = append (hosts , host + "=" + ip )
7784 }
0 commit comments