Unverified Commit 965e1201 authored by Samruddhi Khandale's avatar Samruddhi Khandale Committed by GitHub

[docker] - Install previous version if current tags are missing artifacts (#897)

[docker-in-docker] - Install previous version if current tags are missing artifacts
parent 3c3a270a
{
"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.",
......
......@@ -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.
......
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