Unverified Commit 7eec5e6a authored by Gaurav Saini's avatar Gaurav Saini Committed by GitHub

[docker-outside-of-docker] - Correction in fetching previous version from github api url (#1252)

* [docker-outside-of-docker] - Correction in fetching previous version from github api url

* need full array of objects instead was pulling only the object pertaining to latest release

* Correcting the scenario when result of json can be an object or an array, so to tackle both the scenarios in the function of fallbacking

* version output for docker-compose-switch in test scenario run for testing fallback

* correction in getting version for docker compose outputted in test case

* correction

* correction

* correction

* run the pipeline again

* Update version devcontainer-feature.json

* remove DOCKER_DASH_COMPOSE_VERSION

* typo error

* remove if condition

---------
Co-authored-by: 's avatarsireeshajonnalagadda <sireeshajonnalagadda@github.com>
Co-authored-by: 's avatarMathiyarasy <157102811+Mathiyarasy@users.noreply.github.com>
parent c264b4e8
{ {
"id": "docker-outside-of-docker", "id": "docker-outside-of-docker",
"version": "1.6.0", "version": "1.6.1",
"name": "Docker (docker-outside-of-docker)", "name": "Docker (docker-outside-of-docker)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/docker-outside-of-docker", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/docker-outside-of-docker",
"description": "Re-use the host docker socket, adding the Docker CLI to a container. Feature invokes a script to enable using a forwarded Docker socket within a container to run Docker commands.", "description": "Re-use the host docker socket, adding the Docker CLI to a container. Feature invokes a script to enable using a forwarded Docker socket within a container to run Docker commands.",
......
...@@ -156,25 +156,26 @@ get_previous_version() { ...@@ -156,25 +156,26 @@ get_previous_version() {
output=$(curl -s "$repo_url"); output=$(curl -s "$repo_url");
check_packages jq check_packages jq
message=$(echo "$output" | jq -r '.message')
if [[ $message == "API rate limit exceeded"* ]]; then if echo "$output" | jq -e 'type == "object"' > /dev/null; then
echo -e "\nAn attempt to find latest version using GitHub Api Failed... \nReason: ${message}" message=$(echo "$output" | jq -r '.message')
echo -e "\nAttempting to find latest version using GitHub tags." if [[ $message == "API rate limit exceeded"* ]]; then
find_prev_version_from_git_tags prev_version "$url" "tags/v" echo -e "\nAn attempt to find previous to latest version using GitHub Api Failed... \nReason: ${message}"
declare -g ${variable_name}="${prev_version}" echo -e "\nAttempting to find previous to latest version using GitHub tags."
else find_prev_version_from_git_tags prev_version "$url" "tags/v"
echo -e "\nAttempting to find latest version using GitHub Api." declare -g ${variable_name}="${prev_version}"
version=$(echo "$output" | jq -r '.tag_name') fi
elif echo "$output" | jq -e 'type == "array"' > /dev/null; then
echo -e "\nAttempting to find previous 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}"
} }
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_compose_switch_fallback() { install_compose_switch_fallback() {
...@@ -361,11 +362,7 @@ if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then ...@@ -361,11 +362,7 @@ 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 install_compose_fallback "$docker_compose_url" "$compose_version" "$target_compose_arch" "$docker_compose_path"
install_compose_fallback "$docker_compose_url" "$compose_version" "$target_compose_arch" "$docker_compose_path"
else
echo -e "Error: Failed to install docker-compose v${compose_version}"
fi
} }
chmod +x ${docker_compose_path} chmod +x ${docker_compose_path}
......
...@@ -112,29 +112,26 @@ get_previous_version() { ...@@ -112,29 +112,26 @@ get_previous_version() {
local variable_name=$3 local variable_name=$3
local mode=$4 local mode=$4
prev_version=${!variable_name} prev_version=${!variable_name}
output=$(curl -s "$repo_url"); output=$(curl -s "$repo_url");
check_packages jq check_packages jq
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"* ]] || [[ $mode == 'mode1' ]]; then
if [[ $message == "API rate limit exceeded"* ]] || [[ $mode == 'mode1' ]]; then echo -e "\nAn attempt to find previous to latest version using GitHub Api Failed... \nReason: ${message}"
echo -e "\nAn attempt to find latest version using GitHub Api Failed... \nReason: ${message}" echo -e "\nAttempting to find previous to 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}" fi
else 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 previous 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}"
} }
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_compose_switch_fallback() { install_compose_switch_fallback() {
...@@ -159,7 +156,9 @@ install_compose-switch_as_docker-compose() { ...@@ -159,7 +156,9 @@ install_compose-switch_as_docker-compose() {
echo -e "\n👉 Trying to install compose-switch as docker-compose using mode 1 ( find_prev_version_from_git_tags method )"; echo -e "\n👉 Trying to install compose-switch as docker-compose using mode 1 ( find_prev_version_from_git_tags method )";
install_compose-switch_as_docker-compose "mode1" install_compose-switch_as_docker-compose "mode1"
check "installs compose-switch as docker-compose mode 1" bash -c "[[ -f /usr/local/bin/docker-compose ]]" check "installs compose-switch as docker-compose mode 1" bash -c "[[ -f /usr/local/bin/docker-compose ]]"
check "docker-compose version" bash -c "docker-compose version"
echo -e "\n👉 Trying to install compose-switch as docker-compose using mode 2 ( GitHub Api )"; echo -e "\n👉 Trying to install compose-switch as docker-compose using mode 2 ( GitHub Api )";
install_compose-switch_as_docker-compose "mode2" install_compose-switch_as_docker-compose "mode2"
check "installs compose-switch as docker-compose mode 2" bash -c "[[ -f /usr/local/bin/docker-compose ]]" check "installs compose-switch as docker-compose mode 2" bash -c "[[ -f /usr/local/bin/docker-compose ]]"
\ No newline at end of file check "docker-compose version" bash -c "docker-compose version"
\ No newline at end of file
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