Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit f19462a

Browse files
authored
Add compose-switch in prep for v2 GA (#1383)
1 parent bcdb9ef commit f19462a

File tree

7 files changed

+87
-21
lines changed

7 files changed

+87
-21
lines changed

script-library/container-features/src/devcontainer-features.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
"type": "boolean",
1717
"default": true,
1818
"description": "Install OSS Moby build instead of Docker CE"
19+
},
20+
"dockerDashComposeVersion": {
21+
"type": "string",
22+
"enum": ["v1", "v2" ],
23+
"default": "v1",
24+
"description": "Default version of Docker Compose (v1 or v2)"
1925
}
2026
},
2127
"buildArg": "_VSC_INSTALL_DOCKER_IN_DOCKER",
@@ -71,6 +77,17 @@
7177
"proposals": ["latest", "20.10"],
7278
"default": "latest",
7379
"description": "Select or enter a Docker/Moby CLI version. (Availability can vary by OS version.)"
80+
},
81+
"moby": {
82+
"type": "boolean",
83+
"default": true,
84+
"description": "Install OSS Moby build instead of Docker CE"
85+
},
86+
"dockerDashComposeVersion": {
87+
"type": "string",
88+
"enum": ["v1", "v2" ],
89+
"default": "v1",
90+
"description": "Compose version to use for docker-compose (v1 or v2)"
7491
}
7592
},
7693
"buildArg": "_VSC_INSTALL_DOCKER_FROM_DOCKER",

script-library/container-features/src/feature-scripts.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
_VSC_INSTALL_COMMON="common-debian.sh ${_BUILD_ARG_COMMON_INSTALLZSH} ${_BUILD_ARG_COMMON_USERNAME} ${_BUILD_ARG_COMMON_UID} ${_BUILD_ARG_COMMON_GID} ${_BUILD_ARG_COMMON_UPGRADEPACKAGES} ${_BUILD_ARG_COMMON_INSTALLOHMYZSH} ${_BUILD_ARG_COMMON_NONFREEPACKAGES}"
22
_VSC_INSTALL_GIT="git-from-src-debian.sh ${_BUILD_ARG_GIT_VERSION:-latest} ${_BUILD_ARG_GIT_PPA:-true}"
33
_VSC_INSTALL_GIT_LFS="git-lfs-debian.sh ${_BUILD_ARG_GIT_LFS_VERSION:-latest}"
4-
_VSC_INSTALL_DOCKER_IN_DOCKER="docker-in-docker-debian.sh true automatic ${_BUILD_ARG_DOCKER_IN_DOCKER_MOBY:-true} ${_BUILD_ARG_DOCKER_IN_DOCKER_VERSION:-latest}"
5-
_VSC_INSTALL_DOCKER_FROM_DOCKER="docker-debian.sh true /var/run/docker-host.sock /var/run/docker.sock automatic ${_BUILD_ARG_DOCKER_FROM_DOCKER_MOBY:-true} ${_BUILD_ARG_DOCKER_FROM_DOCKER_VERSION:-latest}"
4+
_VSC_INSTALL_DOCKER_IN_DOCKER="docker-in-docker-debian.sh true automatic ${_BUILD_ARG_DOCKER_IN_DOCKER_MOBY:-true} ${_BUILD_ARG_DOCKER_IN_DOCKER_VERSION:-latest} ${_BUILD_ARG_DOCKER_IN_DOCKER_DOCKERDASHCOMPOSEVERSION:-v1}"
5+
_VSC_INSTALL_DOCKER_FROM_DOCKER="docker-debian.sh true /var/run/docker-host.sock /var/run/docker.sock automatic ${_BUILD_ARG_DOCKER_FROM_DOCKER_MOBY:-true} ${_BUILD_ARG_DOCKER_FROM_DOCKER_VERSION:-latest} ${_BUILD_ARG_DOCKER_FROM_DOCKER_DOCKERDASHCOMPOSEVERSION:-v1}"
66
_VSC_INSTALL_KUBECTL_HELM_MINIKUBE="kubectl-helm-debian.sh ${_BUILD_ARG_KUBECTL_HELM_MINIKUBE_VERSION:-latest} ${_BUILD_ARG_KUBECTL_HELM_MINIKUBE_HELM:-latest} ${_BUILD_ARG_KUBECTL_HELM_MINIKUBE_MINIKUBE:-latest}"
77
_VSC_INSTALL_TERRAFORM="terraform-debian.sh ${_BUILD_ARG_TERRAFORM_VERSION:-latest} ${_BUILD_ARG_TERRAFORM_TFLINT:-latest} ${_BUILD_ARG_TERRAFORM_TERRAGRUNT:-latest}"
88
_VSC_INSTALL_GITHUB_CLI="github-debian.sh ${_BUILD_ARG_GITHUB_CLI_VERSION:-latest}"

