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

Commit 7e821d4

Browse files
joshspicerChuxel
andauthored
supported distro detection for docker-in-docker script (#1371)
* work in progress distro detection * regex check * clearer condition * additional logging * Update script-library/docker-in-docker-debian.sh Co-authored-by: Chuck Lantz <[email protected]> * add impish to dind settings.env * rename docker settings to work for both dind and dfd * add check to dfd * add impish * add jammy * better regression testing for moby (when distro supported) * remove jammy temporarily * echo whether testing moby Co-authored-by: Chuck Lantz <[email protected]>
1 parent 87f2ae9 commit 7e821d4

File tree

6 files changed

+122
-20
lines changed

6 files changed

+122
-20
lines changed

.github/workflows/script-library-pr-debian.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
if: "!contains(github.event.head_commit.message, 'Automated update') && !contains(github.event.head_commit.message, 'CI ignore')"
1414
strategy:
1515
matrix:
16-
os: ["debian:bullseye", "debian:buster", "ubuntu:focal", "ubuntu:bionic"]
16+
os: ["debian:bullseye", "debian:buster", "ubuntu:focal", "ubuntu:bionic"] # TODO: Add "ubuntu:jammy"
1717
defaults: ["true", "false"]
1818
fail-fast: true
1919
runs-on: ubuntu-latest

migrations/readme-metadata-to-json.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,17 @@ def template(defId, displayName, description, categories, defType, platforms, op
106106
options = 'lc rc'
107107

108108
subst = '''
109-
lc
109+
l-c
110110
"id": "{}",
111111
"displayName": "{}",
112112
"description": "{}",
113113
"categories": [ "{}" ],
114114
"platforms": [ "{}" ],
115115
"type": "{}",
116116
"options": {}
117-
rc,'''.format(defId, displayName, description, categories, platforms, defType, options)
117+
r-c,'''.format(defId, displayName, description, categories, platforms, defType, options)
118118

119-
return subst.replace('lc', '{').replace('rc', '}')
119+
return subst.replace('l-c', '{').replace('r-c', '}')
120120

121121

122122
exceptions = 0

script-library/docker-debian.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ USE_MOBY=${5:-"true"}
1717
DOCKER_VERSION=${6:-"latest"}
1818
DOCKER_DASH_COMPOSE_VERSION=${7:-"v1"} # v1 or v2
1919
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
20+
DOCKER_DASH_COMPOSE_VERSION="1"
21+
DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES="buster bullseye bionic focal jammy"
22+
DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES="buster bullseye bionic focal hirsute impish jammy"
2023

2124
set -e
2225

@@ -125,6 +128,26 @@ fi
125128
# Fetch host/container arch.
126129
architecture="$(dpkg --print-architecture)"
127130

131+
# Check if distro is suppported
132+
if [ "${USE_MOBY}" = "true" ]; then
133+
# 'get_common_setting' allows attribute to be updated remotely
134+
get_common_setting DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES
135+
if [[ "${DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES}" != *"${VERSION_CODENAME}"* ]]; then
136+
err "Unsupported distribution version '${VERSION_CODENAME}'. To resolve, either: (1) set feature option '\"moby\": false' , or (2) choose a compatible OS distribution"
137+
err "Support distributions include: ${DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES}"
138+
exit 1
139+
fi
140+
echo "Distro codename '${VERSION_CODENAME}' matched filter '${DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES}'"
141+
else
142+
get_common_setting DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES
143+
if [[ "${DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES}" != *"${VERSION_CODENAME}"* ]]; then
144+
err "Unsupported distribution version '${VERSION_CODENAME}'. To resolve, please choose a compatible OS distribution"
145+
err "Support distributions include: ${DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES}"
146+
exit 1
147+
fi
148+
echo "Distro codename '${VERSION_CODENAME}' matched filter '${DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES}'"
149+
fi
150+
128151
# Set up the necessary apt repos (either Microsoft's or Docker's)
129152
if [ "${USE_MOBY}" = "true" ]; then
130153

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

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,28 @@ USE_MOBY=${3:-"true"}
1515
DOCKER_VERSION=${4:-"latest"} # The Docker/Moby Engine + CLI should match in version
1616
DOCKER_DASH_COMPOSE_VERSION=${5:-"v1"} # v1 or v2
1717
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
18+
DOCKER_DASH_COMPOSE_VERSION="1"
19+
DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES="buster bullseye bionic focal jammy"
20+
DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES="buster bullseye bionic focal hirsute impish jammy"
1821

22+
# Default: Exit on any failure.
1923
set -e
2024

25+
# Setup STDERR.
26+
err() {
27+
echo "(!) $*" >&2
28+
}
29+
2130
if [ "$(id -u)" -ne 0 ]; then
22-
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
31+
err 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
2332
exit 1
2433
fi
2534

35+
###################
36+
# Helper Functions
37+
# See: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/shared/utils.sh
38+
###################
39+
2640
# Determine the appropriate non-root user
2741
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
2842
USERNAME=""
@@ -97,20 +111,50 @@ find_version_from_git_tags() {
97111
declare -g ${variable_name}="$(echo "${version_list}" | head -n 1)"
98112
else
99113
set +e
100-
declare -g ${variable_name}="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")"
114+
declare -g ${variable_name}="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")"
101115
set -e
102116
fi
103117
fi
104118
if [ -z "${!variable_name}" ] || ! echo "${version_list}" | grep "^${!variable_name//./\\.}$" > /dev/null 2>&1; then
105-
echo -e "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2
119+
err "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2
106120
exit 1
107121
fi
108122
echo "${variable_name}=${!variable_name}"
109123
}
110124

125+
###########################################
126+
# Start docker-in-docker installation
127+
###########################################
128+
111129
# Ensure apt is in non-interactive to avoid prompts
112130
export DEBIAN_FRONTEND=noninteractive
113131

132+
133+
# Source /etc/os-release to get OS info
134+
. /etc/os-release
135+
# Fetch host/container arch.
136+
architecture="$(dpkg --print-architecture)"
137+
138+
# Check if distro is suppported
139+
if [ "${USE_MOBY}" = "true" ]; then
140+
# 'get_common_setting' allows attribute to be updated remotely
141+
get_common_setting DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES
142+
if [[ "${DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES}" != *"${VERSION_CODENAME}"* ]]; then
143+
err "Unsupported distribution version '${VERSION_CODENAME}'. To resolve, either: (1) set feature option '\"moby\": false' , or (2) choose a compatible OS distribution"
144+
err "Support distributions include: ${DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES}"
145+
exit 1
146+
fi
147+
echo "Distro codename '${VERSION_CODENAME}' matched filter '${DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES}'"
148+
else
149+
get_common_setting DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES
150+
if [[ "${DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES}" != *"${VERSION_CODENAME}"* ]]; then
151+
err "Unsupported distribution version '${VERSION_CODENAME}'. To resolve, please choose a compatible OS distribution"
152+
err "Support distributions include: ${DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES}"
153+
exit 1
154+
fi
155+
echo "Distro codename '${VERSION_CODENAME}' matched filter '${DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES}'"
156+
fi
157+
114158
# Install dependencies
115159
check_packages apt-transport-https curl ca-certificates pigz iptables gnupg2 dirmngr
116160
if ! type git > /dev/null 2>&1; then
@@ -124,10 +168,7 @@ if type iptables-legacy > /dev/null 2>&1; then
124168
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
125169
fi
126170

127-
# Source /etc/os-release to get OS info
128-
. /etc/os-release
129-
# Fetch host/container arch.
130-
architecture="$(dpkg --print-architecture)"
171+
131172

132173
# Set up the necessary apt repos (either Microsoft's or Docker's)
133174
if [ "${USE_MOBY}" = "true" ]; then
@@ -165,11 +206,11 @@ else
165206
# Regex needs to handle debian package version number format: https://www.systutorials.com/docs/linux/man/5-deb-version/
166207
docker_version_regex="^(.+:)?${docker_version_dot_plus_escaped}([\\.\\+ ~:-]|$)"
167208
set +e # Don't exit if finding version fails - will handle gracefully
168-
cli_version_suffix="=$(apt-cache madison ${cli_package_name} | awk -F"|" '{print $2}' | sed -e 's/^[ \t]*//' | grep -E -m 1 "${docker_version_regex}")"
169-
engine_version_suffix="=$(apt-cache madison ${engine_package_name} | awk -F"|" '{print $2}' | sed -e 's/^[ \t]*//' | grep -E -m 1 "${docker_version_regex}")"
209+
cli_version_suffix="=$(apt-cache madison ${cli_package_name} | awk -F"|" '{print $2}' | sed -e 's/^[ \t]*//' | grep -E -m 1 "${docker_version_regex}")"
210+
engine_version_suffix="=$(apt-cache madison ${engine_package_name} | awk -F"|" '{print $2}' | sed -e 's/^[ \t]*//' | grep -E -m 1 "${docker_version_regex}")"
170211
set -e
171212
if [ -z "${engine_version_suffix}" ] || [ "${engine_version_suffix}" = "=" ] || [ -z "${cli_version_suffix}" ] || [ "${cli_version_suffix}" = "=" ] ; then
172-
echo "(!) No full or partial Docker / Moby version match found for \"${DOCKER_VERSION}\" on OS ${ID} ${VERSION_CODENAME} (${architecture}). Available versions:"
213+
err "No full or partial Docker / Moby version match found for \"${DOCKER_VERSION}\" on OS ${ID} ${VERSION_CODENAME} (${architecture}). Available versions:"
173214
apt-cache madison ${cli_package_name} | awk -F"|" '{print $2}' | grep -oP '^(.+:)?\K.+'
174215
exit 1
175216
fi
@@ -182,8 +223,17 @@ if type docker > /dev/null 2>&1 && type dockerd > /dev/null 2>&1; then
182223
echo "Docker / Moby CLI and Engine already installed."
183224
else
184225
if [ "${USE_MOBY}" = "true" ]; then
185-
apt-get -y install --no-install-recommends moby-cli${cli_version_suffix} moby-buildx moby-engine${engine_version_suffix}
186-
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."
226+
# Install engine
227+
set +e # Handle error gracefully
228+
apt-get -y install --no-install-recommends moby-cli${cli_version_suffix} moby-buildx moby-engine${engine_version_suffix}
229+
if [ $? -ne 0 ]; then
230+
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')."
231+
exit 1
232+
fi
233+
set -e
234+
235+
# Install compose
236+
apt-get -y install --no-install-recommends moby-compose || err "Package moby-compose (Docker Compose v2) not available for OS ${ID} ${VERSION_CODENAME} (${architecture}). Skipping."
187237
else
188238
apt-get -y install --no-install-recommends docker-ce-cli${cli_version_suffix} docker-ce${engine_version_suffix}
189239
fi
@@ -344,3 +394,5 @@ EOF
344394

345395
chmod +x /usr/local/share/docker-init.sh
346396
chown ${USERNAME}:root /usr/local/share/docker-init.sh
397+
398+
echo 'docker-in-docker-debian script has completed!'

script-library/shared/settings.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ H17gsBJr+opwJw/Zio2LMjQBOqlm3K1A4zFTh7wBC7He6KPQea1p2XAMgtvATtNe
5252
YLZATHZKTJyiqA==
5353
=vYOk
5454
-----END PGP PUBLIC KEY BLOCK-----"
55+
DOCKER_IN_DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES="buster bullseye bionic focal jammy"
56+
DOCKER_IN_DOCKER_LICENSED_ARCHIVE_VERSION_CODENAMES="buster bullseye bionic focal hirsute impish jammy"

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ run_script()
4242
echo "**** Done! ****"
4343
}
4444

45+
get_common_setting() {
46+
# if [ "${common_settings_file_loaded}" != "true" ]; then
47+
# curl -sfL "https://aka.ms/vscode-dev-containers/script-library/settings.env" 2>/dev/null -o /tmp/vsdc-settings.env || echo "Could not download settings file. Skipping."
48+
# common_settings_file_loaded=true
49+
# fi
50+
cp ${SCRIPT_DIR}/shared/settings.env /tmp/vsdc-settings.env
51+
52+
if [ -f "/tmp/vsdc-settings.env" ]; then
53+
local multi_line=""
54+
if [ "$2" = "true" ]; then multi_line="-z"; fi
55+
local result="$(grep ${multi_line} -oP "$1=\"?\K[^\"]+" /tmp/vsdc-settings.env | tr -d '\0')"
56+
if [ ! -z "${result}" ]; then declare -g $1="${result}"; fi
57+
fi
58+
echo "$1=${!1}"
59+
}
60+
4561
# Determine distro scripts to use
4662
. /etc/os-release
4763
architecture="$(uname -m)"
@@ -96,11 +112,19 @@ if [ "${DISTRO}" = "debian" ]; then
96112
run_script terraform "0.15.0 0.12.1"
97113
run_script sshd "2223 ${USERNAME} true random"
98114
run_script desktop-lite "${USERNAME} changeme false"
99-
docker_version="20.10"
100-
if [ "${VERSION_CODENAME}" = "stretch" ]; then
101-
docker_version="19.03"
115+
116+
# docker-in-docker
117+
get_common_setting DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES
118+
if [[ "${DOCKER_MOBY_ARCHIVE_VERSION_CODENAMES}" != *"${VERSION_CODENAME}"* ]]; then
119+
# Do not use Moby
120+
echo 'testing moby: false'
121+
run_script docker-in-docker "false ${USERNAME} false latest v2"
122+
else
123+
# Use Moby
124+
echo 'testing moby: true'
125+
run_script docker-in-docker "false ${USERNAME} true latest v2"
102126
fi
103-
run_script docker-in-docker "false ${USERNAME} false ${docker_version} v2"
127+
104128
run_script powershell
105129
if [ "${architecture}" = "amd64" ] || [ "${architecture}" = "x86_64" ] || [ "${architecture}" = "arm64" ] || [ "${architecture}" = "aarch64" ]; then
106130
run_script java "13.0.2.j9-adpt /usr/local/sdkman2 ${USERNAME} false"
@@ -111,6 +135,7 @@ if [ "${DISTRO}" = "debian" ]; then
111135
run_script dotnet "3.1 true ${USERNAME} false /opt/dotnet dotnet"
112136
fi
113137

138+
# TODO: Most of this script does not execute since 'docker-in-docker' is run above
114139
if [ "${DISTRO}" != "alpine" ]; then
115140
run_script docker "true /var/run/docker-host.sock /var/run/docker.sock ${USERNAME}"
116141
fi

0 commit comments

Comments
 (0)