set build-args from docker proxy configuration

For backward compatibility with docker build.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
pull/959/head
Tonis Tiigi 3 years ago
parent c273e0986c
commit e98a476dc8

@ -87,11 +87,12 @@ type Inputs struct {
} }
type DriverInfo struct { type DriverInfo struct {
Driver driver.Driver Driver driver.Driver
Name string Name string
Platform []specs.Platform Platform []specs.Platform
Err error Err error
ImageOpt imagetools.Opt ImageOpt imagetools.Opt
ProxyConfig map[string]string
} }
type DockerAPI interface { type DockerAPI interface {
@ -338,7 +339,8 @@ func toRepoOnly(in string) (string, error) {
return strings.Join(out, ","), nil return strings.Join(out, ","), nil
} }
func toSolveOpt(ctx context.Context, d driver.Driver, multiDriver bool, opt Options, bopts gateway.BuildOpts, configDir string, pw progress.Writer, dl dockerLoadCallback) (solveOpt *client.SolveOpt, release func(), err error) { func toSolveOpt(ctx context.Context, di DriverInfo, multiDriver bool, opt Options, bopts gateway.BuildOpts, configDir string, pw progress.Writer, dl dockerLoadCallback) (solveOpt *client.SolveOpt, release func(), err error) {
d := di.Driver
defers := make([]func(), 0, 2) defers := make([]func(), 0, 2)
releaseF := func() { releaseF := func() {
for _, f := range defers { for _, f := range defers {
@ -541,6 +543,12 @@ func toSolveOpt(ctx context.Context, d driver.Driver, multiDriver bool, opt Opti
so.FrontendAttrs["label:"+k] = v so.FrontendAttrs["label:"+k] = v
} }
for k, v := range di.ProxyConfig {
if _, ok := opt.BuildArgs[k]; !ok {
so.FrontendAttrs["build-arg:"+k] = v
}
}
// set platforms // set platforms
if len(opt.Platforms) != 0 { if len(opt.Platforms) != 0 {
pp := make([]string, len(opt.Platforms)) pp := make([]string, len(opt.Platforms))
@ -635,12 +643,12 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
multiDriver := len(m[k]) > 1 multiDriver := len(m[k]) > 1
hasMobyDriver := false hasMobyDriver := false
for i, dp := range m[k] { for i, dp := range m[k] {
d := drivers[dp.driverIndex].Driver di := drivers[dp.driverIndex]
if d.IsMobyDriver() { if di.Driver.IsMobyDriver() {
hasMobyDriver = true hasMobyDriver = true
} }
opt.Platforms = dp.platforms opt.Platforms = dp.platforms
so, release, err := toSolveOpt(ctx, d, multiDriver, opt, dp.bopts, configDir, w, func(name string) (io.WriteCloser, func(), error) { so, release, err := toSolveOpt(ctx, di, multiDriver, opt, dp.bopts, configDir, w, func(name string) (io.WriteCloser, func(), error) {
return newDockerLoader(ctx, docker, name, w) return newDockerLoader(ctx, docker, name, w)
}) })
if err != nil { if err != nil {

@ -73,8 +73,9 @@ func driversForNodeGroup(ctx context.Context, dockerCli command.Cli, ng *store.N
func(i int, n store.Node) { func(i int, n store.Node) {
eg.Go(func() error { eg.Go(func() error {
di := build.DriverInfo{ di := build.DriverInfo{
Name: n.Name, Name: n.Name,
Platform: n.Platforms, Platform: n.Platforms,
ProxyConfig: storeutil.GetProxyConfig(dockerCli),
} }
defer func() { defer func() {
dis[i] = di dis[i] = di
@ -264,9 +265,10 @@ func getDefaultDrivers(ctx context.Context, dockerCli command.Cli, defaultOnly b
} }
return []build.DriverInfo{ return []build.DriverInfo{
{ {
Name: "default", Name: "default",
Driver: d, Driver: d,
ImageOpt: imageopt, ImageOpt: imageopt,
ProxyConfig: storeutil.GetProxyConfig(dockerCli),
}, },
}, nil }, nil
} }

@ -37,6 +37,32 @@ func GetCurrentEndpoint(dockerCli command.Cli) (string, error) {
return de, nil return de, nil
} }
func GetProxyConfig(dockerCli command.Cli) map[string]string {
cfg := dockerCli.ConfigFile()
host := dockerCli.Client().DaemonHost()
proxy, ok := cfg.Proxies[host]
if !ok {
proxy = cfg.Proxies["default"]
}
m := map[string]string{}
if v := proxy.HTTPProxy; v != "" {
m["HTTP_PROXY"] = v
}
if v := proxy.HTTPSProxy; v != "" {
m["HTTPS_PROXY"] = v
}
if v := proxy.NoProxy; v != "" {
m["NO_PROXY"] = v
}
if v := proxy.FTPProxy; v != "" {
m["FTP_PROXY"] = v
}
return m
}
// GetDockerEndpoint returns docker endpoint string for given context // GetDockerEndpoint returns docker endpoint string for given context
func GetDockerEndpoint(dockerCli command.Cli, name string) (string, error) { func GetDockerEndpoint(dockerCli command.Cli, name string) (string, error) {
list, err := dockerCli.ContextStore().List() list, err := dockerCli.ContextStore().List()

Loading…
Cancel
Save