Skip to content

Commit 87fd9a3

Browse files
authored
[docker-in-docker] - Correction in fetching previous version from github api url (#1302)
* Update dockercompose previous version logic * Update v2 as v2 is latest * Update default to v2 * Update test for fetching previous version * default to latest to test * fix the failure scenario * previous tag * remove latest condition check
1 parent 7eec5e6 commit 87fd9a3

File tree

3 files changed

+34
-38
lines changed

3 files changed

+34
-38
lines changed

src/docker-in-docker/devcontainer-feature.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "docker-in-docker",
3-
"version": "2.12.0",
3+
"version": "2.12.1",
44
"name": "Docker (Docker-in-Docker)",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/docker-in-docker",
66
"description": "Create child containers *inside* a container, independent from the host's docker instance. Installs Docker extension in the container along with needed CLIs.",
@@ -29,11 +29,11 @@
2929
"type": "string",
3030
"enum": [
3131
"none",
32-
"latest",
32+
"v1",
3333
"v2"
3434
],
35-
"default": "latest",
36-
"description": "Default version of Docker Compose (latest, v2 or none)"
35+
"default": "v2",
36+
"description": "Default version of Docker Compose (v1, v2 or none)"
3737
},
3838
"azureDnsAutoDetection": {
3939
"type": "boolean",

src/docker-in-docker/install.sh

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
DOCKER_VERSION="${VERSION:-"latest"}" # The Docker/Moby Engine + CLI should match in version
1212
USE_MOBY="${MOBY:-"true"}"
1313
MOBY_BUILDX_VERSION="${MOBYBUILDXVERSION:-"latest"}"
14-
DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"latest"}" #latest, v2 or none
14+
DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"v2"}" #v1, v2 or none
1515
AZURE_DNS_AUTO_DETECTION="${AZUREDNSAUTODETECTION:-"true"}"
1616
DOCKER_DEFAULT_ADDRESS_POOL="${DOCKERDEFAULTADDRESSPOOL:-""}"
1717
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
@@ -157,26 +157,28 @@ get_previous_version() {
157157
local repo_url=$2
158158
local variable_name=$3
159159
prev_version=${!variable_name}
160-
160+
161161
output=$(curl -s "$repo_url");
162-
message=$(echo "$output" | jq -r '.message')
163-
164-
if [[ $message == "API rate limit exceeded"* ]]; then
165-
echo -e "\nAn attempt to find latest version using GitHub Api Failed... \nReason: ${message}"
166-
echo -e "\nAttempting to find latest version using GitHub tags."
167-
find_prev_version_from_git_tags prev_version "$url" "tags/v"
168-
declare -g ${variable_name}="${prev_version}"
169-
else
162+
if echo "$output" | jq -e 'type == "object"' > /dev/null; then
163+
message=$(echo "$output" | jq -r '.message')
164+
165+
if [[ $message == "API rate limit exceeded"* ]]; then
166+
echo -e "\nAn attempt to find latest version using GitHub Api Failed... \nReason: ${message}"
167+
echo -e "\nAttempting to find latest version using GitHub tags."
168+
find_prev_version_from_git_tags prev_version "$url" "tags/v"
169+
declare -g ${variable_name}="${prev_version}"
170+
fi
171+
elif echo "$output" | jq -e 'type == "array"' > /dev/null; then
170172
echo -e "\nAttempting to find latest version using GitHub Api."
171-
version=$(echo "$output" | jq -r '.tag_name')
173+
version=$(echo "$output" | jq -r '.[1].tag_name')
172174
declare -g ${variable_name}="${version#v}"
173175
fi
174176
echo "${variable_name}=${!variable_name}"
175177
}
176178

177179
get_github_api_repo_url() {
178180
local url=$1
179-
echo "${url/https:\/\/github.com/https:\/\/api.github.com\/repos}/releases/latest"
181+
echo "${url/https:\/\/github.com/https:\/\/api.github.com\/repos}/releases"
180182
}
181183

182184
###########################################
@@ -372,11 +374,8 @@ if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then
372374
find_version_from_git_tags compose_version "$docker_compose_url" "tags/v"
373375
echo "(*) Installing docker-compose ${compose_version}..."
374376
curl -fsSL "https://github.com/docker/compose/releases/download/v${compose_version}/docker-compose-linux-${target_compose_arch}" -o ${docker_compose_path} || {
375-
if [[ $DOCKER_DASH_COMPOSE_VERSION == "latest" ]]; then
376-
fallback_compose "$docker_compose_url"
377-
else
378-
echo -e "Error: Failed to install docker-compose v${compose_version}"
379-
fi
377+
echo -e "\n(!) Failed to fetch the latest artifacts for docker-compose v${compose_version}..."
378+
fallback_compose "$docker_compose_url"
380379
}
381380

382381
chmod +x ${docker_compose_path}

test/docker-in-docker/docker_build_fallback_compose.sh

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,31 +108,28 @@ get_previous_version() {
108108
local mode=$4
109109
prev_version=${!variable_name}
110110

111-
echo -e "\nAttempting to find latest version using Github Api."
112-
113111
output=$(curl -s "$repo_url");
114-
message=$(echo "$output" | jq -r '.message')
115112

116-
if [[ $mode != "install_from_github_api_valid" ]]; then
117-
message="API rate limit exceeded"
118-
fi
119-
120-
if [[ $message == "API rate limit exceeded"* ]]; then
121-
echo -e "\nAttempting to find latest version using Github Api Failed. Exceeded API Rate Limit."
122-
echo -e "\nAttempting to find latest version using Github Tags."
123-
find_prev_version_from_git_tags prev_version "$url" "tags/v"
124-
declare -g ${variable_name}="${prev_version}"
125-
else
126-
echo -e "\nAttempting to find latest version using Github Api Succeeded."
127-
version=$(echo "$output" | jq -r '.tag_name')
113+
if echo "$output" | jq -e 'type == "object"' > /dev/null; then
114+
message=$(echo "$output" | jq -r '.message')
115+
116+
if [[ $message == "API rate limit exceeded"* ]]; then
117+
echo -e "\nAn attempt to find latest version using GitHub Api Failed... \nReason: ${message}"
118+
echo -e "\nAttempting to find latest version using GitHub tags."
119+
find_prev_version_from_git_tags prev_version "$url" "tags/v"
120+
declare -g ${variable_name}="${prev_version}"
121+
fi
122+
elif echo "$output" | jq -e 'type == "array"' > /dev/null; then
123+
echo -e "\nAttempting to find latest version using GitHub Api."
124+
version=$(echo "$output" | jq -r '.[1].tag_name')
128125
declare -g ${variable_name}="${version#v}"
129-
fi
126+
fi
130127
echo "${variable_name}=${!variable_name}"
131128
}
132129

133130
get_github_api_repo_url() {
134131
local url=$1
135-
echo "${url/https:\/\/github.com/https:\/\/api.github.com\/repos}/releases/latest"
132+
echo "${url/https:\/\/github.com/https:\/\/api.github.com\/repos}/releases"
136133
}
137134

138135
install_using_get_previous_version() {

0 commit comments

Comments
 (0)