Last active
February 29, 2016 22:05
-
-
Save mikedougherty/f8ed485134f90f433b1b to your computer and use it in GitHub Desktop.
install script to change docker version on a docker-machine managed host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
# TODO: find a way to automated this variable | |
export CS_LATEST_VERSION=1.10.2-cs1 | |
export HOME="$WORKSPACE" | |
DOCKER_MACHINE_OS=$(docker-machine ssh "$DOCKER_MACHINE_NAME" -- 'source /etc/os-release && echo "$ID-$ID_LIKE"') | |
DOCKER_MACHINE_USER=$(docker-machine inspect "$DOCKER_MACHINE_NAME" | jq -r '.Driver.SSHUser') | |
if ! [[ "$DOCKER_MACHINE_OS" =~ "debian" ]]; then | |
echo "Only debian type distros are supported; ${DOCKER_MACHINE_OS} was detected" >&2 && exit 1 | |
fi | |
## Set the Repo, Channel, Verisoning Info | |
VERSION_CHANNEL="main" | |
if [[ "$DOCKER_VERSION" =~ "_testing" ]]; then | |
VERSION_CHANNEL="testing" | |
fi | |
# install docker | |
case "$DOCKER_VERSION" in | |
*'-cs'*) | |
# set the repo to be used with CS Engine 1.9+ | |
REPO_URL="https://packages.docker.com" | |
if [[ "$DOCKER_VERSION" =~ "_staging" ]]; then | |
REPO_URL="https://s3.amazonaws.com/packages.docker.com-staging" | |
fi | |
if [[ "$DOCKER_VERSION" =~ "latest" ]]; then | |
DOCKER_VERSION="$CS_LATEST_VERSION" | |
fi | |
# parse the major.minor version ... if this is not latest | |
MAJOR_VERSION=$(echo $DOCKER_VERSION | awk -F . '{print $1 "." $2;}') | |
case "$MAJOR_VERSION" in | |
1.6*) | |
INSTALL_SCRIPT=" | |
curl -s https://packagecloud.io/install/repositories/Docker/cs-public/script.deb.sh | bash | |
apt-get -o Dpkg::Options::='--force-overwrite' -o Dpkg::Options::='--force-confnew' install -y docker-engine-cs-${DOCKER_VERSION} | |
" | |
;; | |
*) | |
INSTALL_URL="${REPO_URL}/${MAJOR_VERSION}/install.sh" | |
;; | |
esac | |
;; | |
*) | |
case "$DOCKER_VERSION" in | |
1.5.0|1.6.0|1.6.1|1.6.2) | |
INSTALL_SCRIPT=" | |
apt-get update | |
sh -c 'echo deb https://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list' | |
apt-get install -y apt-transport-https | |
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 | |
apt-get update | |
apt-get -o Dpkg::Options::='--force-overwrite' -o Dpkg::Options::='--force-confnew' install -y lxc-docker-${DOCKER_VERSION} | |
" | |
;; | |
latest) | |
INSTALL_URL="https://get.docker.com" | |
;; | |
latest_testing) | |
INSTALL_URL="https://test.docker.com" | |
;; | |
latest-master) | |
INSTALL_SCRIPT=" | |
curl -sSL https://get.docker.com | bash | |
service docker stop | |
curl --output docker https://master.dockerproject.org/linux/amd64/docker | |
chown root:root ./docker | |
chmod 755 ./docker | |
cp -p docker \$(which docker) | |
service docker start | |
" | |
;; | |
*) | |
INSTALL_SCRIPT=" | |
. /etc/lsb-release | |
curl -sSL https://get.docker.com | sed 's/docker-engine/docker-engine=${DOCKER_VERSION}-0~\${DISTRIB_CODENAME}/g' | bash" | |
;; | |
esac | |
;; | |
esac | |
if [[ -n "$INSTALL_URL" ]] ; then | |
INSTALL_SCRIPT="curl -sSL ${INSTALL_URL} | repo=${VERSION_CHANNEL} bash" | |
fi | |
docker-machine ssh "$DOCKER_MACHINE_NAME" "sudo bash -x" <<EOF | |
docker version | |
apt-get remove -y docker-engine | |
apt-get autoremove -y | |
rm -f /etc/apt/sources.list.d/*ocker* | |
ls -la /etc/apt/sources.list.d/ | |
$INSTALL_SCRIPT | |
docker version | |
usermod -a -G docker ${DOCKER_MACHINE_USER} ||: | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment