Unverified Commit 4db22d38 authored by Samruddhi Khandale's avatar Samruddhi Khandale Committed by GitHub

Docker-in-docker: Updates default value for "dockerDashComposeVersion" to "latest (#873)

* Set v2 by default ; draft

* Fix edge case: compose switch

* Update description

* validate "compose-switch" installation

* fix test
parent 0604e45e
{ {
"id": "docker-in-docker", "id": "docker-in-docker",
"version": "2.9.2", "version": "2.10.0",
"name": "Docker (Docker-in-Docker)", "name": "Docker (Docker-in-Docker)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/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.", "description": "Create child containers *inside* a container, independent from the host's docker instance. Installs Docker extension in the container along with needed CLIs.",
...@@ -29,11 +29,11 @@ ...@@ -29,11 +29,11 @@
"type": "string", "type": "string",
"enum": [ "enum": [
"none", "none",
"v1", "latest",
"v2" "v2"
], ],
"default": "v1", "default": "latest",
"description": "Default version of Docker Compose (v1 or v2 or none)" "description": "Default version of Docker Compose (latest, v2 or none)"
}, },
"azureDnsAutoDetection": { "azureDnsAutoDetection": {
"type": "boolean", "type": "boolean",
...@@ -50,6 +50,11 @@ ...@@ -50,6 +50,11 @@
"type": "boolean", "type": "boolean",
"default": true, "default": true,
"description": "Install Docker Buildx" "description": "Install Docker Buildx"
},
"installDockerComposeSwitch": {
"type": "boolean",
"default": true,
"description": "Install Compose Switch (provided docker compose is available) which is a replacement to the Compose V1 docker-compose (python) executable. It translates the command line into Compose V2 docker compose then runs the latter."
} }
}, },
"entrypoint": "/usr/local/share/docker-init.sh", "entrypoint": "/usr/local/share/docker-init.sh",
......
...@@ -11,11 +11,12 @@ ...@@ -11,11 +11,12 @@
DOCKER_VERSION="${VERSION:-"latest"}" # The Docker/Moby Engine + CLI should match in version DOCKER_VERSION="${VERSION:-"latest"}" # The Docker/Moby Engine + CLI should match in version
USE_MOBY="${MOBY:-"true"}" USE_MOBY="${MOBY:-"true"}"
MOBY_BUILDX_VERSION="${MOBYBUILDXVERSION:-"latest"}" MOBY_BUILDX_VERSION="${MOBYBUILDXVERSION:-"latest"}"
DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"v1"}" # v1 or v2 or none DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"latest"}" #latest, v2 or none
AZURE_DNS_AUTO_DETECTION="${AZUREDNSAUTODETECTION:-"true"}" AZURE_DNS_AUTO_DETECTION="${AZUREDNSAUTODETECTION:-"true"}"
DOCKER_DEFAULT_ADDRESS_POOL="${DOCKERDEFAULTADDRESSPOOL:-""}" DOCKER_DEFAULT_ADDRESS_POOL="${DOCKERDEFAULTADDRESSPOOL:-""}"
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}" USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
INSTALL_DOCKER_BUILDX="${INSTALLDOCKERBUILDX:-"true"}" INSTALL_DOCKER_BUILDX="${INSTALLDOCKERBUILDX:-"true"}"
INSTALL_DOCKER_COMPOSE_SWITCH="${INSTALLDOCKERCOMPOSESWITCH:-"true"}"
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc" MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES="bookworm buster bullseye bionic focal jammy" DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES="bookworm buster bullseye bionic focal jammy"
DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES="bookworm buster bullseye bionic focal hirsute impish jammy" DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES="bookworm buster bullseye bionic focal hirsute impish jammy"
...@@ -247,75 +248,77 @@ fi ...@@ -247,75 +248,77 @@ fi
echo "Finished installing docker / moby!" echo "Finished installing docker / moby!"
docker_home="/usr/libexec/docker"
cli_plugins_dir="${docker_home}/cli-plugins"
# If 'docker-compose' command is to be included # If 'docker-compose' command is to be included
if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then
# Install Docker Compose if not already installed and is on a supported architecture case "${architecture}" in
if type docker-compose > /dev/null 2>&1; then amd64) target_compose_arch=x86_64 ;;
echo "Docker Compose v1 already installed." arm64) target_compose_arch=aarch64 ;;
else *)
target_compose_arch="${architecture}" echo "(!) Docker in docker does not support machine architecture '$architecture'. Please use an x86-64 or ARM64 machine."
if [ "${target_compose_arch}" = "amd64" ]; then exit 1
target_compose_arch="x86_64" esac
fi
# https://github.com/devcontainers/features/issues/832
if [ "${target_compose_arch}" != "x86_64" ] && [ "${VERSION_CODENAME}" != "bookworm" ]; then
# Use pip to get a version that runs on this architecture
check_packages python3-minimal python3-pip libffi-dev python3-venv
export PIPX_HOME=/usr/local/pipx
mkdir -p ${PIPX_HOME}
export PIPX_BIN_DIR=/usr/local/bin
export PYTHONUSERBASE=/tmp/pip-tmp
export PIP_CACHE_DIR=/tmp/pip-tmp/cache
pipx_bin=pipx
if ! type pipx > /dev/null 2>&1; then
pip3 install --disable-pip-version-check --no-cache-dir --user pipx
pipx_bin=/tmp/pip-tmp/bin/pipx
fi
set +e
${pipx_bin} install --pip-args '--no-cache-dir --force-reinstall' docker-compose
exit_code=$?
set -e
if [ ${exit_code} -ne 0 ]; then
# Temporary: https://github.com/devcontainers/features/issues/616
# See https://github.com/yaml/pyyaml/issues/601
echo "(*) Failed to install docker-compose via pipx. Trying via pip3..."
export PYTHONUSERBASE=/usr/local
pip3 install --disable-pip-version-check --no-cache-dir --user "Cython<3.0" pyyaml wheel docker-compose --no-build-isolation
fi
rm -rf /tmp/pip-tmp docker_compose_path="/usr/local/bin/docker-compose"
if [ "${DOCKER_DASH_COMPOSE_VERSION}" = "v1" ]; then
err "The final Compose V1 release, version 1.29.2, was May 10, 2021. These packages haven't received any security updates since then. Use at your own risk."
INSTALL_DOCKER_COMPOSE_SWITCH="false"
if [ "${target_compose_arch}" = "x86_64" ]; then
echo "(*) Installing docker compose v1..."
curl -fsSL "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64" -o ${docker_compose_path}
chmod +x ${docker_compose_path}
# Download the SHA256 checksum
DOCKER_COMPOSE_SHA256="$(curl -sSL "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64.sha256" | awk '{print $1}')"
echo "${DOCKER_COMPOSE_SHA256} ${docker_compose_path}" > docker-compose.sha256sum
sha256sum -c docker-compose.sha256sum --ignore-missing
elif [ "${VERSION_CODENAME}" = "bookworm" ]; then
err "Docker compose v1 is unavailable for 'bookworm' on Arm64. Kindly switch to use v2"
exit 1
else else
compose_v1_version="1" # Use pip to get a version that runs on this architecture
find_version_from_git_tags compose_v1_version "https://github.com/docker/compose" "tags/" check_packages python3-minimal python3-pip libffi-dev python3-venv
echo "(*) Installing docker-compose ${compose_v1_version}..." echo "(*) Installing docker compose v1 via pip..."
curl -fsSL "https://github.com/docker/compose/releases/download/${compose_v1_version}/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose export PYTHONUSERBASE=/usr/local
chmod +x /usr/local/bin/docker-compose pip3 install --disable-pip-version-check --no-cache-dir --user "Cython<3.0" pyyaml wheel docker-compose --no-build-isolation
fi fi
else
compose_version=${DOCKER_DASH_COMPOSE_VERSION#v}
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}
chmod +x ${docker_compose_path}
# Download the SHA256 checksum
DOCKER_COMPOSE_SHA256="$(curl -sSL "https://github.com/docker/compose/releases/download/v${compose_version}/docker-compose-linux-${target_compose_arch}.sha256" | awk '{print $1}')"
echo "${DOCKER_COMPOSE_SHA256} ${docker_compose_path}" > docker-compose.sha256sum
sha256sum -c docker-compose.sha256sum --ignore-missing
mkdir -p ${cli_plugins_dir}
cp ${docker_compose_path} ${cli_plugins_dir}
fi fi
fi
# Install docker-compose switch if not already installed - https://github.com/docker/compose-switch#manual-installation # Install docker-compose switch if not already installed - https://github.com/docker/compose-switch#manual-installation
current_v1_compose_path="$(which docker-compose)" if [ "${INSTALL_DOCKER_COMPOSE_SWITCH}" = "true" ] && ! type compose-switch > /dev/null 2>&1; then
target_v1_compose_path="$(dirname "${current_v1_compose_path}")/docker-compose-v1" if type docker-compose > /dev/null 2>&1; then
if ! type compose-switch > /dev/null 2>&1; then
echo "(*) Installing compose-switch..." echo "(*) Installing compose-switch..."
current_compose_path="$(which docker-compose)"
target_compose_path="$(dirname "${current_compose_path}")/docker-compose-v1"
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/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
chmod +x /usr/local/bin/compose-switch chmod +x /usr/local/bin/compose-switch
# 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
# Setup v1 CLI as alternative in addition to compose-switch (which maps to v2) # Setup v1 CLI as alternative in addition to compose-switch (which maps to v2)
mv "${current_v1_compose_path}" "${target_v1_compose_path}" mv "${current_compose_path}" "${target_compose_path}"
update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/compose-switch 99 update-alternatives --install ${docker_compose_path} docker-compose /usr/local/bin/compose-switch 99
update-alternatives --install /usr/local/bin/docker-compose docker-compose "${target_v1_compose_path}" 1 update-alternatives --install ${docker_compose_path} docker-compose "${target_compose_path}" 1
fi
if [ "${DOCKER_DASH_COMPOSE_VERSION}" = "v1" ]; then
update-alternatives --set docker-compose "${target_v1_compose_path}"
else else
update-alternatives --set docker-compose /usr/local/bin/compose-switch err "Skipping installation of compose-switch as docker compose is unavailable..."
fi fi
fi fi
......
...@@ -9,8 +9,10 @@ source dev-container-features-test-lib ...@@ -9,8 +9,10 @@ source dev-container-features-test-lib
check "docker-buildx" docker buildx version check "docker-buildx" docker buildx version
check "docker-build" docker build ./ check "docker-build" docker build ./
check "installs docker-compose v1 install" bash -c "type docker-compose"
check "installs compose-switch" bash -c "[[ -f /usr/local/bin/compose-switch ]]" check "installs compose-switch" bash -c "[[ -f /usr/local/bin/compose-switch ]]"
check "docker compose" bash -c "docker compose version | grep -E '2.[0-9]+.[0-9]+'"
check "docker-compose" bash -c "docker-compose --version | grep -E '2.[0-9]+.[0-9]+'"
check "docker-buildx" bash -c "docker buildx version" check "docker-buildx" bash -c "docker buildx version"
check "docker-buildx-path" bash -c "ls -la /usr/libexec/docker/cli-plugins/docker-buildx" check "docker-buildx-path" bash -c "ls -la /usr/libexec/docker/cli-plugins/docker-buildx"
......
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "docker-compose" bash -c "docker-compose version | grep -E '1.[0-9]+.[0-9]+'"
# Report result
reportResults
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "docker compose" bash -c "docker compose version | grep -E '2.[0-9]+.[0-9]+'"
check "docker-compose" bash -c "docker-compose --version | grep -E '2.[0-9]+.[0-9]+'"
check "installs compose-switch as docker-compose" bash -c "[[ -f /usr/local/bin/docker-compose ]]"
check "installs compose-switch" bash -c "[[ -f /usr/local/bin/compose-switch ]]"
# Report result
reportResults
...@@ -87,6 +87,26 @@ ...@@ -87,6 +87,26 @@
} }
} }
}, },
"docker_compose_v1": {
"image": "mcr.microsoft.com/devcontainers/base:focal",
"features": {
"docker-in-docker": {
"moby": true,
"installDockerBuildx": true,
"dockerDashComposeVersion": "v1"
}
}
},
"docker_compose_v2": {
"image": "mcr.microsoft.com/devcontainers/base:focal",
"features": {
"docker-in-docker": {
"moby": true,
"installDockerBuildx": true,
"dockerDashComposeVersion": "v2"
}
}
},
"docker_build_fallback_buildx": { "docker_build_fallback_buildx": {
"image": "ubuntu:focal", "image": "ubuntu:focal",
"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