Skip to content

Commit 7eec5e6

Browse files
gauravsaini04sireeshajonnalagaddaMathiyarasy
authored
[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: sireeshajonnalagadda <sireeshajonnalagadda@github.com> Co-authored-by: Mathiyarasy <157102811+Mathiyarasy@users.noreply.github.com>
1 parent c264b4e commit 7eec5e6

File tree

3 files changed

+31
-35
lines changed

3 files changed

+31
-35
lines changed

src/docker-outside-of-docker/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "docker-outside-of-docker",
3-
"version": "1.6.0",
3+
"version": "1.6.1",
44
"name": "Docker (docker-outside-of-docker)",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/docker-outside-of-docker",
66
"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.",

src/docker-outside-of-docker/install.sh

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,25 +156,26 @@ get_previous_version() {
156156
output=$(curl -s "$repo_url");
157157

158158
check_packages jq
159-
160-
message=$(echo "$output" | jq -r '.message')
161159

162-
if [[ $message == "API rate limit exceeded"* ]]; then
163-
echo -e "\nAn attempt to find latest version using GitHub Api Failed... \nReason: ${message}"
164-
echo -e "\nAttempting to find latest version using GitHub tags."
165-
find_prev_version_from_git_tags prev_version "$url" "tags/v"
166-
declare -g ${variable_name}="${prev_version}"
167-
else
168-
echo -e "\nAttempting to find latest version using GitHub Api."
169-
version=$(echo "$output" | jq -r '.tag_name')
160+
if echo "$output" | jq -e 'type == "object"' > /dev/null; then
161+
message=$(echo "$output" | jq -r '.message')
162+
if [[ $message == "API rate limit exceeded"* ]]; then
163+
echo -e "\nAn attempt to find previous to latest version using GitHub Api Failed... \nReason: ${message}"
164+
echo -e "\nAttempting to find previous to latest version using GitHub tags."
165+
find_prev_version_from_git_tags prev_version "$url" "tags/v"
166+
declare -g ${variable_name}="${prev_version}"
167+
fi
168+
elif echo "$output" | jq -e 'type == "array"' > /dev/null; then
169+
echo -e "\nAttempting to find previous version using GitHub Api."
170+
version=$(echo "$output" | jq -r '.[1].tag_name')
170171
declare -g ${variable_name}="${version#v}"
171172
fi
172-
echo "${variable_name}=${!variable_name}"
173+
echo "${variable_name}=${!variable_name}"
173174
}
174175

175176
get_github_api_repo_url() {
176177
local url=$1
177-
echo "${url/https:\/\/github.com/https:\/\/api.github.com\/repos}/releases/latest"
178+
echo "${url/https:\/\/github.com/https:\/\/api.github.com\/repos}/releases"
178179
}
179180

180181
install_compose_switch_fallback() {
@@ -361,11 +362,7 @@ if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then
361362
find_version_from_git_tags compose_version "$docker_compose_url" "tags/v"
362363
echo "(*) Installing docker-compose ${compose_version}..."
363364
curl -fsSL "https://github.com/docker/compose/releases/download/v${compose_version}/docker-compose-linux-${target_compose_arch}" -o ${docker_compose_path} || {
364-
if [[ $DOCKER_DASH_COMPOSE_VERSION == "latest" ]]; then
365-
install_compose_fallback "$docker_compose_url" "$compose_version" "$target_compose_arch" "$docker_compose_path"
366-
else
367-
echo -e "Error: Failed to install docker-compose v${compose_version}"
368-
fi
365+
install_compose_fallback "$docker_compose_url" "$compose_version" "$target_compose_arch" "$docker_compose_path"
369366
}
370367
chmod +x ${docker_compose_path}
371368

test/docker-outside-of-docker/docker_build_compose_fallback.sh

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,26 @@ get_previous_version() {
112112
local variable_name=$3
113113
local mode=$4
114114
prev_version=${!variable_name}
115-
116115
output=$(curl -s "$repo_url");
117-
118116
check_packages jq
119-
120-
message=$(echo "$output" | jq -r '.message')
121-
122-
if [[ $message == "API rate limit exceeded"* ]] || [[ $mode == 'mode1' ]]; then
123-
echo -e "\nAn attempt to find latest version using GitHub Api Failed... \nReason: ${message}"
124-
echo -e "\nAttempting to find latest version using GitHub tags."
125-
find_prev_version_from_git_tags prev_version "$url" "tags/v"
126-
declare -g ${variable_name}="${prev_version}"
127-
else
128-
echo -e "\nAttempting to find latest version using GitHub Api."
129-
version=$(echo "$output" | jq -r '.tag_name')
117+
if echo "$output" | jq -e 'type == "object"' > /dev/null; then
118+
message=$(echo "$output" | jq -r '.message')
119+
if [[ $message == "API rate limit exceeded"* ]] || [[ $mode == 'mode1' ]]; then
120+
echo -e "\nAn attempt to find previous to latest version using GitHub Api Failed... \nReason: ${message}"
121+
echo -e "\nAttempting to find previous to latest version using GitHub tags."
122+
find_prev_version_from_git_tags prev_version "$url" "tags/v"
123+
declare -g ${variable_name}="${prev_version}"
124+
fi
125+
elif echo "$output" | jq -e 'type == "array"' > /dev/null; then
126+
echo -e "\nAttempting to find previous version using GitHub Api."
127+
version=$(echo "$output" | jq -r '.[1].tag_name')
130128
declare -g ${variable_name}="${version#v}"
131-
fi
132-
echo "${variable_name}=${!variable_name}"
129+
fi
133130
}
134131

135132
get_github_api_repo_url() {
136133
local url=$1
137-
echo "${url/https:\/\/github.com/https:\/\/api.github.com\/repos}/releases/latest"
134+
echo "${url/https:\/\/github.com/https:\/\/api.github.com\/repos}/releases"
138135
}
139136

140137
install_compose_switch_fallback() {
@@ -159,7 +156,9 @@ install_compose-switch_as_docker-compose() {
159156
echo -e "\n👉 Trying to install compose-switch as docker-compose using mode 1 ( find_prev_version_from_git_tags method )";
160157
install_compose-switch_as_docker-compose "mode1"
161158
check "installs compose-switch as docker-compose mode 1" bash -c "[[ -f /usr/local/bin/docker-compose ]]"
159+
check "docker-compose version" bash -c "docker-compose version"
162160

163161
echo -e "\n👉 Trying to install compose-switch as docker-compose using mode 2 ( GitHub Api )";
164162
install_compose-switch_as_docker-compose "mode2"
165-
check "installs compose-switch as docker-compose mode 2" bash -c "[[ -f /usr/local/bin/docker-compose ]]"
163+
check "installs compose-switch as docker-compose mode 2" bash -c "[[ -f /usr/local/bin/docker-compose ]]"
164+
check "docker-compose version" bash -c "docker-compose version"

0 commit comments

Comments
 (0)