Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow moby-buildx version to be specified in devcontainer.json #838

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/docker-in-docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Create child containers *inside* a container, independent from the host's docker
|-----|-----|-----|-----|
| version | Select or enter a Docker/Moby Engine version. (Availability can vary by OS version.) | string | latest |
| moby | Install OSS Moby build instead of Docker CE | boolean | true |
| mobyBuildxVersion | Select or enter a Moby Buildx version. (Availability can vary by OS version.) | string | latest |
sayhiben marked this conversation as resolved.
Show resolved Hide resolved
| dockerDashComposeVersion | Default version of Docker Compose (v1 or v2 or none) | string | v1 |
| azureDnsAutoDetection | Allow automatically setting the dockerd DNS server when the installation script detects it is running in Azure | boolean | true |
| dockerDefaultAddressPool | Define default address pools for Docker networks. e.g. base=192.168.0.0/16,size=24 | string | - |
Expand Down
22 changes: 16 additions & 6 deletions src/docker-in-docker/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

DOCKER_VERSION="${VERSION:-"latest"}" # The Docker/Moby Engine + CLI should match in version
USE_MOBY="${MOBY:-"true"}"
MOBY_BUILDX_VERSION="${MOBYBUILDXVERSION:-"latest"}"
sayhiben marked this conversation as resolved.
Show resolved Hide resolved
sayhiben marked this conversation as resolved.
Show resolved Hide resolved
sayhiben marked this conversation as resolved.
Show resolved Hide resolved
DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"v1"}" # v1 or v2 or none
AZURE_DNS_AUTO_DETECTION="${AZUREDNSAUTODETECTION:-"true"}"
DOCKER_DEFAULT_ADDRESS_POOL="${DOCKERDEFAULTADDRESSPOOL}"
Expand Down Expand Up @@ -81,7 +82,7 @@ find_version_from_git_tags() {
local repository=$2
local prefix=${3:-"tags/v"}
local separator=${4:-"."}
local last_part_optional=${5:-"false"}
local last_part_optional=${5:-"false"}
if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then
local escaped_separator=${separator//./\\.}
local last_part
Expand Down Expand Up @@ -198,14 +199,23 @@ else
echo "cli_version_suffix ${cli_version_suffix}"
fi

# Buildx version matching
if [ "${MOBY_BUILDX_VERSION}" = "latest" ]; then
# Empty, meaning grab whatever "latest" is in apt repo
buildx_version_suffix=""
else
buildx_version_suffix="=${MOBY_BUILDX_VERSION}"
echo "buildx_version_suffix ${buildx_version_suffix}"
fi

sayhiben marked this conversation as resolved.
Show resolved Hide resolved
# Install Docker / Moby CLI if not already installed
if type docker > /dev/null 2>&1 && type dockerd > /dev/null 2>&1; then
echo "Docker / Moby CLI and Engine already installed."
else
if [ "${USE_MOBY}" = "true" ]; then
# Install engine
set +e # Handle error gracefully
apt-get -y install --no-install-recommends moby-cli${cli_version_suffix} moby-buildx moby-engine${engine_version_suffix}
apt-get -y install --no-install-recommends moby-cli${cli_version_suffix} moby-buildx${buildx_version_suffix} moby-engine${engine_version_suffix}
if [ $? -ne 0 ]; then
err "Packages for moby not available in OS ${ID} ${VERSION_CODENAME} (${architecture}). To resolve, either: (1) set feature option '\"moby\": false' , or (2) choose a compatible OS version (eg: 'ubuntu-20.04')."
exit 1
Expand Down Expand Up @@ -399,7 +409,7 @@ dockerd_start="AZURE_DNS_AUTO_DETECTION=${AZURE_DNS_AUTO_DETECTION} DOCKER_DEFAU

retry_cgroup_nesting=`expr $retry_cgroup_nesting + 1`
set -e
done
done

# -- End: dind wrapper script --

Expand Down Expand Up @@ -442,7 +452,7 @@ retry_docker_start_count=0
docker_ok="false"

until [ "${docker_ok}" = "true" ] || [ "${retry_docker_start_count}" -eq "5" ];
do
do
# Start using sudo if not invoked as root
if [ "$(id -u)" -ne 0 ]; then
sudo /bin/sh -c "${dockerd_start}"
Expand All @@ -460,15 +470,15 @@ do

retry_count=`expr $retry_count + 1`
done

if [ "${docker_ok}" != "true" ] && [ "${retry_docker_start_count}" != "4" ]; then
echo "(*) Failed to start docker, retrying..."
set +e
sudo_if pkill dockerd
sudo_if pkill containerd
set -e
fi

retry_docker_start_count=`expr $retry_docker_start_count + 1`
done

Expand Down
Loading