BlueGit

timfa bluegit

Files

bluegit / internal / runnercfg / docker.go

docker.go

docker.go 972 B Download Raw
1package runnercfg
2
3import (
4 "context"
5 "os/exec"
6 "strings"
7 "time"
8)
9
10// DockerStatus is de gezondheid van de Docker-daemon.
11type DockerStatus struct {
12 Reachable bool `json:"reachable"`
13 Error string `json:"error,omitempty"`
14}
15
16// PingDocker praat met de Docker-daemon (`docker info`). Een aanwezige
17// binary zonder bereikbare daemon is niet reachable.
18func PingDocker(ctx context.Context, bin string) DockerStatus {
19 if strings.TrimSpace(bin) == "" {
20 bin = "docker"
21 }
22 if _, err := exec.LookPath(bin); err != nil {
23 return DockerStatus{Error: err.Error()}
24 }
25 if ctx == nil {
26 ctx = context.Background()
27 }
28 ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
29 defer cancel()
30 out, err := exec.CommandContext(ctx, bin, "info", "--format", "{{.ServerVersion}}").CombinedOutput()
31 msg := strings.TrimSpace(string(out))
32 if err != nil {
33 if msg == "" {
34 msg = err.Error()
35 }
36 return DockerStatus{Error: msg}
37 }
38 return DockerStatus{Reachable: true}
39}