Skip to content

Commit e25228b

Browse files
authored
Merge branch 'main' into tfgrunt-terragrunt
2 parents 37b34bd + 302feca commit e25228b

23 files changed

Lines changed: 515 additions & 201 deletions

src/docker-outside-of-docker/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Re-use the host docker socket, adding the Docker CLI to a container. Feature inv
2222
| mobyBuildxVersion | Install a specific version of moby-buildx when using Moby | string | latest |
2323
| dockerDashComposeVersion | Compose version to use for docker-compose (v1 or v2 or none) | string | v2 |
2424
| installDockerBuildx | Install Docker Buildx | boolean | true |
25+
| installDockerComposeSwitch | 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. | boolean | true |
2526

2627
## Customizations
2728

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "docker-outside-of-docker",
3-
"version": "1.5.0",
3+
"version": "1.6.0",
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.",
@@ -39,6 +39,11 @@
3939
"type": "boolean",
4040
"default": true,
4141
"description": "Install Docker Buildx"
42+
},
43+
"installDockerComposeSwitch": {
44+
"type": "boolean",
45+
"default": true,
46+
"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."
4247
}
4348
},
4449
"entrypoint": "/usr/local/share/docker-init.sh",

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

Lines changed: 84 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ SOURCE_SOCKET="${SOURCE_SOCKET:-"/var/run/docker-host.sock"}"
1717
TARGET_SOCKET="${TARGET_SOCKET:-"/var/run/docker.sock"}"
1818
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
1919
INSTALL_DOCKER_BUILDX="${INSTALLDOCKERBUILDX:-"true"}"
20+
INSTALL_DOCKER_COMPOSE_SWITCH="${INSTALLDOCKERCOMPOSESWITCH:-"true"}"
2021

2122
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
2223
DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES="bookworm buster bullseye bionic focal jammy noble"
@@ -27,6 +28,11 @@ set -e
2728
# Clean up
2829
rm -rf /var/lib/apt/lists/*
2930

31+
# Setup STDERR.
32+
err() {
33+
echo "(!) $*" >&2
34+
}
35+
3036
if [ "$(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
274280
fi
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
277296
if type docker > /dev/null 2>&1; then
278297
echo "Docker / Moby CLI already installed."
@@ -302,44 +321,82 @@ fi
302321

303322
# If 'docker-compose' command is to be included
304323
if [ "${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
344401
fi
345402

src/git-lfs/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "git-lfs",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"name": "Git Large File Support (LFS)",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/git-lfs",
66
"description": "Installs Git Large File Support (Git LFS) along with needed dependencies. Useful for base Dockerfiles that often are missing required install dependencies like git and curl.",

src/git-lfs/install.sh

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,33 @@ find_version_from_git_tags() {
6262

6363
# Get the list of GPG key servers that are reachable
6464
get_gpg_key_servers() {
65-
declare -A keyservers_curl_map=(
66-
["hkp://keyserver.ubuntu.com"]="http://keyserver.ubuntu.com:11371"
67-
["hkp://keyserver.ubuntu.com:80"]="http://keyserver.ubuntu.com"
68-
["hkps://keys.openpgp.org"]="https://keys.openpgp.org"
69-
["hkp://keyserver.pgp.com"]="http://keyserver.pgp.com:11371"
70-
)
71-
7265
local curl_args=""
7366
local keyserver_reachable=false # Flag to indicate if any keyserver is reachable
7467

7568
if [ ! -z "${KEYSERVER_PROXY}" ]; then
7669
curl_args="--proxy ${KEYSERVER_PROXY}"
7770
fi
7871

79-
for keyserver in "${!keyservers_curl_map[@]}"; do
80-
local keyserver_curl_url="${keyservers_curl_map[${keyserver}]}"
81-
if curl -s ${curl_args} --max-time 5 ${keyserver_curl_url} > /dev/null; then
72+
test_keyserver() {
73+
local keyserver="$1"
74+
local keyserver_curl_url="$2"
75+
if curl -s ${curl_args} --max-time 5 "${keyserver_curl_url}" > /dev/null; then
8276
echo "keyserver ${keyserver}"
8377
keyserver_reachable=true
8478
else
8579
echo "(*) Keyserver ${keyserver} is not reachable." >&2
8680
fi
87-
done
81+
}
82+
83+
# Explicitly test these in order because Bash v4.4.20 (Ubuntu Bionic)
84+
# enumerates associative array keys in a different order than Bash v5
85+
test_keyserver "hkp://keyserver.ubuntu.com" "http://keyserver.ubuntu.com:11371"
86+
test_keyserver "hkp://keyserver.ubuntu.com:80" "http://keyserver.ubuntu.com"
87+
test_keyserver "hkp://keyserver.pgp.com" "http://keyserver.pgp.com:11371"
88+
# Test this server last because keys.openpgp.org strips user IDs from keys unless
89+
# the owner gives permission, which causes gpg in Ubuntu Bionic to reject the key
90+
# (https://github.com/devcontainers/features/issues/1055)
91+
test_keyserver "hkps://keys.openpgp.org" "https://keys.openpgp.org"
8892

8993
if ! $keyserver_reachable; then
9094
echo "(!) No keyserver is reachable." >&2

src/java/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "java",
3-
"version": "1.6.0",
3+
"version": "1.6.1",
44
"name": "Java (via SDKMAN!)",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/java",
66
"description": "Installs Java, SDKMAN! (if not installed), and needed dependencies.",

0 commit comments

Comments
 (0)