@@ -23,6 +23,19 @@ import (
2323 "encoding/json"
2424 "errors"
2525 "fmt"
26+ "io"
27+ "io/ioutil"
28+ "log"
29+ "os"
30+ "os/exec"
31+ "path"
32+ "path/filepath"
33+ "strconv"
34+ "strings"
35+ "sync"
36+ "syscall"
37+ "time"
38+
2639 "github.com/aws/aws-sdk-go/aws"
2740 "github.com/aws/aws-sdk-go/aws/credentials"
2841 "github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
@@ -38,18 +51,6 @@ import (
3851 "github.com/devtron-labs/common-lib/utils/dockerOperations"
3952 "github.com/devtron-labs/common-lib/utils/retryFunc"
4053 "golang.org/x/sync/errgroup"
41- "io"
42- "io/ioutil"
43- "log"
44- "os"
45- "os/exec"
46- "path"
47- "path/filepath"
48- "strconv"
49- "strings"
50- "sync"
51- "syscall"
52- "time"
5354)
5455
5556const (
@@ -480,7 +481,7 @@ func (impl *DockerHelperImpl) BuildArtifact(ciRequest *CommonWorkflowRequest) (s
480481 }
481482 useBuildxK8sDriver , eligibleK8sDriverNodes = dockerBuildConfig .CheckForBuildXK8sDriver ()
482483 if useBuildxK8sDriver {
483- deploymentNames , err = impl .createBuildxBuilderWithK8sDriver (ciContext , ciRequest .PropagateLabelsInBuildxPod , ciRequest .DockerConnection , dockerBuildConfig .BuildxDriverImage , eligibleK8sDriverNodes , ciRequest .PipelineId , ciRequest .WorkflowId )
484+ deploymentNames , err = impl .createBuildxBuilderWithK8sDriver (ciContext , ciRequest .PropagateLabelsInBuildxPod , ciRequest .DockerConnection , dockerBuildConfig .BuildxDriverImage , eligibleK8sDriverNodes , ciRequest .PipelineId , ciRequest .WorkflowId , builderPodWaitDuration )
484485 if err != nil {
485486 log .Println (util .DEVTRON , " error in creating buildxDriver , err : " , err .Error ())
486487 return err
@@ -1129,14 +1130,14 @@ func (impl *DockerHelperImpl) createBuildxBuilderForMultiArchBuild(ciContext cic
11291130 return nil
11301131}
11311132
1132- func (impl * DockerHelperImpl ) createBuildxBuilderWithK8sDriver (ciContext cicxt.CiContext , propagateLabelsInBuildxPod bool , dockerConnection , buildxDriverImage string , builderNodes []map [string ]string , ciPipelineId , ciWorkflowId int ) ([]string , error ) {
1133+ func (impl * DockerHelperImpl ) createBuildxBuilderWithK8sDriver (ciContext cicxt.CiContext , propagateLabelsInBuildxPod bool , dockerConnection , buildxDriverImage string , builderNodes []map [string ]string , ciPipelineId , ciWorkflowId int , timeout time. Duration ) ([]string , error ) {
11331134 deploymentNames := make ([]string , 0 )
11341135 if len (builderNodes ) == 0 {
11351136 return deploymentNames , errors .New ("atleast one node is expected for builder with kubernetes driver" )
11361137 }
11371138 for i := 0 ; i < len (builderNodes ); i ++ {
11381139 nodeOpts := builderNodes [i ]
1139- builderCmd , deploymentName , err := getBuildxK8sDriverCmd (propagateLabelsInBuildxPod , dockerConnection , buildxDriverImage , nodeOpts , ciPipelineId , ciWorkflowId )
1140+ builderCmd , deploymentName , err := getBuildxK8sDriverCmd (propagateLabelsInBuildxPod , dockerConnection , buildxDriverImage , nodeOpts , ciPipelineId , ciWorkflowId , timeout )
11401141 if err != nil {
11411142 return deploymentNames , err
11421143 }
@@ -1213,7 +1214,7 @@ func (impl *DockerHelperImpl) runCmd(cmd string) (error, *bytes.Buffer) {
12131214 return err , errBuf
12141215}
12151216
1216- func getBuildxK8sDriverCmd (propagateLabelsInBuildxPod bool , dockerConnection , buildxDriverImage string , driverOpts map [string ]string , ciPipelineId , ciWorkflowId int ) (string , string , error ) {
1217+ func getBuildxK8sDriverCmd (propagateLabelsInBuildxPod bool , dockerConnection , buildxDriverImage string , driverOpts map [string ]string , ciPipelineId , ciWorkflowId int , timeout time. Duration ) (string , string , error ) {
12171218 buildxCreate := "docker buildx create --buildkitd-flags '--allow-insecure-entitlement network.host --allow-insecure-entitlement security.insecure' --name=%s --driver=kubernetes --node=%s --bootstrap "
12181219 nodeName := driverOpts ["node" ]
12191220 if nodeName == "" {
@@ -1235,6 +1236,9 @@ func getBuildxK8sDriverCmd(propagateLabelsInBuildxPod bool, dockerConnection, bu
12351236 }
12361237
12371238 driverOpts ["driverOptions" ] = getBuildXDriverOptionsWithImage (buildxDriverImage , driverOpts ["driverOptions" ])
1239+ if timeout > 0 {
1240+ driverOpts ["driverOptions" ] = getBuildXDriverOptionsWithTimeout (timeout , driverOpts ["driverOptions" ])
1241+ }
12381242 if len (driverOpts ["driverOptions" ]) > 0 {
12391243 buildxCreate += " '--driver-opt=%s' "
12401244 buildxCreate = fmt .Sprintf (buildxCreate , driverOpts ["driverOptions" ])
@@ -1259,6 +1263,21 @@ func getBuildXDriverOptionsWithImage(buildxDriverImage, driverOptions string) st
12591263 return driverOptions
12601264}
12611265
1266+ func getBuildXDriverOptionsWithTimeout (timeout time.Duration , driverOptions string ) string {
1267+ if strings .HasPrefix (driverOptions , "timeout=" ) ||
1268+ strings .Contains (driverOptions , ",timeout=" ) {
1269+ // if timeout is already present in driver options then do not override it, just return the existing options
1270+ return driverOptions
1271+ }
1272+ timeoutOption := fmt .Sprintf ("\" timeout=%s\" " , timeout .String ())
1273+ if len (driverOptions ) > 0 {
1274+ driverOptions += fmt .Sprintf (",%s" , timeoutOption )
1275+ } else {
1276+ driverOptions = timeoutOption
1277+ }
1278+ return driverOptions
1279+ }
1280+
12621281func getBuildXDriverOptionsWithLabelsAndAnnotations (driverOptions string ) (string , error ) {
12631282 // not passing annotation as of now because --driver-opt=annotations is not supported by buildx if contains quotes
12641283 labels := make (map [string ]string )
0 commit comments