diff --git a/.gitlab-ci-base-template.yml b/.gitlab-ci-base-template.yml index b357121..cedaff2 100644 --- a/.gitlab-ci-base-template.yml +++ b/.gitlab-ci-base-template.yml @@ -103,7 +103,7 @@ variables: .test: services: - - docker:stable-dind + - docker:24.0.5-dind stage: test script: - set_env_from_devops docker_test_image BUILT_DOCKER_TEST_IMAGE diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b08b928..37e667c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,6 +37,9 @@ build-bootstrap: DOCKER_IMAGE_TAGS: "" # Don't build development image DOCKER_TEST_IMAGE_STAGE: "" + script: + - sleep 30 + - devops create_images build: image: ${BOOTSTRAP_IMAGE} diff --git a/Dockerfile b/Dockerfile index 3449817..f94c51d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -73,6 +73,11 @@ ENV DOCKER_CLI_EXPERIMENTAL=enabled WORKDIR /app +# Add a wrapper for docker that waits for docker daemon. See: +# https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27300 +COPY ./utils/docker-wrapper.sh /usr/local/bin/docker +RUN chmod a+x /usr/local/bin/docker + RUN apk add --no-cache \ apache2-utils \ bash \ diff --git a/utils/docker-wrapper.sh b/utils/docker-wrapper.sh new file mode 100644 index 0000000..c3e7ee1 --- /dev/null +++ b/utils/docker-wrapper.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# A wrapper for docker to check that wait for docker daemon to spin up. See: +# https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27300 + +wait_for_dockerd() { + END=$(expr $(date +%s) + 30) # Wait for 30s at most. + while ! /usr/bin/docker info >/dev/null 2>&1; do + if [ $(date +%s) -ge "$END" ]; then + return 1 + fi + sleep 1 + done +} + +if ! wait_for_dockerd; then + echo "Failed to connect Docker daemon!" >&2 + exit 1 +fi + +exec /usr/bin/docker "$@"