Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
samruddhikhandale committed Aug 7, 2023
1 parent 773c443 commit 8cdd5fe
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/docker-in-docker/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "docker-in-docker",
"version": "2.2.2",
"version": "2.3.0",
"name": "Docker (Docker-in-Docker)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/docker-in-docker",
"description": "Create child containers *inside* a container, independent from the host's docker instance. Installs Docker extension in the container along with needed CLIs.",
Expand Down
4 changes: 2 additions & 2 deletions src/docker-in-docker/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ fi

tee /usr/local/share/docker-init.sh > /dev/null \
<< EOF
#!/usr/bin/env bash
#!/bin/sh
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
Expand Down Expand Up @@ -440,7 +440,7 @@ do
if [ "${docker_ok}" != "true" ]; then
echo "(*) Failed to start docker, retrying in 5s..."
(( retry_count++ ))
retry_count=`expr $retry_count + 1`
sleep 5s
fi
set -e
Expand Down
32 changes: 32 additions & 0 deletions test/docker-in-docker/docker_retry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
check "docker-buildx" docker buildx version
check "docker-ps" docker ps

sleep 5s

# Stop docker
pkill dockerd
pkill containerd

sleep 5s

set +e
docker_ok_code="$(docker info > /dev/null 2>&1; echo $?)"
set -e

check "docker-not-running" bash -c "[[ ${docker_ok_code} == 1 ]]"

# Testing retry logic
./test-scripts/docker-test-init.sh

check "docker-started-after-retries" docker ps

# Report result
reportResults
7 changes: 6 additions & 1 deletion test/docker-in-docker/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
}
},
"remoteUser": "node"
},
"docker_retry": {
"image": "ubuntu:focal",
"features": {
"docker-in-docker": {}
}
}

}
26 changes: 26 additions & 0 deletions test/docker-in-docker/test-scripts/docker-test-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

retry_count=0
docker_ok="false"

until [ "${docker_ok}" = "true" ] || [ "${retry_count}" -eq "5" ];
do
if [ "${retry_count}" -eq "3" ]; then
echo "Starting docker after 3 retries..."
/usr/local/share/docker-init.sh
fi

set +e
docker info > /dev/null 2>&1 && docker_ok="true"

if [ "${docker_ok}" != "true" ]; then
echo "(*) Failed to start docker, retrying in 5s... Retry count: ${retry_count}"
retry_count=`expr $retry_count + 1`
sleep 1s
fi
set -e
done

0 comments on commit 8cdd5fe

Please sign in to comment.