mirror of
				https://gitea.com/gitea/act_runner.git
				synced 2025-10-31 21:07:57 +01:00 
			
		
		
		
	Timeout to wait for and optionally require docker always (#741)
* do not require docker cli in the runner image for waiting for a sidecar dockerd * allow to specify that `:host` labels would also only be accepted if docker is reachable Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-on: https://gitea.com/gitea/act_runner/pulls/741 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Christopher Homberger <christopher.homberger@web.de> Co-committed-by: Christopher Homberger <christopher.homberger@web.de>
This commit is contained in:
		
				
					committed by
					
						 Lunny Xiao
						Lunny Xiao
					
				
			
			
				
	
			
			
			
						parent
						
							bbf9d7e90f
						
					
				
				
					commit
					8920c4a170
				
			| @@ -5,6 +5,7 @@ package cmd | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"path" | ||||
| @@ -13,6 +14,7 @@ import ( | ||||
| 	"slices" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | ||||
| 	"connectrpc.com/connect" | ||||
| 	"github.com/mattn/go-isatty" | ||||
| @@ -64,7 +66,34 @@ func runDaemon(ctx context.Context, daemArgs *daemonArgs, configFile *string) fu | ||||
| 			log.Warn("no labels configured, runner may not be able to pick up jobs") | ||||
| 		} | ||||
|  | ||||
| 		if ls.RequireDocker() { | ||||
| 		if ls.RequireDocker() || cfg.Container.RequireDocker { | ||||
| 			// Wait for dockerd be ready | ||||
| 			if timeout := cfg.Container.DockerTimeout; timeout > 0 { | ||||
| 				tctx, cancel := context.WithTimeout(ctx, timeout) | ||||
| 				defer cancel() | ||||
| 				keepRunning := true | ||||
| 				for keepRunning { | ||||
| 					dockerSocketPath, err := getDockerSocketPath(cfg.Container.DockerHost) | ||||
| 					if err != nil { | ||||
| 						log.Errorf("Failed to get socket path: %s", err.Error()) | ||||
| 					} else if err = envcheck.CheckIfDockerRunning(tctx, dockerSocketPath); errors.Is(err, context.Canceled) { | ||||
| 						log.Infof("Docker wait timeout of %s expired", timeout.String()) | ||||
| 						break | ||||
| 					} else if err != nil { | ||||
| 						log.Errorf("Docker connection failed: %s", err.Error()) | ||||
| 					} else { | ||||
| 						log.Infof("Docker is ready") | ||||
| 						break | ||||
| 					} | ||||
| 					select { | ||||
| 					case <-time.After(time.Second): | ||||
| 					case <-tctx.Done(): | ||||
| 						log.Infof("Docker wait timeout of %s expired", timeout.String()) | ||||
| 						keepRunning = false | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 			// Require dockerd be ready | ||||
| 			dockerSocketPath, err := getDockerSocketPath(cfg.Container.DockerHost) | ||||
| 			if err != nil { | ||||
| 				return err | ||||
|   | ||||
		Reference in New Issue
	
	Block a user