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", "id": "docker-in-docker",
"version": "2.12.0", "version": "2.12.1",
"name": "Docker (Docker-in-Docker)", "name": "Docker (Docker-in-Docker)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/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.", "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 @@ ...@@ -29,11 +29,11 @@
"type": "string", "type": "string",
"enum": [ "enum": [
"none", "none",
"latest", "v1",
"v2" "v2"
], ],
"default": "latest", "default": "v2",
"description": "Default version of Docker Compose (latest, v2 or none)" "description": "Default version of Docker Compose (v1, v2 or none)"
}, },
"azureDnsAutoDetection": { "azureDnsAutoDetection": {
"type": "boolean", "type": "boolean",
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
DOCKER_VERSION="${VERSION:-"latest"}" # The Docker/Moby Engine + CLI should match in version DOCKER_VERSION="${VERSION:-"latest"}" # The Docker/Moby Engine + CLI should match in version
USE_MOBY="${MOBY:-"true"}" USE_MOBY="${MOBY:-"true"}"
MOBY_BUILDX_VERSION="${MOBYBUILDXVERSION:-"latest"}" 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"}" AZURE_DNS_AUTO_DETECTION="${AZUREDNSAUTODETECTION:-"true"}"
DOCKER_DEFAULT_ADDRESS_POOL="${DOCKERDEFAULTADDRESSPOOL:-""}" DOCKER_DEFAULT_ADDRESS_POOL="${DOCKERDEFAULTADDRESSPOOL:-""}"
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}" USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
...@@ -159,6 +159,7 @@ get_previous_version() { ...@@ -159,6 +159,7 @@ get_previous_version() {
prev_version=${!variable_name} prev_version=${!variable_name}
output=$(curl -s "$repo_url"); output=$(curl -s "$repo_url");
if echo "$output" | jq -e 'type == "object"' > /dev/null; then
message=$(echo "$output" | jq -r '.message') message=$(echo "$output" | jq -r '.message')
if [[ $message == "API rate limit exceeded"* ]]; then if [[ $message == "API rate limit exceeded"* ]]; then
...@@ -166,9 +167,10 @@ get_previous_version() { ...@@ -166,9 +167,10 @@ get_previous_version() {
echo -e "\nAttempting to find latest version using GitHub tags." echo -e "\nAttempting to find latest version using GitHub tags."
find_prev_version_from_git_tags prev_version "$url" "tags/v" find_prev_version_from_git_tags prev_version "$url" "tags/v"
declare -g ${variable_name}="${prev_version}" 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." 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}" declare -g ${variable_name}="${version#v}"
fi fi
echo "${variable_name}=${!variable_name}" echo "${variable_name}=${!variable_name}"
...@@ -176,7 +178,7 @@ get_previous_version() { ...@@ -176,7 +178,7 @@ get_previous_version() {
get_github_api_repo_url() { get_github_api_repo_url() {
local url=$1 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 ...@@ -372,11 +374,8 @@ if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then
find_version_from_git_tags compose_version "$docker_compose_url" "tags/v" find_version_from_git_tags compose_version "$docker_compose_url" "tags/v"
echo "(*) Installing docker-compose ${compose_version}..." 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} || { 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" fallback_compose "$docker_compose_url"
else
echo -e "Error: Failed to install docker-compose v${compose_version}"
fi
} }
chmod +x ${docker_compose_path} chmod +x ${docker_compose_path}
......
...@@ -108,23 +108,20 @@ get_previous_version() { ...@@ -108,23 +108,20 @@ get_previous_version() {
local mode=$4 local mode=$4
prev_version=${!variable_name} prev_version=${!variable_name}
echo -e "\nAttempting to find latest version using Github Api."
output=$(curl -s "$repo_url"); output=$(curl -s "$repo_url");
message=$(echo "$output" | jq -r '.message')
if [[ $mode != "install_from_github_api_valid" ]]; then if echo "$output" | jq -e 'type == "object"' > /dev/null; then
message="API rate limit exceeded" message=$(echo "$output" | jq -r '.message')
fi
if [[ $message == "API rate limit exceeded"* ]]; then if [[ $message == "API rate limit exceeded"* ]]; then
echo -e "\nAttempting to find latest version using Github Api Failed. Exceeded API Rate Limit." echo -e "\nAn attempt to find latest version using GitHub Api Failed... \nReason: ${message}"
echo -e "\nAttempting to find latest version using Github Tags." echo -e "\nAttempting to find latest version using GitHub tags."
find_prev_version_from_git_tags prev_version "$url" "tags/v" find_prev_version_from_git_tags prev_version "$url" "tags/v"
declare -g ${variable_name}="${prev_version}" declare -g ${variable_name}="${prev_version}"
else fi
echo -e "\nAttempting to find latest version using Github Api Succeeded." elif echo "$output" | jq -e 'type == "array"' > /dev/null; then
version=$(echo "$output" | jq -r '.tag_name') echo -e "\nAttempting to find latest version using GitHub Api."
version=$(echo "$output" | jq -r '.[1].tag_name')
declare -g ${variable_name}="${version#v}" declare -g ${variable_name}="${version#v}"
fi fi
echo "${variable_name}=${!variable_name}" echo "${variable_name}=${!variable_name}"
...@@ -132,7 +129,7 @@ get_previous_version() { ...@@ -132,7 +129,7 @@ get_previous_version() {
get_github_api_repo_url() { get_github_api_repo_url() {
local url=$1 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() { 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