@@ -13,6 +13,7 @@ ENABLE_NONROOT_DOCKER=${1:-"true"}
13
13
USERNAME=${2:- " automatic" }
14
14
USE_MOBY=${3:- " true" }
15
15
MICROSOFT_GPG_KEYS_URI=" https://packages.microsoft.com/keys/microsoft.asc"
16
+ DOCKER_DASH_COMPOSE_VERSION=" 1"
16
17
17
18
set -e
18
19
@@ -72,11 +73,49 @@ check_packages() {
72
73
fi
73
74
}
74
75
76
+ # Figure out correct version of a three part version number is not passed
77
+ find_version_from_git_tags () {
78
+ local variable_name=$1
79
+ local requested_version=${! variable_name}
80
+ if [ " ${requested_version} " = " none" ]; then return ; fi
81
+ local repository=$2
82
+ local prefix=${3:- " tags/v" }
83
+ local separator=${4:- " ." }
84
+ local last_part_optional=${5:- " false" }
85
+ if [ " $( echo " ${requested_version} " | grep -o " ." | wc -l) " != " 2" ]; then
86
+ local escaped_separator=${separator// ./ \\ .}
87
+ local last_part
88
+ if [ " ${last_part_optional} " = " true" ]; then
89
+ last_part=" (${escaped_separator} [0-9]+)?"
90
+ else
91
+ last_part=" ${escaped_separator} [0-9]+"
92
+ fi
93
+ local regex=" ${prefix} \\ K[0-9]+${escaped_separator} [0-9]+${last_part} $"
94
+ local version_list=" $( git ls-remote --tags ${repository} | grep -oP " ${regex} " | tr -d ' ' | tr " ${separator} " " ." | sort -rV) "
95
+ if [ " ${requested_version} " = " latest" ] || [ " ${requested_version} " = " current" ] || [ " ${requested_version} " = " lts" ]; then
96
+ declare -g ${variable_name} =" $( echo " ${version_list} " | head -n 1) "
97
+ else
98
+ set +e
99
+ declare -g ${variable_name} =" $( echo " ${version_list} " | grep -E -m 1 " ^${requested_version// ./ \\ .} ([\\ .\\ s]|$)" ) "
100
+ set -e
101
+ fi
102
+ fi
103
+ if [ -z " ${! variable_name} " ] || ! echo " ${version_list} " | grep " ^${! variable_name// ./ \\ .} $" > /dev/null 2>&1 ; then
104
+ echo -e " Invalid ${variable_name} value: ${requested_version} \nValid values:\n${version_list} " >&2
105
+ exit 1
106
+ fi
107
+ echo " ${variable_name} =${! variable_name} "
108
+ }
109
+
75
110
# Ensure apt is in non-interactive to avoid prompts
76
111
export DEBIAN_FRONTEND=noninteractive
77
112
78
113
# Install dependencies
79
114
check_packages apt-transport-https curl ca-certificates lxc pigz iptables gnupg2 dirmngr
115
+ if ! type git > /dev/null 2>&1 ; then
116
+ apt_get_update_if_needed
117
+ apt-get -y install git
118
+ fi
80
119
81
120
# Swap to legacy iptables for compatibility
82
121
if type iptables-legacy > /dev/null 2>&1 ; then
137
176
${pipx_bin} install --system-site-packages --pip-args ' --no-cache-dir --force-reinstall' docker-compose
138
177
rm -rf /tmp/pip-tmp
139
178
else
140
- latest_compose_version=$( basename " $( curl -fsSL -o /dev/null -w " %{url_effective}" https://github.com/docker/compose/releases/latest) " )
141
- curl -fsSL " https://github.com/docker/compose/releases/download/${latest_compose_version} /docker-compose-$( uname -s) -${target_compose_arch} " -o /usr/local/bin/docker-compose
179
+ find_version_from_git_tags DOCKER_DASH_COMPOSE_VERSION " https://github.com/docker/compose" " tags/"
180
+ echo " (*) Installing docker-compose ${DOCKER_DASH_COMPOSE_VERSION} ..."
181
+ curl -fsSL " https://github.com/docker/compose/releases/download/${DOCKER_DASH_COMPOSE_VERSION} /docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
142
182
chmod +x /usr/local/bin/docker-compose
143
183
fi
144
184
fi
@@ -148,7 +188,7 @@ if [ -f "/usr/local/share/docker-init.sh" ]; then
148
188
echo " /usr/local/share/docker-init.sh already exists, so exiting."
149
189
exit 0
150
190
fi
151
- echo " docker-init doesnt exist..."
191
+ echo " docker-init doesnt exist, adding ..."
152
192
153
193
# Add user to the docker group
154
194
if [ " ${ENABLE_NONROOT_DOCKER} " = " true" ]; then
0 commit comments