Skip to content

Commit 8af4ce3

Browse files
[docker-outside-of-docker] compose-switch can fallback to previous version (devcontainers#901)
* compose-switch fallback previous version * changes required
1 parent 965e120 commit 8af4ce3

4 files changed

Lines changed: 64 additions & 2 deletions

File tree

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.4.2",
3+
"version": "1.4.3",
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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,22 @@ find_version_from_git_tags() {
9999
echo "${variable_name}=${!variable_name}"
100100
}
101101

102+
# Function to fetch the previous version of the plugin
103+
get_previous_version() {
104+
repo_url=$1
105+
# this would del the assets key and then get the second encountered tag_name's value from the filtered array of objects
106+
curl -s "$repo_url" | jq -r 'del(.[].assets) | .[0].tag_name'
107+
}
108+
109+
110+
install_compose_switch_fallback() {
111+
echo -e "\n(!) Failed to fetch the latest artifacts for compose-switch v${compose_switch_version}..."
112+
previous_version=$(get_previous_version "https://api.github.com/repos/docker/compose-switch/releases")
113+
echo -e "\nAttempting to install ${previous_version}"
114+
compose_switch_version=${previous_version#v}
115+
curl -fsSL "https://github.com/docker/compose-switch/releases/download/v${compose_switch_version}/docker-compose-linux-${architecture}" -o /usr/local/bin/docker-compose
116+
}
117+
102118
# Ensure apt is in non-interactive to avoid prompts
103119
export DEBIAN_FRONTEND=noninteractive
104120

@@ -255,7 +271,7 @@ if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then
255271
echo "(*) Installing compose-switch as docker-compose..."
256272
compose_switch_version="latest"
257273
find_version_from_git_tags compose_switch_version "https://github.com/docker/compose-switch"
258-
curl -fsSL "https://github.com/docker/compose-switch/releases/download/v${compose_switch_version}/docker-compose-linux-${architecture}" -o /usr/local/bin/docker-compose
274+
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
259275
chmod +x /usr/local/bin/docker-compose
260276
# TODO: Verify checksum once available: https://github.com/docker/compose-switch/issues/11
261277
fi
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Optional: Import test library
4+
source dev-container-features-test-lib
5+
6+
check "installs compose-switch as docker-compose" bash -c "[[ -f /usr/local/bin/docker-compose ]]"
7+
8+
# Fetch host/container arch.
9+
architecture="$(dpkg --print-architecture)"
10+
11+
repo_url="https://api.github.com/repos/docker/compose-switch/releases"
12+
13+
# Function to fetch the previous version of the plugin
14+
get_previous_version() {
15+
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
16+
}
17+
18+
install_compose_switch_fallback() {
19+
echo -e "\n(!) Failed to fetch the latest artifacts for compose-switch ${test_compose_switch_version}..."
20+
previous_version=$(get_previous_version)
21+
echo -e "\nAttempting to install ${previous_version}"
22+
compose_switch_version=${previous_version}
23+
sudo curl -fsSL "https://github.com/docker/compose-switch/releases/download/${compose_switch_version}/docker-compose-linux-${architecture}" -o /usr/local/bin/docker-compose
24+
}
25+
26+
install_compose-switch_as_docker-compose() {
27+
echo "(*) Installing compose-switch as docker-compose..."
28+
test_compose_switch_version="1.2.xyz"
29+
echo -e "\nTesting with $test_compose_switch_version..."
30+
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
31+
sudo chmod +x /usr/local/bin/docker-compose
32+
}
33+
34+
install_compose-switch_as_docker-compose
35+
36+
check "installs compose-switch as docker-compose" bash -c "[[ -f /usr/local/bin/docker-compose ]]"

test/docker-outside-of-docker/scenarios.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
{
2+
"docker_build_compose_fallback": {
3+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04",
4+
"features": {
5+
"docker-outside-of-docker": {
6+
"moby": false,
7+
"dockerDashComposeVersion": "latest"
8+
}
9+
},
10+
"containerUser": "vscode"
11+
},
212
"docker_init_moby": {
313
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04",
414
"features": {

0 commit comments

Comments
 (0)