@@ -49,6 +49,13 @@ type ComposeCmdOpts struct {
49
49
Progress bool // Add dots every second while the compose command is running
50
50
}
51
51
52
+ // NoHealthCheck is a HealthConfig that disables any existing healthcheck when
53
+ // running a container. Used by RunSimpleContainer
54
+ // See https://pkg.go.dev/github.com/moby/docker-image-spec/specs-go/v1#HealthcheckConfig
55
+ var NoHealthCheck = dockerContainer.HealthConfig {
56
+ Test : []string {"NONE" }, // Disables any existing health check
57
+ }
58
+
52
59
// EnsureNetwork will ensure the Docker network for DDEV is created.
53
60
func EnsureNetwork (ctx context.Context , client * dockerClient.Client , name string , netOptions dockerTypes.NetworkCreate ) error {
54
61
// Pre-check for network duplicates
@@ -891,10 +898,14 @@ func GetDockerIP() (string, error) {
891
898
// RunSimpleContainer runs a container (non-daemonized) and captures the stdout/stderr.
892
899
// It will block, so not to be run on a container whose entrypoint or cmd might hang or run too long.
893
900
// This should be the equivalent of something like
894
- // docker run -t -u '%s:%s' -e SNAPSHOT_NAME='%s' -v '%s:/mnt/ddev_config' -v '%s:/var/lib/mysql' --rm --entrypoint=/migrate_file_to_volume.sh %s:%s"
901
+ // docker run -t -u '%s:%s' -e SNAPSHOT_NAME='%s' -v '%s:/mnt/ddev_config' -v '%s:/var/lib/mysql' --no-healthcheck -- rm --entrypoint=/migrate_file_to_volume.sh %s:%s"
895
902
// Example code from https://gist.github.com/fsouza/b0bf3043827f8e39c4589e88cec067d8
903
+ // Default behavior is to use the image's healthcheck (healthConfig == nil)
904
+ // When passed a pointer to HealthConfig (often &dockerutils.NoHealthCheck) it can turn off healthcheck
905
+ // or it can replace it or have other behaviors, see
906
+ // https://pkg.go.dev/github.com/moby/docker-image-spec/specs-go/v1#HealthcheckConfig
896
907
// Returns containerID, output, error
897
- func RunSimpleContainer (image string , name string , cmd []string , entrypoint []string , env []string , binds []string , uid string , removeContainerAfterRun bool , detach bool , labels map [string ]string , portBindings nat.PortMap ) (containerID string , output string , returnErr error ) {
908
+ func RunSimpleContainer (image string , name string , cmd []string , entrypoint []string , env []string , binds []string , uid string , removeContainerAfterRun bool , detach bool , labels map [string ]string , portBindings nat.PortMap , healthConfig * dockerContainer. HealthConfig ) (containerID string , output string , returnErr error ) {
898
909
ctx , client := GetDockerClient ()
899
910
900
911
// Ensure image string includes a tag
@@ -949,6 +960,7 @@ func RunSimpleContainer(image string, name string, cmd []string, entrypoint []st
949
960
Entrypoint : entrypoint ,
950
961
AttachStderr : true ,
951
962
AttachStdout : true ,
963
+ Healthcheck : healthConfig ,
952
964
}
953
965
954
966
containerHostConfig := & dockerContainer.HostConfig {
@@ -1409,7 +1421,7 @@ func CopyIntoVolume(sourcePath string, volumeName string, targetSubdir string, u
1409
1421
containerName := "CopyIntoVolume_" + nodeps .RandomString (12 )
1410
1422
1411
1423
track := util .TimeTrackC ("CopyIntoVolume " + sourcePath + " " + volumeName )
1412
- containerID , _ , err := RunSimpleContainer (ddevImages .GetWebImage (), containerName , []string {"sh" , "-c" , "mkdir -p " + targetSubdirFullPath + " && sleep infinity" }, nil , nil , []string {volumeName + ":" + volPath }, "0" , false , true , map [string ]string {"com.ddev.site-name" : "" }, nil )
1424
+ containerID , _ , err := RunSimpleContainer (ddevImages .GetWebImage (), containerName , []string {"sh" , "-c" , "mkdir -p " + targetSubdirFullPath + " && sleep infinity" }, nil , nil , []string {volumeName + ":" + volPath }, "0" , false , true , map [string ]string {"com.ddev.site-name" : "" }, nil , nil )
1413
1425
if err != nil {
1414
1426
return err
1415
1427
}
@@ -1481,7 +1493,7 @@ func Exec(containerID string, command string, uid string) (string, string, error
1481
1493
1482
1494
// CheckAvailableSpace outputs a warning if Docker space is low
1483
1495
func CheckAvailableSpace () {
1484
- _ , out , _ := RunSimpleContainer (ddevImages .GetWebImage (), "check-available-space-" + util .RandString (6 ), []string {"sh" , "-c" , `df / | awk '!/Mounted/ {print $4, $5;}'` }, []string {}, []string {}, []string {}, "" , true , false , map [string ]string {"com.ddev.site-name" : "" }, nil )
1496
+ _ , out , _ := RunSimpleContainer (ddevImages .GetWebImage (), "check-available-space-" + util .RandString (6 ), []string {"sh" , "-c" , `df / | awk '!/Mounted/ {print $4, $5;}'` }, []string {}, []string {}, []string {}, "" , true , false , map [string ]string {"com.ddev.site-name" : "" }, nil , nil )
1485
1497
out = strings .Trim (out , "% \r \n " )
1486
1498
parts := strings .Split (out , " " )
1487
1499
if len (parts ) != 2 {
0 commit comments