@@ -205,7 +205,17 @@ func (p *Provider) createRemoteExec(outputPath string) error {
205
205
group = p .config .RunAs .Group
206
206
}
207
207
208
- _ , err := p .container .ExecuteScript (targetID , script , envs , p .config .WorkingDirectory , user , group , 300 , p .log .StandardWriter ())
208
+ if p .config .Timeout == "" {
209
+ p .config .Timeout = "300s"
210
+ }
211
+
212
+ timeout , err := time .ParseDuration (p .config .Timeout )
213
+ if err != nil {
214
+ p .log .Error ("Unable to parse timeout duration" , "ref" , p .config .Meta .Name , "timeout" , p .config .Timeout , "error" , err )
215
+ return fmt .Errorf ("unable to parse timeout duration: %w" , err )
216
+ }
217
+
218
+ _ , err = p .container .ExecuteScript (targetID , script , envs , p .config .WorkingDirectory , user , group , int (timeout .Seconds ()), p .log .StandardWriter ())
209
219
if err != nil {
210
220
p .log .Error ("Unable to execute command" , "ref" , p .config .Meta .Name , "image" , p .config .Image , "script" , p .config .Script )
211
221
return fmt .Errorf ("unable to execute command: in remote container: %w" , err )
@@ -304,19 +314,21 @@ func (p *Provider) createLocalExec(outputPath string) (int, error) {
304
314
// create the folders for logs and pids
305
315
logPath := filepath .Join (utils .LogsDir (), fmt .Sprintf ("exec_%s.log" , p .config .Meta .Name ))
306
316
307
- // do we have a duration to parse
308
- var d time.Duration
309
- if p .config .Timeout != "" {
310
- d , err = time .ParseDuration (p .config .Timeout )
311
- if err != nil {
312
- return 0 , fmt .Errorf ("unable to parse duration for timeout: %s" , err )
313
- }
314
-
317
+ // do we have a duration to parse otherwise set default
318
+ if p .config .Timeout == "" {
319
+ p .config .Timeout = "300s"
320
+ } else {
315
321
if p .config .Daemon {
316
322
p .log .Warn ("Timeout will be ignored when exec is running in daemon mode" )
317
323
}
318
324
}
319
325
326
+ timeout , err := time .ParseDuration (p .config .Timeout )
327
+ if err != nil {
328
+ p .log .Error ("Unable to parse timeout duration" , "ref" , p .config .Meta .Name , "timeout" , p .config .Timeout , "error" , err )
329
+ return 1 , fmt .Errorf ("unable to parse timeout duration: %w" , err )
330
+ }
331
+
320
332
// inject the output file into the environment
321
333
envs = append (envs , fmt .Sprintf ("EXEC_OUTPUT=%s" , outputPath ))
322
334
@@ -327,7 +339,7 @@ func (p *Provider) createLocalExec(outputPath string) (int, error) {
327
339
WorkingDirectory : p .config .WorkingDirectory ,
328
340
RunInBackground : p .config .Daemon ,
329
341
LogFilePath : logPath ,
330
- Timeout : d ,
342
+ Timeout : timeout ,
331
343
}
332
344
333
345
pid , err := p .command .Execute (cc )
0 commit comments