@@ -17,6 +17,7 @@ SOURCE_SOCKET="${SOURCE_SOCKET:-"/var/run/docker-host.sock"}"
1717TARGET_SOCKET=" ${TARGET_SOCKET:- " /var/run/docker.sock" } "
1818USERNAME=" ${USERNAME:- " ${_REMOTE_USER:- " automatic" } " } "
1919INSTALL_DOCKER_BUILDX=" ${INSTALLDOCKERBUILDX:- " true" } "
20+ INSTALL_DOCKER_COMPOSE_SWITCH=" ${INSTALLDOCKERCOMPOSESWITCH:- " true" } "
2021
2122MICROSOFT_GPG_KEYS_URI=" https://packages.microsoft.com/keys/microsoft.asc"
2223DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES=" bookworm buster bullseye bionic focal jammy noble"
@@ -27,6 +28,11 @@ set -e
2728# Clean up
2829rm -rf /var/lib/apt/lists/*
2930
31+ # Setup STDERR.
32+ err () {
33+ echo " (!) $* " >&2
34+ }
35+
3036if [ " $( id -u) " -ne 0 ]; then
3137 echo -e ' Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
3238 exit 1
@@ -177,7 +183,7 @@ install_compose_switch_fallback() {
177183 echo -e " \n(!) Failed to fetch the latest artifacts for compose-switch v${compose_switch_version} ..."
178184 get_previous_version " ${compose_switch_url} " " ${repo_url} " compose_switch_version
179185 echo -e " \nAttempting to install v${compose_switch_version} "
180- curl -fsSL " https://github.com/docker/compose-switch/releases/download/v${compose_switch_version} /docker-compose-linux-${architecture} " -o /usr/local/bin/docker- compose
186+ curl -fsSL " https://github.com/docker/compose-switch/releases/download/v${compose_switch_version} /docker-compose-linux-${architecture} " -o /usr/local/bin/compose-switch
181187}
182188
183189# Ensure apt is in non-interactive to avoid prompts
@@ -273,6 +279,19 @@ if [ "${USE_MOBY}" = "true" ]; then
273279 fi
274280fi
275281
282+
283+ docker_home=" /usr/libexec/docker"
284+ cli_plugins_dir=" ${docker_home} /cli-plugins"
285+
286+ install_compose_fallback (){
287+ local url=$1
288+ local repo_url=$( get_github_api_repo_url " $url " )
289+ echo -e " \n(!) Failed to fetch the latest artifacts for docker-compose v${compose_version} ..."
290+ get_previous_version " ${url} " " ${repo_url} " compose_version
291+ echo -e " \nAttempting to install v${compose_version} "
292+ curl -fsSL " https://github.com/docker/compose/releases/download/v${compose_version} /docker-compose-linux-${target_compose_arch} " -o ${docker_compose_path}
293+ }
294+
276295# Install Docker / Moby CLI if not already installed
277296if type docker > /dev/null 2>&1 ; then
278297 echo " Docker / Moby CLI already installed."
302321
303322# If 'docker-compose' command is to be included
304323if [ " ${DOCKER_DASH_COMPOSE_VERSION} " != " none" ]; then
324+ case " ${architecture} " in
325+ amd64) target_compose_arch=x86_64 ;;
326+ arm64) target_compose_arch=aarch64 ;;
327+ * )
328+ echo " (!) Docker outside of docker does not support machine architecture '$architecture '. Please use an x86-64 or ARM64 machine."
329+ exit 1
330+ esac
331+ docker_compose_path=" /usr/local/bin/docker-compose"
305332 # Install Docker Compose if not already installed and is on a supported architecture
306333 if type docker-compose > /dev/null 2>&1 ; then
307334 echo " Docker Compose already installed."
308335 elif [ " ${DOCKER_DASH_COMPOSE_VERSION} " = " v1" ]; then
309- TARGET_COMPOSE_ARCH=" $( uname -m) "
310- if [ " ${TARGET_COMPOSE_ARCH} " = " amd64" ]; then
311- TARGET_COMPOSE_ARCH=" x86_64"
312- fi
313- if [ " ${TARGET_COMPOSE_ARCH} " != " x86_64" ]; then
336+ 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."
337+ INSTALL_DOCKER_COMPOSE_SWITCH=" false"
338+
339+ if [ " ${target_compose_arch} " = " x86_64" ]; then
340+ echo " (*) Installing docker compose v1..."
341+ curl -fsSL " https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64" -o ${docker_compose_path}
342+ chmod +x ${docker_compose_path}
343+
344+ # Download the SHA256 checksum
345+ DOCKER_COMPOSE_SHA256=" $( curl -sSL " https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64.sha256" | awk ' {print $1}' ) "
346+ echo " ${DOCKER_COMPOSE_SHA256} ${docker_compose_path} " > docker-compose.sha256sum
347+ sha256sum -c docker-compose.sha256sum --ignore-missing
348+ elif [ " ${VERSION_CODENAME} " = " bookworm" ]; then
349+ err " Docker compose v1 is unavailable for 'bookworm' on Arm64. Kindly switch to use v2"
350+ exit 1
351+ else
314352 # Use pip to get a version that runs on this architecture
315353 check_packages python3-minimal python3-pip libffi-dev python3-venv
316- export PIPX_HOME=/usr/local/pipx
317- mkdir -p ${PIPX_HOME}
318- export PIPX_BIN_DIR=/usr/local/bin
319- export PYTHONUSERBASE=/tmp/pip-tmp
320- export PIP_CACHE_DIR=/tmp/pip-tmp/cache
321- pipx_bin=pipx
322- if ! type pipx > /dev/null 2>&1 ; then
323- pip3 install --disable-pip-version-check --no-cache-dir --user pipx
324- pipx_bin=/tmp/pip-tmp/bin/pipx
325- fi
326- ${pipx_bin} install --pip-args ' --no-cache-dir --force-reinstall' docker-compose
327- rm -rf /tmp/pip-tmp
328- else
329- compose_v1_version=" 1"
330- find_version_from_git_tags compose_v1_version " https://github.com/docker/compose" " tags/"
331- echo " (*) Installing docker-compose ${compose_v1_version} ..."
332- curl -fsSL " https://github.com/docker/compose/releases/download/${compose_v1_version} /docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
333- chmod +x /usr/local/bin/docker-compose
354+ echo " (*) Installing docker compose v1 via pip..."
355+ export PYTHONUSERBASE=/usr/local
356+ pip3 install --disable-pip-version-check --no-cache-dir --user " Cython<3.0" pyyaml wheel docker-compose --no-build-isolation
334357 fi
335358 else
336- echo " (*) Installing compose-switch as docker-compose..."
359+ compose_version=${DOCKER_DASH_COMPOSE_VERSION# v}
360+ docker_compose_url=" https://github.com/docker/compose"
361+ find_version_from_git_tags compose_version " $docker_compose_url " " tags/v"
362+ echo " (*) Installing docker-compose ${compose_version} ..."
363+ 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
369+ }
370+ chmod +x ${docker_compose_path}
371+
372+ # Download the SHA256 checksum
373+ 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}' ) "
374+ echo " ${DOCKER_COMPOSE_SHA256} ${docker_compose_path} " > docker-compose.sha256sum
375+ sha256sum -c docker-compose.sha256sum --ignore-missing
376+
377+ mkdir -p ${cli_plugins_dir}
378+ cp ${docker_compose_path} ${cli_plugins_dir}
379+ fi
380+ fi
381+
382+ # Install docker-compose switch if not already installed - https://github.com/docker/compose-switch#manual-installation
383+ if [ " ${INSTALL_DOCKER_COMPOSE_SWITCH} " = " true" ] && ! type compose-switch > /dev/null 2>&1 ; then
384+ if type docker-compose > /dev/null 2>&1 ; then
385+ echo " (*) Installing compose-switch..."
386+ current_compose_path=" $( which docker-compose) "
387+ target_compose_path=" $( dirname " ${current_compose_path} " ) /docker-compose-v1"
337388 compose_switch_version=" latest"
338389 compose_switch_url=" https://github.com/docker/compose-switch"
339390 find_version_from_git_tags compose_switch_version " ${compose_switch_url} "
340- 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 " ${compose_switch_url} "
341- chmod +x /usr/local/bin/docker- compose
391+ curl -fsSL " https://github.com/docker/compose-switch/releases/download/v${compose_switch_version} /docker-compose-linux-${architecture} " -o /usr/local/bin/compose-switch || install_compose_switch_fallback " ${compose_switch_url} "
392+ chmod +x /usr/local/bin/compose-switch
342393 # TODO: Verify checksum once available: https://github.com/docker/compose-switch/issues/11
394+ # Setup v1 CLI as alternative in addition to compose-switch (which maps to v2)
395+ mv " ${current_compose_path} " " ${target_compose_path} "
396+ update-alternatives --install ${docker_compose_path} docker-compose /usr/local/bin/compose-switch 99
397+ update-alternatives --install ${docker_compose_path} docker-compose " ${target_compose_path} " 1
398+ else
399+ err " Skipping installation of compose-switch as docker compose is unavailable..."
343400 fi
344401fi
345402
0 commit comments