script-library/docker-debian.sh

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/docker.md
88
# Maintainer: The VS Code and Codespaces Teams
99
#
10-
# Syntax: ./docker-debian.sh [enable non-root docker socket access flag] [source socket] [target socket] [non-root user] [use moby] [CLI version]
10+
# Syntax: ./docker-debian.sh [enable non-root docker socket access flag] [source socket] [target socket] [non-root user] [use moby] [CLI version] [Major version for docker-compose]
1111

1212
ENABLE_NONROOT_DOCKER=${1:-"true"}
1313
SOURCE_SOCKET=${2:-"/var/run/docker-host.sock"}
1414
TARGET_SOCKET=${3:-"/var/run/docker.sock"}
1515
USERNAME=${4:-"automatic"}
1616
USE_MOBY=${5:-"true"}
1717
DOCKER_VERSION=${6:-"latest"}
18+
DOCKER_DASH_COMPOSE_VERSION=${7:-"v1"} # v1 or v2
1819
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
19-
DOCKER_DASH_COMPOSE_VERSION="1"
2020

2121
set -e
2222

@@ -206,13 +206,36 @@ else
206206
${pipx_bin} install --pip-args '--no-cache-dir --force-reinstall' docker-compose
207207
rm -rf /tmp/pip-tmp
208208
else
209-
find_version_from_git_tags DOCKER_DASH_COMPOSE_VERSION "https://github.com/docker/compose" "tags/"
210-
echo "(*) Installing docker-compose ${DOCKER_DASH_COMPOSE_VERSION}..."
211-
curl -fsSL "https://github.com/docker/compose/releases/download/${DOCKER_DASH_COMPOSE_VERSION}/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
209+
compose_v1_version="1"
210+
find_version_from_git_tags compose_v1_version "https://github.com/docker/compose" "tags/"
211+
echo "(*) Installing docker-compose ${compose_v1_version}..."
212+
curl -fsSL "https://github.com/docker/compose/releases/download/${compose_v1_version}/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
212213
chmod +x /usr/local/bin/docker-compose
213214
fi
214215
fi
215216

217+
# Install docker-compose switch if not already installed - https://github.com/docker/compose-switch#manual-installation
218+
current_v1_compose_path="$(which docker-compose)"
219+
target_v1_compose_path="$(dirname "${current_v1_compose_path}")/docker-compose-v1"
220+
if ! type compose-switch > /dev/null 2>&1; then
221+
echo "(*) Installing compose-switch..."
222+
compose_switch_version="latest"
223+
find_version_from_git_tags compose_switch_version "https://github.com/docker/compose-switch"
224+
curl -fsSL "https://github.com/docker/compose-switch/releases/download/v${compose_switch_version}/docker-compose-linux-${architecture}" -o /usr/local/bin/compose-switch
225+
chmod +x /usr/local/bin/compose-switch
226+
# TODO: Verify checksum once available: https://github.com/docker/compose-switch/issues/11
227+
228+
# Setup v1 CLI as alternative in addition to compose-switch (which maps to v2)
229+
mv "${current_v1_compose_path}" "${target_v1_compose_path}"
230+
update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/compose-switch 99
231+
update-alternatives --install /usr/local/bin/docker-compose docker-compose "${target_v1_compose_path}" 1
232+
fi
233+
if [ "${DOCKER_DASH_COMPOSE_VERSION}" = "v1" ]; then
234+
update-alternatives --set docker-compose "${target_v1_compose_path}"
235+
else
236+
update-alternatives --set docker-compose /usr/local/bin/compose-switch
237+
fi
238+
216239
# If init file already exists, exit
217240
if [ -f "/usr/local/share/docker-init.sh" ]; then
218241
exit 0

