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

Commit 33e97c0

Browse files
authored
Fix DinD, D-from-D scripts (#1082)
1 parent 70899b4 commit 33e97c0

File tree

4 files changed

+75
-30
lines changed

4 files changed

+75
-30
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
_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}
2-
_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}"
1+
_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}"
2+
_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}"
33
_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}"
44
_VSC_INSTALL_TERRAFORM="terraform-debian.sh ${_BUILD_ARG_TERRAFORM_VERSION:-latest} ${_BUILD_ARG_TERRAFORM_TFLINT:-latest} ${_BUILD_ARG_TERRAFORM_TERRAGRUNT:-latest}"
55
_VSC_INSTALL_GIT="git-from-src-debian.sh ${_BUILD_ARG_GIT_VERSION:-latest} ${_BUILD_ARG_GIT_PPA:-true}"

script-library/docker-debian.sh

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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"}
17-
CLI_VERSION=${6:-"latest"}
17+
DOCKER_VERSION=${6:-"latest"}
1818
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
1919
DOCKER_DASH_COMPOSE_VERSION="1"
2020

@@ -110,6 +110,15 @@ find_version_from_git_tags() {
110110
echo "${variable_name}=${!variable_name}"
111111
}
112112

113+
# Ensure apt is in non-interactive to avoid prompts
114+
export DEBIAN_FRONTEND=noninteractive
115+
116+
# Install dependencies
117+
check_packages apt-transport-https curl ca-certificates gnupg2 dirmngr
118+
if ! type git > /dev/null 2>&1; then
119+
apt_get_update_if_needed
120+
apt-get -y install git
121+
fi
113122

114123
# Source /etc/os-release to get OS info
115124
. /etc/os-release
@@ -138,39 +147,33 @@ fi
138147
apt-get update
139148

140149
# Soft version matching for CLI
141-
if [ "${CLI_VERSION}" = "latest" ] || [ "${CLI_VERSION}" = "lts" ] || [ "${CLI_VERSION}" = "stable" ]; then
150+
if [ "${DOCKER_VERSION}" = "latest" ] || [ "${DOCKER_VERSION}" = "lts" ] || [ "${DOCKER_VERSION}" = "stable" ]; then
142151
# Empty, meaning grab whatever "latest" is in apt repo
143152
cli_version_suffix=""
144153
else
145154
# Fetch a valid version from the apt-cache (eg: the Microsoft repo appends +azure, breakfix, etc...)
146-
cli_version_suffix="=$(apt-cache madison ${cli_package_name} | awk -F"|" '{print $2}' | sed -e 's/^[ \t]*//' | grep -E -m 1 "^(${CLI_VERSION})(\.|$|\+.*|-.*)")"
147-
148-
if [ -z ${cli_version_suffix} ] || [ ${cli_version_suffix} = "=" ]; then
149-
echo "ERR: Parsed CLI_VERSION (${CLI_VERSION}) was not found in the apt-cache for this package+distribution combo";
150-
echo "Available versions for your distribution (NOTE: pass to this script in the form -> MAJOR.MINOR.REV)"
151-
apt-cache madison ${cli_package_name} | awk -F"|" '{print $2}'
155+
docker_version_dot_escaped="${DOCKER_VERSION//./\\.}"
156+
docker_version_dot_plus_escaped="${docker_version_dot_escaped//+/\\+}"
157+
# Regex needs to handle debian package version number format: https://www.systutorials.com/docs/linux/man/5-deb-version/
158+
docker_version_regex="^(.+:)?${docker_version_dot_plus_escaped}([\\.\\+ ~:-]|$)"
159+
set +e # Don't exit if finding version fails - will handle gracefully
160+
cli_version_suffix="=$(apt-cache madison ${cli_package_name} | awk -F"|" '{print $2}' | sed -e 's/^[ \t]*//' | grep -E -m 1 "${docker_version_regex}")"
161+
set -e
162+
if [ -z "${cli_version_suffix}" ] || [ "${cli_version_suffix}" = "=" ]; then
163+
echo "(!) No full or partial Docker / Moby version match found for \"${DOCKER_VERSION}\" on OS ${ID} ${VERSION_CODENAME} (${architecture}). Available versions:"
164+
apt-cache madison ${cli_package_name} | awk -F"|" '{print $2}' | grep -oP '^(.+:)?\K.+'
152165
exit 1
153166
fi
154167
echo "cli_version_suffix ${cli_version_suffix}"
155168
fi
156169

