Add VERSION pinning to the installation script

VERSION pinning is something that people have been asking for, for a
while so this attempts to add that in.

Should work in most scenarios aside from incomplete VERSIONS.

IE: If you have the `test` channel enabled and try to install `17.12`
for example, the script will instead try to install rc2 since that is
the latest VERSION in the results.

Should also work with nightly builds like pinning to a date, or a
specific git SHA

Signed-off-by: Eli Uriegas <eli.uriegas@docker.com>
This commit is contained in:
Eli Uriegas 2018-02-23 23:10:27 +00:00
parent 91ca5b2c7d
commit efeeb89fea
2 changed files with 64 additions and 4 deletions

View File

@ -2,6 +2,7 @@ SHELL:=/bin/bash
DISTROS:=centos-7 fedora-25 fedora-26 debian-wheezy debian-jessie debian-stretch debian-buster ubuntu-trusty ubuntu-xenial ubuntu-yakkety ubuntu-artful
VERIFY_INSTALL_DISTROS:=$(addprefix x86_64-verify-install-,$(DISTROS))
CHANNEL_TO_TEST?=test
VERSION?=
SHELLCHECK_EXCLUSIONS=$(addprefix -e, SC1091 SC1117)
SHELLCHECK=docker run --rm -v "$(CURDIR)":/v -w /v koalaman/shellcheck $(SHELLCHECK_EXCLUSIONS)
@ -22,6 +23,7 @@ x86_64-verify-install-%:
sed 's/DEFAULT_CHANNEL_VALUE="test"/DEFAULT_CHANNEL_VALUE="$(CHANNEL_TO_TEST)"/' install.sh > build/install.sh
set -o pipefail && docker run \
--rm \
-e VERSION \
-v $(CURDIR):/v \
-w /v \
$(subst -,:,$*) \
@ -32,6 +34,7 @@ armhf-verify-install-raspbian-jessie:
sed 's/DEFAULT_CHANNEL_VALUE="test"/DEFAULT_CHANNEL_VALUE="$(CHANNEL_TO_TEST)"/' install.sh > build/install.sh
set -o pipefail && docker run \
--rm \
-e VERSION \
-v $(CURDIR):/v \
-w /v \
resin/rpi-raspbian:jessie \
@ -42,6 +45,7 @@ armhf-verify-install-raspbian-stretch:
sed 's/DEFAULT_CHANNEL_VALUE="test"/DEFAULT_CHANNEL_VALUE="$(CHANNEL_TO_TEST)"/' install.sh > build/install.sh
set -o pipefail && docker run \
--rm \
-e VERSION \
-v $(CURDIR):/v \
-w /v \
resin/rpi-raspbian:stretch \
@ -52,6 +56,7 @@ armhf-verify-install-%:
sed 's/DEFAULT_CHANNEL_VALUE="test"/DEFAULT_CHANNEL_VALUE="$(CHANNEL_TO_TEST)"/' install.sh > build/install.sh
set -o pipefail && docker run \
--rm \
-e VERSION \
-v $(CURDIR):/v \
-w /v \
arm32v7/$(subst -,:,$*) \
@ -62,6 +67,7 @@ aarch64-verify-install-%:
sed 's/DEFAULT_CHANNEL_VALUE="test"/DEFAULT_CHANNEL_VALUE="$(CHANNEL_TO_TEST)"/' install.sh > build/install.sh
set -o pipefail && docker run \
--rm \
-e VERSION \
-v $(CURDIR):/v \
-w /v \
arm64v8/$(subst -,:,$*) \
@ -72,6 +78,7 @@ s390x-verify-install-%:
sed 's/DEFAULT_CHANNEL_VALUE="test"/DEFAULT_CHANNEL_VALUE="$(CHANNEL_TO_TEST)"/' install.sh > build/install.sh
set -o pipefail && docker run \
--rm \
-e VERSION \
-v $(CURDIR):/v \
-w /v \
s390x/$(subst -,:,$*) \
@ -82,6 +89,7 @@ ppc64le-verify-install-%:
sed 's/DEFAULT_CHANNEL_VALUE="test"/DEFAULT_CHANNEL_VALUE="$(CHANNEL_TO_TEST)"/' install.sh > build/install.sh
set -o pipefail && docker run \
--rm \
-e VERSION \
-v $(CURDIR):/v \
-w /v \
ppc64le/$(subst -,:,$*) \

