Unverified Commit 87fd9a35 authored by Mathiyarasy's avatar Mathiyarasy Committed by GitHub

[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
parent 7eec5e6a
{
"id": "docker-in-docker",
"version": "2.12.0",
"version": "2.12.1",
"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.",
......@@ -29,11 +29,11 @@
"type": "string",
"enum": [
"none",
"latest",
"v1",
"v2"
],
"default": "latest",
"description": "Default version of Docker Compose (latest, v2 or none)"
"default": "v2",
"description": "Default version of Docker Compose (v1, v2 or none)"
},
"azureDnsAutoDetection": {
"type": "boolean",
......
......@@ -11,7 +11,7 @@
DOCKER_VERSION="${VERSION:-"latest"}" # The Docker/Moby Engine + CLI should match in version
USE_MOBY="${MOBY:-"true"}"
MOBY_BUILDX_VERSION="${MOBYBUILDXVERSION:-"latest"}"
DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"latest"}" #latest, v2 or none
DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"v2"}" #v1, v2 or none
AZURE_DNS_AUTO_DETECTION="${AZUREDNSAUTODETECTION:-"true"}"
DOCKER_DEFAULT_ADDRESS_POOL="${DOCKERDEFAULTADDRESSPOOL:-""}"
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
......@@ -159,6 +159,7 @@ get_previous_version() {
prev_version=${!variable_name}
output=$(curl -s "$repo_url");
if echo "$output" | jq -e 'type == "object"' > /dev/null; then
message=$(echo "$output" | jq -r '.message')
if [[ $message == "API rate limit exceeded"* ]]; then
......@@ -166,9 +167,10 @@ get_previous_version() {
echo -e "\nAttempting to find latest version using GitHub tags."
find_prev_version_from_git_tags prev_version "$url" "tags/v"
declare -g ${variable_name}="${prev_version}"
else
fi
elif echo "$output" | jq -e 'type == "array"' > /dev/null; then
echo -e "\nAttempting to find latest version using GitHub Api."
version=$(echo "$output" | jq -r '.tag_name')
version=$(echo "$output" | jq -r '.[1].tag_name')
declare -g ${variable_name}="${version#v}"
fi
echo "${variable_name}=${!variable_name}"
......@@ -176,7 +178,7 @@ get_previous_version() {
get_github_api_repo_url() {
local url=$1
echo "${url/https:\/\/github.com/https:\/\/api.github.com\/repos}/releases/latest"
echo "${url/https:\/\/github.com/https:\/\/api.github.com\/repos}/releases"
}
###########################################
......@@ -372,11 +374,8 @@ if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then
find_version_from_git_tags compose_version "$docker_compose_url" "tags/v"
echo "(*) Installing docker-compose ${compose_version}..."
curl -fsSL "https://github.com/docker/compose/releases/download/v${compose_version}/docker-compose-linux-${target_compose_arch}" -o ${docker_compose_path} || {
if [[ $DOCKER_DASH_COMPOSE_VERSION == "latest" ]]; then
echo -e "\n(!) Failed to fetch the latest artifacts for docker-compose v${compose_version}..."
fallback_compose "$docker_compose_url"
else
echo -e "Error: Failed to install docker-compose v${compose_version}"
fi
}
chmod +x ${docker_compose_path}
......
......@@ -108,23 +108,20 @@ get_previous_version() {
local mode=$4
prev_version=${!variable_name}
echo -e "\nAttempting to find latest version using Github Api."
output=$(curl -s "$repo_url");
message=$(echo "$output" | jq -r '.message')
if [[ $mode != "install_from_github_api_valid" ]]; then
message="API rate limit exceeded"
fi
if echo "$output" | jq -e 'type == "object"' > /dev/null; then
message=$(echo "$output" | jq -r '.message')
if [[ $message == "API rate limit exceeded"* ]]; then
echo -e "\nAttempting to find latest version using Github Api Failed. Exceeded API Rate Limit."
echo -e "\nAttempting to find latest version using Github Tags."
echo -e "\nAn attempt to find latest version using GitHub Api Failed... \nReason: ${message}"
echo -e "\nAttempting to find latest version using GitHub tags."
find_prev_version_from_git_tags prev_version "$url" "tags/v"
declare -g ${variable_name}="${prev_version}"
else
echo -e "\nAttempting to find latest version using Github Api Succeeded."
version=$(echo "$output" | jq -r '.tag_name')
fi
elif echo "$output" | jq -e 'type == "array"' > /dev/null; then
echo -e "\nAttempting to find latest version using GitHub Api."
version=$(echo "$output" | jq -r '.[1].tag_name')
declare -g ${variable_name}="${version#v}"
fi
echo "${variable_name}=${!variable_name}"
......@@ -132,7 +129,7 @@ get_previous_version() {
get_github_api_repo_url() {
local url=$1
echo "${url/https:\/\/github.com/https:\/\/api.github.com\/repos}/releases/latest"
echo "${url/https:\/\/github.com/https:\/\/api.github.com\/repos}/releases"
}
install_using_get_previous_version() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment