Skip to content

Commit

Permalink
[ tests only] Solve colima ContainerWait failure (ddev#4144)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay authored Aug 25, 2022
1 parent a84a81a commit bec7523
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
8 changes: 4 additions & 4 deletions containers/ddev-webserver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ RUN chmod -f ugo+rwx /usr/local/bin /usr/local/bin/*

RUN chmod ugo+w /etc/ssl/certs /usr/local/share/ca-certificates

HEALTHCHECK --interval=1s --retries=10 --timeout=120s --start-period=10s CMD ["/healthcheck.sh"]
HEALTHCHECK --interval=1s --retries=120 --timeout=120s --start-period=120s CMD ["/healthcheck.sh"]
CMD ["/start.sh"]
RUN apt-get -qq clean -y && rm -rf /var/lib/apt/lists/* /tmp/ddev
#END ddev-webserver-dev-base
Expand All @@ -172,7 +172,7 @@ ENV XHPROF_OUTPUT_DIR=/tmp/xhprof

COPY --from=ddev-webserver-dev-base / /
EXPOSE 80 8025
HEALTHCHECK --interval=1s --retries=10 --timeout=120s --start-period=10s CMD ["/healthcheck.sh"]
HEALTHCHECK --interval=1s --retries=120 --timeout=120s --start-period=120s CMD ["/healthcheck.sh"]
CMD ["/start.sh"]
#END ddev-webserver

Expand Down Expand Up @@ -255,7 +255,7 @@ RUN /sbin/mkhomedir_helper www-data

RUN chmod ugo+w /etc/ssl/certs /usr/local/share/ca-certificates

HEALTHCHECK --interval=1s --retries=10 --timeout=120s --start-period=10s CMD ["/healthcheck.sh"]
HEALTHCHECK --interval=1s --retries=120 --timeout=120s --start-period=120s CMD ["/healthcheck.sh"]
CMD ["/start.sh"]
RUN apt-get -qq clean -y && rm -rf /var/lib/apt/lists/*

Expand All @@ -278,6 +278,6 @@ ENV TERM xterm
ENV BASH_ENV /etc/bash.nointeractive.bashrc

COPY --from=ddev-webserver-prod-base / /
HEALTHCHECK --interval=1s --retries=10 --timeout=120s --start-period=10s CMD ["/healthcheck.sh"]
HEALTHCHECK --interval=1s --retries=120 --timeout=120s --start-period=120s CMD ["/healthcheck.sh"]
CMD ["/start.sh"]
#END ddev-webserver-prod
6 changes: 4 additions & 2 deletions pkg/dockerutil/dockerutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ func NetExists(client *docker.Client, name string) bool {
// Returns logoutput, error, returns error if not "healthy"
func ContainerWait(waittime int, labels map[string]string) (string, error) {

timeoutChan := time.NewTimer(time.Duration(waittime) * time.Second)
durationWait := time.Duration(waittime) * time.Second
timeoutChan := time.NewTimer(durationWait)
tickChan := time.NewTicker(500 * time.Millisecond)
defer tickChan.Stop()
defer timeoutChan.Stop()
Expand All @@ -271,7 +272,8 @@ func ContainerWait(waittime int, labels map[string]string) (string, error) {
for {
select {
case <-timeoutChan.C:
return "", fmt.Errorf("health check timed out: labels %v timed out without becoming healthy, status=%v", labels, status)
_ = timeoutChan.Stop()
return "", fmt.Errorf("health check timed out after %v: labels %v timed out without becoming healthy, status=%v", durationWait, labels, status)

case <-tickChan.C:
container, err := FindContainerByLabels(labels)
Expand Down
25 changes: 12 additions & 13 deletions pkg/dockerutil/dockerutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"runtime"
"strings"
"testing"
"time"

"github.com/drud/ddev/pkg/exec"
"github.com/drud/ddev/pkg/util"
Expand Down Expand Up @@ -37,16 +38,13 @@ func testMain(m *testing.M) int {

// prep docker container for docker util tests
client := GetDockerClient()
imageExists, err := ImageExistsLocally(versionconstants.WebImg + ":" + versionconstants.WebTag)
imageExists, err := ImageExistsLocally(versionconstants.GetWebImage())
if err != nil {
logOutput.Errorf("Failed to check for local image %s: %v", versionconstants.WebImg+":"+versionconstants.WebTag, err)
logOutput.Errorf("Failed to check for local image %s: %v", versionconstants.GetWebImage(), err)
return 6
}
if !imageExists {
err := client.PullImage(docker.PullImageOptions{
Repository: versionconstants.WebImg,
Tag: versionconstants.WebTag,
}, docker.AuthConfiguration{})
err := Pull(versionconstants.GetWebImage())
if err != nil {
logOutput.Errorf("failed to pull test image: %v", err)
return 7
Expand Down Expand Up @@ -89,6 +87,7 @@ func testMain(m *testing.M) int {
logOutput.Errorf("failed to create/start docker container: %v", err)
return 1
}
log.Printf("StartContainer() at %v", time.Now())
err = client.StartContainer(container.ID, nil)
if err != nil {
logOutput.Errorf("-- FAIL: dockerutils_test failed to StartContainer: %v", err)
Expand All @@ -100,11 +99,14 @@ func testMain(m *testing.M) int {
logOutput.Errorf("-- FAIL: dockerutils_test failed to remove test container: %v", err)
}
}()
_, err = ContainerWait(60, map[string]string{"com.ddev.site-name": testContainerName})
log.Printf("ContainerWait at %v", time.Now())
out, err := ContainerWait(60, map[string]string{"com.ddev.site-name": testContainerName})
log.Printf("ContainerWait returrned at %v out='%s' err='%v'", time.Now(), out, err)

if err != nil {
logout, _ := exec.RunHostCommand("docker", "logs", container.Name)
inspectOut, _ := exec.RunHostCommand("sh", "-c", fmt.Sprintf("docker inspect %s|jq -r '.[0].State.Health.Log'", container.Name))
log.Printf("FAIL: dockerutils_test failed to ContainerWait for container: %v, logs\n========= container logs ======\n%s\n======= end logs =======\n==== health log =====\ninspectOut\n%s\n========", err, logout, inspectOut)
log.Printf("FAIL: dockerutils_test testMain failed to ContainerWait for container: %v, logs\n========= container logs ======\n%s\n======= end logs =======\n==== health log =====\ninspectOut\n%s\n========", err, logout, inspectOut)
return 4
}
exitStatus := m.Run()
Expand Down Expand Up @@ -144,9 +146,6 @@ func TestGetContainerHealth(t *testing.T) {

// TestContainerWait tests the error cases for the container check wait loop.
func TestContainerWait(t *testing.T) {
if IsColima() {
t.Skip("Skipping on colima because of so many odd failures")
}
assert := asrt.New(t)

labels := map[string]string{
Expand Down Expand Up @@ -285,11 +284,11 @@ func TestComposeWithStreams(t *testing.T) {
_, _, err = ComposeCmd(composeFiles, "up", "-d")
require.NoError(t, err)

_, err = ContainerWait(30, map[string]string{"com.ddev.site-name": t.Name()})
_, err = ContainerWait(60, map[string]string{"com.ddev.site-name": t.Name()})
if err != nil {
logout, _ := exec.RunCommand("docker", []string{"logs", t.Name()})
inspectOut, _ := exec.RunCommandPipe("sh", []string{"-c", fmt.Sprintf("docker inspect %s|jq -r '.[0].State.Health.Log'", t.Name())})
t.Fatalf("FAIL: dockerutils_test failed to ContainerWait for container: %v, logs\n========= container logs ======\n%s\n======= end logs =======\n==== health log =====\ninspectOut\n%s\n========", err, logout, inspectOut)
t.Fatalf("FAIL: TestComposeWithStreams failed to ContainerWait for container: %v, logs\n========= container logs ======\n%s\n======= end logs =======\n==== health log =====\ninspectOut\n%s\n========", err, logout, inspectOut)
}

// Point stdout to os.Stdout and do simple ps -ef in web container
Expand Down
2 changes: 1 addition & 1 deletion pkg/versionconstants/versionconstants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var SegmentKey = ""
var WebImg = "drud/ddev-webserver"

// WebTag defines the default web image tag
var WebTag = "20220808_yarn_crash" // Note that this can be overridden by make
var WebTag = "20220824_containerwait_fail" // Note that this can be overridden by make

// DBImg defines the default db image used for applications.
var DBImg = "drud/ddev-dbserver"
Expand Down

0 comments on commit bec7523

Please sign in to comment.