Unverified Commit 8af4ce3d authored by Gaurav Saini's avatar Gaurav Saini Committed by GitHub

[docker-outside-of-docker] compose-switch can fallback to previous version (#901)

* compose-switch fallback previous version

* changes required
parent 965e1201
{ {
"id": "docker-outside-of-docker", "id": "docker-outside-of-docker",
"version": "1.4.2", "version": "1.4.3",
"name": "Docker (docker-outside-of-docker)", "name": "Docker (docker-outside-of-docker)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/docker-outside-of-docker", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/docker-outside-of-docker",
"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.", "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.",
......
...@@ -99,6 +99,22 @@ find_version_from_git_tags() { ...@@ -99,6 +99,22 @@ find_version_from_git_tags() {
echo "${variable_name}=${!variable_name}" echo "${variable_name}=${!variable_name}"
} }
# Function to fetch the previous version of the plugin
get_previous_version() {
repo_url=$1
# this would del the assets key and then get the second encountered tag_name's value from the filtered array of objects
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/docker-compose
}
# Ensure apt is in non-interactive to avoid prompts # Ensure apt is in non-interactive to avoid prompts
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
...@@ -255,7 +271,7 @@ if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then ...@@ -255,7 +271,7 @@ if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then
echo "(*) Installing compose-switch as docker-compose..." echo "(*) Installing compose-switch as docker-compose..."
compose_switch_version="latest" compose_switch_version="latest"
find_version_from_git_tags compose_switch_version "https://github.com/docker/compose-switch" 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/docker-compose curl -fsSL "https://github.com/docker/compose-switch/releases/download/v${compose_switch_version}/docker-compose-linux-${architecture}" -o /usr/local/bin/docker-compose || install_compose_switch_fallback
chmod +x /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose
# TODO: Verify checksum once available: https://github.com/docker/compose-switch/issues/11 # TODO: Verify checksum once available: https://github.com/docker/compose-switch/issues/11
fi fi
......
#!/bin/bash
# Optional: Import test library
source dev-container-features-test-lib
check "installs compose-switch as docker-compose" bash -c "[[ -f /usr/local/bin/docker-compose ]]"
# Fetch host/container arch.
architecture="$(dpkg --print-architecture)"
repo_url="https://api.github.com/repos/docker/compose-switch/releases"
# Function to fetch the previous version of the plugin
get_previous_version() {
sudo curl -s "$repo_url" | jq -r 'del(.[].assets) | .[0].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_compose_switch_fallback() {
echo -e "\n(!) Failed to fetch the latest artifacts for compose-switch ${test_compose_switch_version}..."
previous_version=$(get_previous_version)
echo -e "\nAttempting to install ${previous_version}"
compose_switch_version=${previous_version}
sudo curl -fsSL "https://github.com/docker/compose-switch/releases/download/${compose_switch_version}/docker-compose-linux-${architecture}" -o /usr/local/bin/docker-compose
}
install_compose-switch_as_docker-compose() {
echo "(*) Installing compose-switch as docker-compose..."
test_compose_switch_version="1.2.xyz"
echo -e "\nTesting with $test_compose_switch_version..."
sudo curl -fsSL "https://github.com/docker/compose-switch/releases/download/${test_compose_switch_version}/docker-compose-linux-${architecture}" -o /usr/local/bin/docker-compose || install_compose_switch_fallback
sudo chmod +x /usr/local/bin/docker-compose
}
install_compose-switch_as_docker-compose
check "installs compose-switch as docker-compose" bash -c "[[ -f /usr/local/bin/docker-compose ]]"
\ No newline at end of file
{ {
"docker_build_compose_fallback": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04",
"features": {
"docker-outside-of-docker": {
"moby": false,
"dockerDashComposeVersion": "latest"
}
},
"containerUser": "vscode"
},
"docker_init_moby": { "docker_init_moby": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04", "image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04",
"features": { "features": {
......
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