Skip to content

Commit

Permalink
Docker-outside-of-docker: Fix moby-buildx errors (#843)
Browse files Browse the repository at this point in the history
* Docker-outside-of-docker: Fix moby-buildx errors

* test debugging

* fix test

* nit
  • Loading branch information
samruddhikhandale authored Feb 12, 2024
1 parent fc62e9a commit e05b0b8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/docker-outside-of-docker/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "docker-outside-of-docker",
"version": "1.3.2",
"version": "1.4.0",
"name": "Docker (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.",
Expand All @@ -20,6 +20,11 @@
"default": true,
"description": "Install OSS Moby build instead of Docker CE"
},
"mobyBuildxVersion": {
"type": "string",
"default": "0.12.0",
"description": "Install a specific version of moby-buildx when using Moby. (2024-02-09: Microsoft's Package Manifest has mismatching filesize and SHA for 0.12.1; default is last known good version)"
},
"dockerDashComposeVersion": {
"type": "string",
"enum": [
Expand Down
24 changes: 23 additions & 1 deletion src/docker-outside-of-docker/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

DOCKER_VERSION="${VERSION:-"latest"}"
USE_MOBY="${MOBY:-"true"}"
MOBY_BUILDX_VERSION="${MOBYBUILDXVERSION}"
DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"v1"}" # v1 or v2 or none

ENABLE_NONROOT_DOCKER="${ENABLE_NONROOT_DOCKER:-"true"}"
Expand Down Expand Up @@ -170,14 +171,35 @@ else
echo "cli_version_suffix ${cli_version_suffix}"
fi

# Version matching for moby-buildx
if [ "${USE_MOBY}" = "true" ]; then
if [ "${MOBY_BUILDX_VERSION}" = "latest" ]; then
# Empty, meaning grab whatever "latest" is in apt repo
buildx_version_suffix=""
else
buildx_version_dot_escaped="${MOBY_BUILDX_VERSION//./\\.}"
buildx_version_dot_plus_escaped="${buildx_version_dot_escaped//+/\\+}"
buildx_version_regex="^(.+:)?${buildx_version_dot_plus_escaped}([\\.\\+ ~:-]|$)"
set +e
buildx_version_suffix="=$(apt-cache madison moby-buildx | awk -F"|" '{print $2}' | sed -e 's/^[ \t]*//' | grep -E -m 1 "${buildx_version_regex}")"
set -e
if [ -z "${buildx_version_suffix}" ] || [ "${buildx_version_suffix}" = "=" ]; then
err "No full or partial moby-buildx version match found for \"${MOBY_BUILDX_VERSION}\" on OS ${ID} ${VERSION_CODENAME} (${architecture}). Available versions:"
apt-cache madison moby-buildx | awk -F"|" '{print $2}' | grep -oP '^(.+:)?\K.+'
exit 1
fi
echo "buildx_version_suffix ${buildx_version_suffix}"
fi
fi

# Install Docker / Moby CLI if not already installed
if type docker > /dev/null 2>&1; then
echo "Docker / Moby CLI already installed."
else
if [ "${USE_MOBY}" = "true" ]; then
buildx=()
if [ "${INSTALL_DOCKER_BUILDX}" = "true" ]; then
buildx=(moby-buildx)
buildx=(moby-buildx${buildx_version_suffix})
fi
apt-get -y install --no-install-recommends ${cli_package_name}${cli_version_suffix} "${buildx[@]}"
apt-get -y install --no-install-recommends moby-compose || echo "(*) Package moby-compose (Docker Compose v2) not available for OS ${ID} ${VERSION_CODENAME} (${architecture}). Skipping."
Expand Down
3 changes: 2 additions & 1 deletion test/docker-outside-of-docker/docker_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ check "docker-compose" bash -c "docker-compose --version"
check "docker-init-exists" bash -c "ls /usr/local/share/docker-init.sh"
check "log-exists" bash -c "ls /tmp/vscr-docker-from-docker.log"
check "log-contents-for-success" bash -c "cat /tmp/vscr-docker-from-docker.log | grep 'Success'"
check "log-contents" bash -c "cat /tmp/vscr-docker-from-docker.log | grep 'Proxying /var/run/docker-host.sock to /var/run/docker.sock for vscode'"

check "log-contents" bash -c "cat /tmp/vscr-docker-from-docker.log | grep 'Ensuring vscode has access to /var/run/docker-host.sock via /var/run/docker.sock'"
check "docker-ps" bash -c "docker ps >/dev/null"

# Report result
Expand Down

0 comments on commit e05b0b8

Please sign in to comment.