aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorM. R <2947595+m-roberts@users.noreply.github.com>2023-05-02 22:00:45 +0300
committerGitHub <noreply@github.com>2023-05-02 22:00:45 +0300
commit4312340798680a2b148847b124fcf737e5839c2e (patch)
tree60685df52a1f8b197a78e0dffa553ccb0463ba4f
parentb16ff1efb7b092c73ab1e13c3d016d1ab7a9e4b6 (diff)
Add support for skipping `docker-compose` v1 operations during Docker feature install script (#533)feature_docker-outside-of-docker_1.3.0feature_docker-in-docker_2.2.0
* Add support for skipping docker-compose operations * Move changes from auto-generated files to templates and bump version * Add test * Add test conditions * Add test conditions for docker-outside-of-docker * install.sh set -x for debugging * set -x * Move compose-switch check in docker-outside-of-docker test * Put into correct test * Test for correct path
-rw-r--r--src/docker-in-docker/devcontainer-feature.json5
-rwxr-xr-xsrc/docker-in-docker/install.sh103
-rw-r--r--src/docker-outside-of-docker/devcontainer-feature.json5
-rwxr-xr-xsrc/docker-outside-of-docker/install.sh71
-rwxr-xr-x[-rw-r--r--]test/docker-in-docker/docker_build.sh3
-rwxr-xr-xtest/docker-in-docker/docker_build_no_compose.sh16
-rw-r--r--test/docker-in-docker/scenarios.json10
-rwxr-xr-x[-rw-r--r--]test/docker-outside-of-docker/docker_build.sh2
-rwxr-xr-xtest/docker-outside-of-docker/docker_build_no_compose.sh15
-rwxr-xr-xtest/docker-outside-of-docker/docker_dash_compose_v2.sh2
-rw-r--r--test/docker-outside-of-docker/scenarios.json9
11 files changed, 153 insertions, 88 deletions
diff --git a/src/docker-in-docker/devcontainer-feature.json b/src/docker-in-docker/devcontainer-feature.json
index 798b8e8..1555cd6 100644
--- a/src/docker-in-docker/devcontainer-feature.json
+++ b/src/docker-in-docker/devcontainer-feature.json
@@ -1,6 +1,6 @@
{
"id": "docker-in-docker",
- "version": "2.1.0",
+ "version": "2.2.0",
"name": "Docker (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.",
@@ -23,11 +23,12 @@
"dockerDashComposeVersion": {
"type": "string",
"enum": [
+ "none",
"v1",
"v2"
],
"default": "v1",
- "description": "Default version of Docker Compose (v1 or v2)"
+ "description": "Default version of Docker Compose (v1 or v2 or none)"
},
"azureDnsAutoDetection": {
"type": "boolean",
diff --git a/src/docker-in-docker/install.sh b/src/docker-in-docker/install.sh
index 7705199..9ad807e 100755
--- a/src/docker-in-docker/install.sh
+++ b/src/docker-in-docker/install.sh
@@ -10,7 +10,7 @@
DOCKER_VERSION="${VERSION:-"latest"}" # The Docker/Moby Engine + CLI should match in version
USE_MOBY="${MOBY:-"true"}"
-DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"v1"}" # v1 or v2
+DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"v1"}" # v1 or v2 or none
AZURE_DNS_AUTO_DETECTION="${AZUREDNSAUTODETECTION:-"true"}"
DOCKER_DEFAULT_ADDRESS_POOL="${DOCKERDEFAULTADDRESSPOOL}"
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
@@ -242,58 +242,61 @@ fi
echo "Finished installing docker / moby!"
-# Install Docker Compose if not already installed and is on a supported architecture
-if type docker-compose > /dev/null 2>&1; then
- echo "Docker Compose v1 already installed."
-else
- target_compose_arch="${architecture}"
- if [ "${target_compose_arch}" = "amd64" ]; then
- target_compose_arch="x86_64"
- fi
- if [ "${target_compose_arch}" != "x86_64" ]; 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
- ${pipx_bin} install --pip-args '--no-cache-dir --force-reinstall' docker-compose
- rm -rf /tmp/pip-tmp
+# If 'docker-compose' command is to be included
+if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then
+ # Install Docker Compose if not already installed and is on a supported architecture
+ if type docker-compose > /dev/null 2>&1; then
+ echo "Docker Compose v1 already installed."
else
- compose_v1_version="1"
- find_version_from_git_tags compose_v1_version "https://github.com/docker/compose" "tags/"
- echo "(*) Installing docker-compose ${compose_v1_version}..."
- curl -fsSL "https://github.com/docker/compose/releases/download/${compose_v1_version}/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
+ target_compose_arch="${architecture}"
+ if [ "${target_compose_arch}" = "amd64" ]; then
+ target_compose_arch="x86_64"
+ fi
+ if [ "${target_compose_arch}" != "x86_64" ]; 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
+ ${pipx_bin} install --pip-args '--no-cache-dir --force-reinstall' docker-compose
+ rm -rf /tmp/pip-tmp
+ else
+ compose_v1_version="1"
+ find_version_from_git_tags compose_v1_version "https://github.com/docker/compose" "tags/"
+ echo "(*) Installing docker-compose ${compose_v1_version}..."
+ curl -fsSL "https://github.com/docker/compose/releases/download/${compose_v1_version}/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
+ chmod +x /usr/local/bin/docker-compose
+ fi
fi
-fi
-# Install docker-compose switch if not already installed - https://github.com/docker/compose-switch#manual-installation
-current_v1_compose_path="$(which docker-compose)"
-target_v1_compose_path="$(dirname "${current_v1_compose_path}")/docker-compose-v1"
-if ! type compose-switch > /dev/null 2>&1; then
- echo "(*) Installing compose-switch..."
- compose_switch_version="latest"
- 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
- chmod +x /usr/local/bin/compose-switch
- # 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)
- mv "${current_v1_compose_path}" "${target_v1_compose_path}"
- update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/compose-switch 99
- update-alternatives --install /usr/local/bin/docker-compose docker-compose "${target_v1_compose_path}" 1
-fi
-if [ "${DOCKER_DASH_COMPOSE_VERSION}" = "v1" ]; then
- update-alternatives --set docker-compose "${target_v1_compose_path}"
-else
- update-alternatives --set docker-compose /usr/local/bin/compose-switch
+ # Install docker-compose switch if not already installed - https://github.com/docker/compose-switch#manual-installation
+ current_v1_compose_path="$(which docker-compose)"
+ target_v1_compose_path="$(dirname "${current_v1_compose_path}")/docker-compose-v1"
+ if ! type compose-switch > /dev/null 2>&1; then
+ echo "(*) Installing compose-switch..."
+ compose_switch_version="latest"
+ 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
+ chmod +x /usr/local/bin/compose-switch
+ # 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)
+ mv "${current_v1_compose_path}" "${target_v1_compose_path}"
+ update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/compose-switch 99
+ update-alternatives --install /usr/local/bin/docker-compose docker-compose "${target_v1_compose_path}" 1
+ fi
+ if [ "${DOCKER_DASH_COMPOSE_VERSION}" = "v1" ]; then
+ update-alternatives --set docker-compose "${target_v1_compose_path}"
+ else
+ update-alternatives --set docker-compose /usr/local/bin/compose-switch
+ fi
fi
# If init file already exists, exit
diff --git a/src/docker-outside-of-docker/devcontainer-feature.json b/src/docker-outside-of-docker/devcontainer-feature.json
index 2b75aa4..d3123fa 100644
--- a/src/docker-outside-of-docker/devcontainer-feature.json
+++ b/src/docker-outside-of-docker/devcontainer-feature.json
@@ -1,6 +1,6 @@
{
"id": "docker-outside-of-docker",
- "version": "1.2.1",
+ "version": "1.3.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.",
@@ -23,11 +23,12 @@
"dockerDashComposeVersion": {
"type": "string",
"enum": [
+ "none",
"v1",
"v2"
],
"default": "v2",
- "description": "Compose version to use for docker-compose (v1 or v2)"
+ "description": "Compose version to use for docker-compose (v1 or v2 or none)"
},
"installDockerBuildx": {
"type": "boolean",
diff --git a/src/docker-outside-of-docker/install.sh b/src/docker-outside-of-docker/install.sh
index f32db2f..7bf2138 100755
--- a/src/docker-outside-of-docker/install.sh
+++ b/src/docker-outside-of-docker/install.sh
@@ -9,7 +9,7 @@
DOCKER_VERSION="${VERSION:-"latest"}"
USE_MOBY="${MOBY:-"true"}"
-DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"v2"}" # v1 or v2
+DOCKER_DASH_COMPOSE_VERSION="${DOCKERDASHCOMPOSEVERSION:-"v1"}" # v1 or v2 or none
ENABLE_NONROOT_DOCKER="${ENABLE_NONROOT_DOCKER:-"true"}"
SOURCE_SOCKET="${SOURCE_SOCKET:-"/var/run/docker-host.sock"}"
@@ -216,43 +216,46 @@ else
unset buildx buildx_path
fi
-# Install Docker Compose if not already installed and is on a supported architecture
-if type docker-compose > /dev/null 2>&1; then
- echo "Docker Compose already installed."
-elif [ "${DOCKER_DASH_COMPOSE_VERSION}" = "v1" ]; then
- TARGET_COMPOSE_ARCH="$(uname -m)"
- if [ "${TARGET_COMPOSE_ARCH}" = "amd64" ]; then
- TARGET_COMPOSE_ARCH="x86_64"
- fi
- if [ "${TARGET_COMPOSE_ARCH}" != "x86_64" ]; 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
+# If 'docker-compose' command is to be included
+if [ "${DOCKER_DASH_COMPOSE_VERSION}" != "none" ]; then
+ # Install Docker Compose if not already installed and is on a supported architecture
+ if type docker-compose > /dev/null 2>&1; then
+ echo "Docker Compose already installed."
+ elif [ "${DOCKER_DASH_COMPOSE_VERSION}" = "v1" ]; then
+ TARGET_COMPOSE_ARCH="$(uname -m)"
+ if [ "${TARGET_COMPOSE_ARCH}" = "amd64" ]; then
+ TARGET_COMPOSE_ARCH="x86_64"
+ fi
+ if [ "${TARGET_COMPOSE_ARCH}" != "x86_64" ]; 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
+ ${pipx_bin} install --pip-args '--no-cache-dir --force-reinstall' docker-compose
+ rm -rf /tmp/pip-tmp
+ else
+ compose_v1_version="1"
+ find_version_from_git_tags compose_v1_version "https://github.com/docker/compose" "tags/"
+ echo "(*) Installing docker-compose ${compose_v1_version}..."
+ curl -fsSL "https://github.com/docker/compose/releases/download/${compose_v1_version}/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
+ chmod +x /usr/local/bin/docker-compose
fi
- ${pipx_bin} install --pip-args '--no-cache-dir --force-reinstall' docker-compose
- rm -rf /tmp/pip-tmp
else
- compose_v1_version="1"
- find_version_from_git_tags compose_v1_version "https://github.com/docker/compose" "tags/"
- echo "(*) Installing docker-compose ${compose_v1_version}..."
- curl -fsSL "https://github.com/docker/compose/releases/download/${compose_v1_version}/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
+ echo "(*) Installing compose-switch as docker-compose..."
+ compose_switch_version="latest"
+ 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/docker-compose
chmod +x /usr/local/bin/docker-compose
+ # TODO: Verify checksum once available: https://github.com/docker/compose-switch/issues/11
fi
-else
- echo "(*) Installing compose-switch as docker-compose..."
- compose_switch_version="latest"
- 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/docker-compose
- chmod +x /usr/local/bin/docker-compose
- # TODO: Verify checksum once available: https://github.com/docker/compose-switch/issues/11
fi
# Setup a docker group in the event the docker socket's group is not root
diff --git a/test/docker-in-docker/docker_build.sh b/test/docker-in-docker/docker_build.sh
index 742b222..d51e7d6 100644..100755
--- a/test/docker-in-docker/docker_build.sh
+++ b/test/docker-in-docker/docker_build.sh
@@ -9,5 +9,8 @@ source dev-container-features-test-lib
check "docker-buildx" docker buildx version
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 ]]"
+
# Report result
reportResults
diff --git a/test/docker-in-docker/docker_build_no_compose.sh b/test/docker-in-docker/docker_build_no_compose.sh
new file mode 100755
index 0000000..e913be3
--- /dev/null
+++ b/test/docker-in-docker/docker_build_no_compose.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+set -e
+
+# Optional: Import test library
+source dev-container-features-test-lib
+
+# Definition specific tests
+check "docker-buildx" docker buildx version
+check "docker-build" docker build ./
+
+check "not installing compose skips docker-compose v1 install" bash -c "! type docker-compose"
+check "not installing compose skips compose-switch" bash -c "[[ ! -f /usr/local/bin/compose-switch ]]"
+
+# Report result
+reportResults
diff --git a/test/docker-in-docker/scenarios.json b/test/docker-in-docker/scenarios.json
index 5123d09..9c44478 100644
--- a/test/docker-in-docker/scenarios.json
+++ b/test/docker-in-docker/scenarios.json
@@ -58,5 +58,15 @@
}
},
"remoteUser": "node"
+ },
+ "docker_build_no_compose": {
+ "image": "mcr.microsoft.com/devcontainers/javascript-node:0-18",
+ "features": {
+ "docker-in-docker": {
+ "dockerDashComposeVersion": "none"
+ }
+ },
+ "remoteUser": "node"
}
+
}
diff --git a/test/docker-outside-of-docker/docker_build.sh b/test/docker-outside-of-docker/docker_build.sh
index 742b222..056a764 100644..100755
--- a/test/docker-outside-of-docker/docker_build.sh
+++ b/test/docker-outside-of-docker/docker_build.sh
@@ -9,5 +9,7 @@ source dev-container-features-test-lib
check "docker-buildx" docker buildx version
check "docker-build" docker build ./
+check "installs docker-compose v1 install" bash -c "type docker-compose"
+
# Report result
reportResults
diff --git a/test/docker-outside-of-docker/docker_build_no_compose.sh b/test/docker-outside-of-docker/docker_build_no_compose.sh
new file mode 100755
index 0000000..477bf21
--- /dev/null
+++ b/test/docker-outside-of-docker/docker_build_no_compose.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+set -e
+
+# Optional: Import test library
+source dev-container-features-test-lib
+
+# Definition specific tests
+check "docker-buildx" docker buildx version
+check "docker-build" docker build ./
+
+check "not installing compose skips docker-compose v1 install" bash -c "! type docker-compose"
+
+# Report result
+reportResults
diff --git a/test/docker-outside-of-docker/docker_dash_compose_v2.sh b/test/docker-outside-of-docker/docker_dash_compose_v2.sh
index 8f2a104..b24238f 100755
--- a/test/docker-outside-of-docker/docker_dash_compose_v2.sh
+++ b/test/docker-outside-of-docker/docker_dash_compose_v2.sh
@@ -9,5 +9,7 @@ source dev-container-features-test-lib
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 ]]"
+
# Report result
reportResults
diff --git a/test/docker-outside-of-docker/scenarios.json b/test/docker-outside-of-docker/scenarios.json
index be63470..3b82c6c 100644
--- a/test/docker-outside-of-docker/scenarios.json
+++ b/test/docker-outside-of-docker/scenarios.json
@@ -115,5 +115,14 @@
}
},
"containerUser": "vscode"
+ },
+ "docker_build_no_compose": {
+ "image": "mcr.microsoft.com/devcontainers/javascript-node:0-18",
+ "features": {
+ "docker-in-docker": {
+ "dockerDashComposeVersion": "none"
+ }
+ },
+ "remoteUser": "node"
}
}