@@ -159,6 +159,15 @@ func (s *S2IBuilder) Build() error {
159
159
}
160
160
161
161
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
+ }
162
171
163
172
config := & s2iapi.Config {
164
173
WorkingDir : buildDir ,
@@ -175,11 +184,12 @@ func (s *S2IBuilder) Build() error {
175
184
Environment : buildEnvVars (s .build ),
176
185
DockerNetworkMode : getDockerNetworkMode (),
177
186
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 ,
183
193
}
184
194
185
195
if s .build .Spec .Strategy .SourceStrategy .ForcePull {
@@ -341,3 +351,39 @@ func buildEnvVars(build *api.Build) map[string]string {
341
351
}
342
352
return envVars
343
353
}
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