script-library/docker-in-docker-debian.sh

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/docker-in-docker.md
88
# Maintainer: The VS Code and Codespaces Teams
99
#
10-
# Syntax: ./docker-in-docker-debian.sh [enable non-root docker access flag] [non-root user] [use moby] [Engine/CLI Version]
10+
# Syntax: ./docker-in-docker-debian.sh [enable non-root docker access flag] [non-root user] [use moby] [Engine/CLI Version] [Major version for docker-compose]
1111

1212
ENABLE_NONROOT_DOCKER=${1:-"true"}
1313
USERNAME=${2:-"automatic"}
1414
USE_MOBY=${3:-"true"}
1515
DOCKER_VERSION=${4:-"latest"} # The Docker/Moby Engine + CLI should match in version
16+
DOCKER_DASH_COMPOSE_VERSION=${5:-"v1"} # v1 or v2
1617
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
17-
DOCKER_DASH_COMPOSE_VERSION="1"
1818

1919
set -e
2020

@@ -193,7 +193,7 @@ echo "Finished installing docker / moby!"
193193

194194
# Install Docker Compose if not already installed and is on a supported architecture
195195
if type docker-compose > /dev/null 2>&1; then
196-
echo "Docker Compose already installed."
196+
echo "Docker Compose v1 already installed."
197197
else
198198
target_compose_arch="${architecture}"
199199
if [ "${target_compose_arch}" = "amd64" ]; then
@@ -218,14 +218,36 @@ else
218218
${pipx_bin} install --pip-args '--no-cache-dir --force-reinstall' docker-compose
219219
rm -rf /tmp/pip-tmp
220220
else
221-
# Only supports docker-compose v1
222-
find_version_from_git_tags DOCKER_DASH_COMPOSE_VERSION "https://github.com/docker/compose" "tags/"
223-
echo "(*) Installing docker-compose ${DOCKER_DASH_COMPOSE_VERSION}..."
224-
curl -fsSL "https://github.com/docker/compose/releases/download/${DOCKER_DASH_COMPOSE_VERSION}/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
221+
compose_v1_version="1"
222+
find_version_from_git_tags compose_v1_version "https://github.com/docker/compose" "tags/"
223+
echo "(*) Installing docker-compose ${compose_v1_version}..."
224+
curl -fsSL "https://github.com/docker/compose/releases/download/${compose_v1_version}/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
225225
chmod +x /usr/local/bin/docker-compose
226226
fi
227227
fi
228228

229+
# Install docker-compose switch if not already installed - https://github.com/docker/compose-switch#manual-installation
230+
current_v1_compose_path="$(which docker-compose)"
231+
target_v1_compose_path="$(dirname "${current_v1_compose_path}")/docker-compose-v1"
232+
if ! type compose-switch > /dev/null 2>&1; then
233+
echo "(*) Installing compose-switch..."
234+
compose_switch_version="latest"
235+
find_version_from_git_tags compose_switch_version "https://github.com/docker/compose-switch"
236+
curl -fsSL "https://github.com/docker/compose-switch/releases/download/v${compose_switch_version}/docker-compose-linux-${architecture}" -o /usr/local/bin/compose-switch
237+
chmod +x /usr/local/bin/compose-switch
238+
# TODO: Verify checksum once available: https://github.com/docker/compose-switch/issues/11
239+
240+
# Setup v1 CLI as alternative in addition to compose-switch (which maps to v2)
241+
mv "${current_v1_compose_path}" "${target_v1_compose_path}"
242+
update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/compose-switch 99
243+
update-alternatives --install /usr/local/bin/docker-compose docker-compose "${target_v1_compose_path}" 1
244+
fi
245+
if [ "${DOCKER_DASH_COMPOSE_VERSION}" = "v1" ]; then
246+
update-alternatives --set docker-compose "${target_v1_compose_path}"
247+
else
248+
update-alternatives --set docker-compose /usr/local/bin/compose-switch
249+
fi
250+
229251
# If init file already exists, exit
230252
if [ -f "/usr/local/share/docker-init.sh" ]; then
231253
echo "/usr/local/share/docker-init.sh already exists, so exiting."

script-library/docs/docker-in-docker.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
## Syntax
1616

1717
```text
18-
./docker-in-docker-debian.sh [Enable non-root docker access flag] [Non-root user] [Use Moby] [Docker / Moby Version]
18+
./docker-in-docker-debian.sh [Enable non-root docker access flag] [Non-root user] [Use Moby] [Docker / Moby Version] [Major version for docker-compose]
1919
```
2020

