Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
| ... | ... |
@@ -3,6 +3,7 @@ package buildkit |
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
"io" |
| 6 |
+ "net" |
|
| 6 | 7 |
"strings" |
| 7 | 8 |
"sync" |
| 8 | 9 |
"time" |
| ... | ... |
@@ -244,6 +245,12 @@ func (b *Builder) Build(ctx context.Context, opt backend.BuildConfig) (*builder. |
| 244 | 244 |
return nil, errors.Errorf("network mode %q not supported by buildkit", opt.Options.NetworkMode)
|
| 245 | 245 |
} |
| 246 | 246 |
|
| 247 |
+ extraHosts, err := toBuildkitExtraHosts(opt.Options.ExtraHosts) |
|
| 248 |
+ if err != nil {
|
|
| 249 |
+ return nil, err |
|
| 250 |
+ } |
|
| 251 |
+ frontendAttrs["add-hosts"] = extraHosts |
|
| 252 |
+ |
|
| 247 | 253 |
exporterAttrs := map[string]string{}
|
| 248 | 254 |
|
| 249 | 255 |
if len(opt.Options.Tags) > 0 {
|
| ... | ... |
@@ -444,3 +451,19 @@ func (j *buildJob) SetUpload(ctx context.Context, rc io.ReadCloser) error {
|
| 444 | 444 |
return fn(rc) |
| 445 | 445 |
} |
| 446 | 446 |
} |
| 447 |
+ |
|
| 448 |
+// toBuildkitExtraHosts converts hosts from docker key:value format to buildkit's csv format |
|
| 449 |
+func toBuildkitExtraHosts(inp []string) (string, error) {
|
|
| 450 |
+ if len(inp) == 0 {
|
|
| 451 |
+ return "", nil |
|
| 452 |
+ } |
|
| 453 |
+ hosts := make([]string, 0, len(inp)) |
|
| 454 |
+ for _, h := range inp {
|
|
| 455 |
+ parts := strings.Split(h, ":") |
|
| 456 |
+ if len(parts) != 2 || parts[0] == "" || net.ParseIP(parts[1]) == nil {
|
|
| 457 |
+ return "", errors.Errorf("invalid host %s", h)
|
|
| 458 |
+ } |
|
| 459 |
+ hosts = append(hosts, parts[0]+"="+parts[1]) |
|
| 460 |
+ } |
|
| 461 |
+ return strings.Join(hosts, ","), nil |
|
| 462 |
+} |