Skip to content

Commit

Permalink
changes as requested in comments by @samruddhikhandale
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravsaini04 committed Feb 22, 2024
1 parent 5cce54c commit 3e5a33b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
26 changes: 12 additions & 14 deletions src/docker-in-docker/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -338,20 +338,18 @@ get_previous_version() {
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
}

fetch_previous_version() {
install_previous_version_artifacts() {
wget_exit_code=$?
if [ $wget_exit_code -ne 0 ]; then # means wget command to fetch latest version failed
if [ $wget_exit_code -eq 8 ]; then # failure due to 404: Not Found.
echo -e "\n(!) Failed to fetch the latest artifacts for docker buildx v${buildx_version}..."
repo_url="https://api.github.com/repos/docker/buildx/releases" # GitHub repository URL
previous_version=$(get_previous_version "${repo_url}")
buildx_file_name="buildx-${previous_version}.linux-${architecture}"
echo -e "\nAttempting to install ${previous_version}"
wget https://github.com/docker/buildx/releases/download/${previous_version}/${buildx_file_name}
else
echo "(!) Failed to download docker buildx with exit code: $wget_exit_code"
exit 1
fi
if [ $wget_exit_code -eq 8 ]; then # failure due to 404: Not Found.
echo -e "\n(!) Failed to fetch the latest artifacts for docker buildx v${buildx_version}..."
repo_url="https://api.github.com/repos/docker/buildx/releases" # GitHub repository URL
previous_version=$(get_previous_version "${repo_url}")
buildx_file_name="buildx-${previous_version}.linux-${architecture}"
echo -e "\nAttempting to install ${previous_version}"
wget https://github.com/docker/buildx/releases/download/${previous_version}/${buildx_file_name}
else
echo "(!) Failed to download docker buildx with exit code: $wget_exit_code"
exit 1
fi
}

Expand All @@ -362,7 +360,7 @@ if [ "${INSTALL_DOCKER_BUILDX}" = "true" ]; then
buildx_file_name="buildx-v${buildx_version}.linux-${architecture}"

cd /tmp
wget https://github.com/docker/buildx/releases/download/v${buildx_version}/${buildx_file_name} || fetch_previous_version
wget https://github.com/docker/buildx/releases/download/v${buildx_version}/${buildx_file_name} || install_previous_version_artifacts

docker_home="/usr/libexec/docker"
cli_plugins_dir="${docker_home}/cli-plugins"
Expand Down
16 changes: 13 additions & 3 deletions test/docker-in-docker/docker_build_fallback_buildx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ set -e
# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests before test for fallback
HL="\033[1;33m"
N="\033[0;37m"
echo -e "\n👉${HL} docker/buildx version as installed by docker-in-docker feature${N}"
check "docker-buildx" docker buildx version
check "docker-build" docker build ./
check "docker-buildx" bash -c "docker buildx version"
check "docker-buildx-path" bash -c "ls -la /usr/libexec/docker/cli-plugins/docker-buildx"

echo -e "\n👉${HL} Creating a scenario for fallback${N}\n"
# Code to test the made up scenario when latest version of docker/buildx fails on wget command for fetching the artifacts
repo_url="https://api.github.com/repos/docker/buildx/releases" # GitHub repository URL
architecture="$(dpkg --print-architecture)"
Expand Down Expand Up @@ -41,7 +50,7 @@ change_version_to_fail() {
echo "${buildx_version_fallback_test}"
}

fetch_previous_version() {
install_previous_version_artifacts() {
wget_exit_code=$?
if [ $wget_exit_code -ne 0 ]; then # means wget command to fetch latest version failed
if [ $wget_exit_code -eq 8 ]; then # failure due to 404: Not Found.
Expand All @@ -62,7 +71,7 @@ buildx_file_name="buildx-${test_version}.linux-${architecture}"
buildx_version=$test_version

# This wget command will fail as the wrong version won't fetch artifact
wget https://github.com/docker/buildx/releases/download/${buildx_version}/${buildx_file_name} || fetch_previous_version
wget https://github.com/docker/buildx/releases/download/${buildx_version}/${buildx_file_name} || install_previous_version_artifacts

docker_home="/usr/libexec/docker"
cli_plugins_dir="${docker_home}/cli-plugins"
Expand All @@ -75,7 +84,8 @@ chown -R "${USERNAME}:docker" "${docker_home}"
chmod -R g+r+w "${docker_home}"
find "${docker_home}" -type d -print0 | xargs -n 1 -0 chmod g+s

# Definition specific tests
# Definition specific tests after test for fallback
echo -e "\n👉${HL} docker/buildx version as installed by test for fallback${N}"
check "docker-buildx" docker buildx version
check "docker-build" docker build ./
check "docker-buildx" bash -c "docker buildx version"
Expand Down

0 comments on commit 3e5a33b

Please sign in to comment.