157-
# Ensure apt is in non-interactive to avoid prompts
158-
export DEBIAN_FRONTEND=noninteractive
159-
160-
# Install dependencies
161-
check_packages apt-transport-https curl ca-certificates gnupg2 dirmngr
162-
if ! type git > /dev/null 2>&1; then
163-
apt_get_update_if_needed
164-
apt-get -y install git
165-
fi
166-
167170
# Install Docker / Moby CLI if not already installed
168171
if type docker > /dev/null 2>&1; then
169172
echo "Docker / Moby CLI already installed."
170173
else
171174
if [ "${USE_MOBY}" = "true" ]; then
172175
apt-get -y install --no-install-recommends moby-cli${cli_version_suffix} moby-buildx
173-
apt-get -y install --no-install-recommends moby-compose || echo "(*) Package moby-compose (Docker Compose v2) not available for ${VERSION_CODENAME} ${architecture}. Skipping."
176+
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."
174177
else
175178
apt-get -y install --no-install-recommends docker-ce-cli${cli_version_suffix}
176179
fi

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,17 @@ if [ "${DOCKER_VERSION}" = "latest" ] || [ "${DOCKER_VERSION}" = "lts" ] || [ "$
160160
cli_version_suffix=""
161161
else
162162
# Fetch a valid version from the apt-cache (eg: the Microsoft repo appends +azure, breakfix, etc...)
163-
engine_version_suffix="=$(apt-cache madison ${engine_package_name} | awk -F"|" '{print $2}' | sed -e 's/^[ \t]*//' | grep -E -m 1 "^(${DOCKER_VERSION})(\.|$|\+.*|-.*)")"
164-
cli_version_suffix="=$(apt-cache madison ${cli_package_name} | awk -F"|" '{print $2}' | sed -e 's/^[ \t]*//' | grep -E -m 1 "^(${DOCKER_VERSION})(\.|$|\+.*|-.*)")"
165-
if [ ${engine_version_suffix} = "=" ] || [ ${cli_version_suffix} = "=" ] ; then
166-
echo "ERR: Provided VERSION (${DOCKER_VERSION}) was not found in the apt-cache for the CLI and/or Engine in this distribution";
167-
echo "Available *engine* versions for your distribution (NOTE: pass to this script in the form -> MAJOR.MINOR.REV)"
168-
apt-cache madison ${engine_package_name} | awk -F"|" '{print $2}'
163+
docker_version_dot_escaped="${DOCKER_VERSION//./\\.}"
164+
docker_version_dot_plus_escaped="${docker_version_dot_escaped//+/\\+}"
165+
# Regex needs to handle debian package version number format: https://www.systutorials.com/docs/linux/man/5-deb-version/
166+
docker_version_regex="^(.+:)?${docker_version_dot_plus_escaped}([\\.\\+ ~:-]|$)"
167+
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}")"
170+
set -e
171+
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:"
173+
apt-cache madison ${cli_package_name} | awk -F"|" '{print $2}' | grep -oP '^(.+:)?\K.+'
169174
exit 1
170175
fi
171176
echo "engine_version_suffix ${engine_version_suffix}"
@@ -178,7 +183,7 @@ if type docker > /dev/null 2>&1 && type dockerd > /dev/null 2>&1; then
178183
else
179184
if [ "${USE_MOBY}" = "true" ]; then
180185
apt-get -y install --no-install-recommends moby-cli${cli_version_suffix} moby-buildx moby-engine${engine_version_suffix}
181-
apt-get -y install --no-install-recommends moby-compose || echo "(*) Package moby-compose (Docker Compose v2) not available for ${VERSION_CODENAME} ${architecture}. Skipping."
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."
182187
else
183188
apt-get -y install --no-install-recommends docker-ce-cli${cli_version_suffix} docker-ce${engine_version_suffix}
184189
fi

