Skip to content

Commit c5f794b

Browse files
committed
Use strategy proxy setting for script download
1 parent fba9dc0 commit c5f794b

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

pkg/build/builder/sti.go

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ func (s *S2IBuilder) Build() error {
159159
}
160160

161161
buildTag := randomBuildTag(s.build.Namespace, s.build.Name)
162+
scriptDownloadProxyConfig, err := scriptProxyConfig(s.build)
163+
if err != nil {
164+
return err
165+
}
166+
if scriptDownloadProxyConfig != nil {
167+
glog.V(2).Infof("Using HTTP proxy %v and HTTPS proxy %v for script download",
168+
scriptDownloadProxyConfig.HTTPProxy,
169+
scriptDownloadProxyConfig.HTTPSProxy)
170+
}
162171

163172
config := &s2iapi.Config{
164173
WorkingDir: buildDir,
@@ -175,11 +184,12 @@ func (s *S2IBuilder) Build() error {
175184
Environment: buildEnvVars(s.build),
176185
DockerNetworkMode: getDockerNetworkMode(),
177186

178-
Source: sourceURI.String(),
179-
Tag: buildTag,
180-
ContextDir: s.build.Spec.Source.ContextDir,
181-
CGroupLimits: s.cgLimits,
182-
Injections: injections,
187+
Source: sourceURI.String(),
188+
Tag: buildTag,
189+
ContextDir: s.build.Spec.Source.ContextDir,
190+
CGroupLimits: s.cgLimits,
191+
Injections: injections,
192+
ScriptDownloadProxyConfig: scriptDownloadProxyConfig,
183193
}
184194

185195
if s.build.Spec.Strategy.SourceStrategy.ForcePull {
@@ -341,3 +351,39 @@ func buildEnvVars(build *api.Build) map[string]string {
341351
}
342352
return envVars
343353
}
354+
355+
// scriptProxyConfig determines a proxy configuration for downloading
356+
// scripts from a URL. For now, it uses environment variables passed in
357+
// the strategy's environment. There is no preference given to either lowercase
358+
// or uppercase form of the variable.
359+
func scriptProxyConfig(build *api.Build) (*s2iapi.ProxyConfig, error) {
360+
httpProxy := ""
361+
httpsProxy := ""
362+
for _, env := range build.Spec.Strategy.SourceStrategy.Env {
363+
switch env.Name {
364+
case "HTTP_PROXY", "http_proxy":
365+
httpProxy = env.Value
366+
case "HTTPS_PROXY", "https_proxy":
367+
httpsProxy = env.Value
368+
}
369+
}
370+
if len(httpProxy) == 0 && len(httpsProxy) == 0 {
371+
return nil, nil
372+
}
373+
config := &s2iapi.ProxyConfig{}
374+
if len(httpProxy) > 0 {
375+
proxyURL, err := url.Parse(httpProxy)
376+
if err != nil {
377+
return nil, err
378+
}
379+
config.HTTPProxy = proxyURL
380+
}
381+
if len(httpsProxy) > 0 {
382+
proxyURL, err := url.Parse(httpsProxy)
383+
if err != nil {
384+
return nil, err
385+
}
386+
config.HTTPSProxy = proxyURL
387+
}
388+
return config, nil
389+
}

0 commit comments

Comments
 (0)