Skip to content

Commit

Permalink
[docker] - Install previous version if current tags are missing artif…
Browse files Browse the repository at this point in the history
…acts (#897)

[docker-in-docker] - Install previous version if current tags are missing artifacts
  • Loading branch information
samruddhikhandale authored Mar 6, 2024
1 parent 3c3a270 commit 965e120
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/docker-in-docker/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
31 changes: 24 additions & 7 deletions src/docker-in-docker/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
###########################################
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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.
Expand Down

0 comments on commit 965e120

Please sign in to comment.