View File

@ -239,11 +239,11 @@ do_install() {
echo "# Executing docker install script, commit: $SCRIPT_COMMIT_SHA"
if command_exists docker; then
version="$(docker -v | cut -d ' ' -f3 | cut -d ',' -f1)"
docker_version="$(docker -v | cut -d ' ' -f3 | cut -d ',' -f1)"
MAJOR_W=1
MINOR_W=10
semverParse "$version"
semverParse "$docker_version"
shouldWarn=0
if [ "$major" -lt "$MAJOR_W" ]; then
@ -411,7 +411,32 @@ do_install() {
$sh_c 'sed -i "/deb-src.*download\.docker/d" /etc/apt/sources.list.d/docker.list'
fi
$sh_c 'apt-get update -qq >/dev/null'
$sh_c 'apt-get install -y -qq --no-install-recommends docker-ce >/dev/null'
)
pkg_version=""
if [ ! -z "$VERSION" ]; then
if is_dry_run; then
echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
else
# Will work for incomplete versions IE (17.12), but may not actually grab the "latest" if in the test channel
pkg_pattern="$(echo "$VERSION" | sed "s/-ce-/~ce~/g" | sed "s/-/.*/g").*-0~$lsb_dist"
search_command="apt-cache madison 'docker-ce' | grep '$pkg_pattern' | head -1 | cut -d' ' -f 4"
pkg_version="$($sh_c "$search_command")"
echo "INFO: Searching repository for VERSION '$VERSION'"
echo "INFO: $search_command"
if [ -z "$pkg_version" ]; then
echo
echo "ERROR: '$VERSION' not found amongst apt-cache madison results"
echo
exit 1
fi
pkg_version="=$pkg_version"
fi
fi
(
if ! is_dry_run; then
set -x
fi
$sh_c "apt-get install -y -qq --no-install-recommends docker-ce$pkg_version >/dev/null"
)
echo_docker_as_nonroot
exit 0
@ -434,11 +459,13 @@ do_install() {
config_manager="dnf config-manager"
enable_channel_flag="--set-enabled"
pre_reqs="dnf-plugins-core"
pkg_suffix="fc$dist_version"
else
pkg_manager="yum"
config_manager="yum-config-manager"
enable_channel_flag="--enable"
pre_reqs="yum-utils"
pkg_suffix="el"
fi
(
if ! is_dry_run; then
@ -451,7 +478,32 @@ do_install() {
$sh_c "$config_manager $enable_channel_flag docker-ce-$CHANNEL"
fi
$sh_c "$pkg_manager makecache"
$sh_c "$pkg_manager install -y -q docker-ce"
)
pkg_version=""
if [ ! -z "$VERSION" ]; then
if is_dry_run; then
echo "# WARNING: VERSION pinning is not supported in DRY_RUN"
else
pkg_pattern="$(echo "$VERSION" | sed "s/-ce-/\\\\.ce\\\\./g" | sed "s/-/.*/g").*$pkg_suffix"
search_command="$pkg_manager list --showduplicates 'docker-ce' | grep '$pkg_pattern' | tail -1 | awk '{print \$2}'"
pkg_version="$($sh_c "$search_command")"
echo "INFO: Searching repository for VERSION '$VERSION'"
echo "INFO: $search_command"
if [ -z "$pkg_version" ]; then
echo
echo "ERROR: '$VERSION' not found amongst $pkg_manager list results"
echo
exit 1
fi
# Cut out the epoch and prefix with a '-'
pkg_version="-$(echo "$pkg_version" | cut -d':' -f 2)"
fi
fi
(
if ! is_dry_run; then
set -x
fi
$sh_c "$pkg_manager install -y -q docker-ce$pkg_version"
)
echo_docker_as_nonroot
exit 0