mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 18:13:42 +08:00 
			
		
		
		
	set build-args from docker proxy configuration
For backward compatibility with docker build. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
		@@ -87,11 +87,12 @@ type Inputs struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type DriverInfo struct {
 | 
			
		||||
	Driver   driver.Driver
 | 
			
		||||
	Name     string
 | 
			
		||||
	Platform []specs.Platform
 | 
			
		||||
	Err      error
 | 
			
		||||
	ImageOpt imagetools.Opt
 | 
			
		||||
	Driver      driver.Driver
 | 
			
		||||
	Name        string
 | 
			
		||||
	Platform    []specs.Platform
 | 
			
		||||
	Err         error
 | 
			
		||||
	ImageOpt    imagetools.Opt
 | 
			
		||||
	ProxyConfig map[string]string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type DockerAPI interface {
 | 
			
		||||
@@ -338,7 +339,8 @@ func toRepoOnly(in string) (string, error) {
 | 
			
		||||
	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)
 | 
			
		||||
	releaseF := func() {
 | 
			
		||||
		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
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for k, v := range di.ProxyConfig {
 | 
			
		||||
		if _, ok := opt.BuildArgs[k]; !ok {
 | 
			
		||||
			so.FrontendAttrs["build-arg:"+k] = v
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// set platforms
 | 
			
		||||
	if len(opt.Platforms) != 0 {
 | 
			
		||||
		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
 | 
			
		||||
		hasMobyDriver := false
 | 
			
		||||
		for i, dp := range m[k] {
 | 
			
		||||
			d := drivers[dp.driverIndex].Driver
 | 
			
		||||
			if d.IsMobyDriver() {
 | 
			
		||||
			di := drivers[dp.driverIndex]
 | 
			
		||||
			if di.Driver.IsMobyDriver() {
 | 
			
		||||
				hasMobyDriver = true
 | 
			
		||||
			}
 | 
			
		||||
			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)
 | 
			
		||||
			})
 | 
			
		||||
			if err != nil {
 | 
			
		||||
 
 | 
			
		||||
@@ -73,8 +73,9 @@ func driversForNodeGroup(ctx context.Context, dockerCli command.Cli, ng *store.N
 | 
			
		||||
		func(i int, n store.Node) {
 | 
			
		||||
			eg.Go(func() error {
 | 
			
		||||
				di := build.DriverInfo{
 | 
			
		||||
					Name:     n.Name,
 | 
			
		||||
					Platform: n.Platforms,
 | 
			
		||||
					Name:        n.Name,
 | 
			
		||||
					Platform:    n.Platforms,
 | 
			
		||||
					ProxyConfig: storeutil.GetProxyConfig(dockerCli),
 | 
			
		||||
				}
 | 
			
		||||
				defer func() {
 | 
			
		||||
					dis[i] = di
 | 
			
		||||
@@ -264,9 +265,10 @@ func getDefaultDrivers(ctx context.Context, dockerCli command.Cli, defaultOnly b
 | 
			
		||||
	}
 | 
			
		||||
	return []build.DriverInfo{
 | 
			
		||||
		{
 | 
			
		||||
			Name:     "default",
 | 
			
		||||
			Driver:   d,
 | 
			
		||||
			ImageOpt: imageopt,
 | 
			
		||||
			Name:        "default",
 | 
			
		||||
			Driver:      d,
 | 
			
		||||
			ImageOpt:    imageopt,
 | 
			
		||||
			ProxyConfig: storeutil.GetProxyConfig(dockerCli),
 | 
			
		||||
		},
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -37,6 +37,32 @@ func GetCurrentEndpoint(dockerCli command.Cli) (string, error) {
 | 
			
		||||
	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
 | 
			
		||||
func GetDockerEndpoint(dockerCli command.Cli, name string) (string, error) {
 | 
			
		||||
	list, err := dockerCli.ContextStore().List()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user