2121
Or as a feature:
@@ -24,7 +24,8 @@ Or as a feature:
2424
"features": {
2525
"docker-in-docker": {
2626
"version": "latest",
27-
"moby": true
27+
"moby": true,
28+
"dockerDashComposeVersion": "v1"
2829
}
2930
}
3031
```
@@ -35,6 +36,7 @@ Or as a feature:
3536
|Non-root user| | `automatic`| Specifies a user in the container other than root that will be using the desktop. A value of `automatic` will cause the script to check for a user called `vscode`, then `node`, `codespace`, and finally a user with a UID of `1000` before falling back to `root`. |
3637
|Use Moby | `moby`|`true` | Specifies that a build of the open source [Moby CLI](https://github.com/moby/moby/tree/master/cli) should be used instead of the Docker CLI distribution of it. |
3738
| Docker / Moby version | `version` | `latest` | Docker/Moby Engine version or `latest`. Partial version numbers allowed. Availability can vary by OS version. |
39+
| Major version for docker-compose | `dockerDashComposeVersion` | `v1` | Updates `docker-compose` to either Docker Compose v1 or v2 ([learn more](https://docs.docker.com/compose/cli-command/#transitioning-to-ga-for-compose-v2)). |
3840

3941

4042
## Usage
@@ -47,7 +49,8 @@ You can use this script for your primary dev container by adding it to the `feat
4749
"features": {
4850
"docker-in-docker": {
4951
"version": "latest",
50-
"moby": true
52+
"moby": true,
53+
"dockerDashComposeVersion": "v1"
5154
}
5255
}
5356
```

script-library/docs/docker.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
## Syntax
1616

1717
```text
18-
./docker-debian.sh [Non-root access flag] [Source socket] [Target socket] [Non-root user] [Use Moby] [Docker / Moby version]
18+
./docker-debian.sh [Non-root access flag] [Source socket] [Target socket] [Non-root user] [Use Moby] [Docker / Moby version] [Major version for docker-compose]
1919
./docker-redhat.sh [Non-root access flag] [Source socket] [Target socket] [Non-root user]
2020
```
2121

@@ -25,7 +25,8 @@ Or as a feature (Debian/Ubuntu only):
2525
"features": {
2626
"docker-from-docker": {
2727
"version": "latest",
28-
"moby": true
28+
"moby": true,
29+
"dockerDashComposeVersion": "v1"
2930
}
3031
}
3132
```
@@ -38,7 +39,7 @@ Or as a feature (Debian/Ubuntu only):
3839
|Non-root user| | `automatic`| Specifies a user in the container other than root that will be using the desktop. A value of `automatic` will cause the script to check for a user called `vscode`, then `node`, `codespace`, and finally a user with a UID of `1000` before falling back to `root`. |
3940
|Use Moby| `moby` | `true`| Specifies that a build of the open source [Moby CLI](https://github.com/moby/moby/tree/master/cli) should be used instead of the Docker CLI distribution of it. |
4041
| Docker / Moby version | `version` | `latest` | Docker/Moby Engine version or `latest`. Partial version numbers allowed. Availability can vary by OS version. |
41-
42+
| Major version for docker-compose | `dockerDashComposeVersion` | `v1` | Updates `docker-compose` to either Docker Compose v1 or v2 ([learn more](https://docs.docker.com/compose/cli-command/#transitioning-to-ga-for-compose-v2)). |
4243

4344
## Usage
4445

script-library/test/regression/run-scripts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ if [ "${DISTRO}" = "debian" ]; then
8989
runScript terraform "0.15.0 0.12.1"
9090
runScript sshd "2223 ${USERNAME} true random"
9191
runScript desktop-lite "${USERNAME} changeme false"
92-
runScript docker-in-docker "false ${USERNAME} false"
92+
runScript docker-in-docker "false ${USERNAME} false 20.10 v2"
9393
runScript powershell
9494
runScript fish
9595
if [ "${architecture}" = "amd64" ] || [ "${architecture}" = "x86_64" ] || [ "${architecture}" = "arm64" ] || [ "${architecture}" = "aarch64" ]; then

0 commit comments

Comments
 (0)