script-library/docker-redhat.sh

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ENABLE_NONROOT_DOCKER=${1:-"true"}
1414
SOURCE_SOCKET=${2:-"/var/run/docker-host.sock"}
1515
TARGET_SOCKET=${3:-"/var/run/docker.sock"}
1616
USERNAME=${4:-"automatic"}
17+
DOCKER_DASH_COMPOSE_VERSION="1"
1718

1819
set -e
1920

@@ -22,6 +23,40 @@ if [ "$(id -u)" -ne 0 ]; then
2223
exit 1
2324
fi
2425

26+
# Figure out correct version of a three part version number is not passed
27+
find_version_from_git_tags() {
28+
local variable_name=$1
29+
local requested_version=${!variable_name}
30+
if [ "${requested_version}" = "none" ]; then return; fi
31+
local repository=$2
32+
local prefix=${3:-"tags/v"}
33+
local separator=${4:-"."}
34+
local last_part_optional=${5:-"false"}
35+
if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then
36+
local escaped_separator=${separator//./\\.}
37+
local last_part
38+
if [ "${last_part_optional}" = "true" ]; then
39+
last_part="(${escaped_separator}[0-9]+)?"
40+
else
41+
last_part="${escaped_separator}[0-9]+"
42+
fi
43+
local regex="${prefix}\\K[0-9]+${escaped_separator}[0-9]+${last_part}$"
44+
local version_list="$(git ls-remote --tags ${repository} | grep -oP "${regex}" | tr -d ' ' | tr "${separator}" "." | sort -rV)"
45+
if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ] || [ "${requested_version}" = "lts" ]; then
46+
declare -g ${variable_name}="$(echo "${version_list}" | head -n 1)"
47+
else
48+
set +e
49+
declare -g ${variable_name}="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")"
50+
set -e
51+
fi
52+
fi
53+
if [ -z "${!variable_name}" ] || ! echo "${version_list}" | grep "^${!variable_name//./\\.}$" > /dev/null 2>&1; then
54+
echo -e "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2
55+
exit 1
56+
fi
57+
echo "${variable_name}=${!variable_name}"
58+
}
59+
2560
# Determine the appropriate non-root user
2661
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
2762
USERNAME=""
@@ -45,6 +80,7 @@ if yum list deltarpm > /dev/null 2>&1; then
4580
fi
4681
yum -y install ca-certificates curl gnupg2 dirmngr dnf net-tools dialog git openssh-clients curl less procps
4782

83+
4884
# Try to load os-release
4985
. /etc/os-release 2>/dev/null
5086

@@ -81,8 +117,9 @@ yum -y update
81117
yum -y install docker-ce-cli
82118

83119
# Install Docker Compose
84-
LATEST_COMPOSE_VERSION=$(basename "$(curl -fsSL -o /dev/null -w "%{url_effective}" https://github.com/docker/compose/releases/latest)")
85-
curl -fsSL "https://github.com/docker/compose/releases/download/${LATEST_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
120+
find_version_from_git_tags DOCKER_DASH_COMPOSE_VERSION "https://github.com/docker/compose" "tags/"
121+
echo "(*) Installing docker-compose ${DOCKER_DASH_COMPOSE_VERSION}..."
122+
curl -fsSL "https://github.com/docker/compose/releases/download/${DOCKER_DASH_COMPOSE_VERSION}/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
86123
chmod +x /usr/local/bin/docker-compose
87124

88125
# By default, make the source and target sockets the same

0 commit comments

Comments
 (0)