Skip to content

Commit

Permalink
Merge branch 'fix/add-docker-wrapper' into 'v3'
Browse files Browse the repository at this point in the history
Add a wrapper for docker that waits for daemon

See merge request anders/ci-configuration!377
  • Loading branch information
Paul Nylund committed Feb 3, 2024
2 parents afe7a0c + 3d1c180 commit dd07912
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitlab-ci-base-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
21 changes: 21 additions & 0 deletions utils/docker-wrapper.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit dd07912

Please sign in to comment.