From 965e12010f31baea61c7a9389082b19cfe498207 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Tue, 5 Mar 2024 17:20:49 -0800 Subject: [PATCH] [docker] - Install previous version if current tags are missing artifacts (#897) [docker-in-docker] - Install previous version if current tags are missing artifacts --- .../devcontainer-feature.json | 2 +- src/docker-in-docker/install.sh | 31 ++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/docker-in-docker/devcontainer-feature.json b/src/docker-in-docker/devcontainer-feature.json index ab26a5e11..671f4e2ed 100644 --- a/src/docker-in-docker/devcontainer-feature.json +++ b/src/docker-in-docker/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "docker-in-docker", - "version": "2.10.0", + "version": "2.10.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.", diff --git a/src/docker-in-docker/install.sh b/src/docker-in-docker/install.sh index 2a27f5c9c..dbe34e2ea 100755 --- a/src/docker-in-docker/install.sh +++ b/src/docker-in-docker/install.sh @@ -109,6 +109,20 @@ find_version_from_git_tags() { echo "${variable_name}=${!variable_name}" } +# Function to fetch the version released prior to the latest version +get_previous_version() { + repo_url=$1 + curl -s "$repo_url" | jq -r 'del(.[].assets) | .[0].tag_name' +} + +install_compose_switch_fallback() { + echo -e "\n(!) Failed to fetch the latest artifacts for compose-switch v${compose_switch_version}..." + previous_version=$(get_previous_version "https://api.github.com/repos/docker/compose-switch/releases") + echo -e "\nAttempting to install ${previous_version}" + compose_switch_version=${previous_version#v} + curl -fsSL "https://github.com/docker/compose-switch/releases/download/v${compose_switch_version}/docker-compose-linux-${architecture}" -o /usr/local/bin/compose-switch +} + ########################################### # Start docker-in-docker installation ########################################### @@ -290,6 +304,15 @@ if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then find_version_from_git_tags compose_version "https://github.com/docker/compose" "tags/v" echo "(*) Installing docker-compose ${compose_version}..." curl -L "https://github.com/docker/compose/releases/download/v${compose_version}/docker-compose-linux-${target_compose_arch}" -o ${docker_compose_path} + + if grep -q "Not Found" "${docker_compose_path}"; then + echo -e "\n(!) Failed to fetch the latest artifacts for docker-compose v${compose_version}..." + previous_version=$(get_previous_version "https://api.github.com/repos/docker/compose/releases") + echo -e "\nAttempting to install ${previous_version}" + compose_version=${previous_version#v} + curl -L "https://github.com/docker/compose/releases/download/v${compose_version}/docker-compose-linux-${target_compose_arch}" -o ${docker_compose_path} + fi + chmod +x ${docker_compose_path} # Download the SHA256 checksum @@ -310,7 +333,7 @@ if [ "${INSTALL_DOCKER_COMPOSE_SWITCH}" = "true" ] && ! type compose-switch > /d target_compose_path="$(dirname "${current_compose_path}")/docker-compose-v1" compose_switch_version="latest" find_version_from_git_tags compose_switch_version "https://github.com/docker/compose-switch" - curl -fsSL "https://github.com/docker/compose-switch/releases/download/v${compose_switch_version}/docker-compose-linux-${architecture}" -o /usr/local/bin/compose-switch + curl -fsSL "https://github.com/docker/compose-switch/releases/download/v${compose_switch_version}/docker-compose-linux-${architecture}" -o /usr/local/bin/compose-switch || install_compose_switch_fallback chmod +x /usr/local/bin/compose-switch # TODO: Verify checksum once available: https://github.com/docker/compose-switch/issues/11 # Setup v1 CLI as alternative in addition to compose-switch (which maps to v2) @@ -337,12 +360,6 @@ fi usermod -aG docker ${USERNAME} -# Function to fetch the version released prior to the latest version -get_previous_version() { - repo_url=$1 - curl -s "$repo_url" | jq -r 'del(.[].assets) | .[1].tag_name' # this would del the assets key and then get the second encountered tag_name's value from the filtered array of objects -} - install_previous_version_artifacts() { wget_exit_code=$? if [ $wget_exit_code -eq 8 ]; then # failure due to 404: Not Found.