From 72fa0be5f4ce69857c43dec9168a91ff66f054df Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Fri, 6 Nov 2020 14:36:41 -0800 Subject: [PATCH] Add script to automatically install docker on jenkins machines --- hack/jenkins/common.sh | 3 ++ .../installers/check_install_docker.sh | 44 +++++++++++++++++++ .../installers/check_install_golang.sh | 2 +- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 hack/jenkins/installers/check_install_docker.sh diff --git a/hack/jenkins/common.sh b/hack/jenkins/common.sh index fdab1c301..efc10af02 100755 --- a/hack/jenkins/common.sh +++ b/hack/jenkins/common.sh @@ -33,6 +33,9 @@ export PATH=$PATH:"/usr/local/bin/:/usr/local/go/bin/:$GOPATH/bin" # installing golang so we could do go get for gopogh sudo ./installers/check_install_golang.sh "1.15.2" "/usr/local" || true +# install docker and kubectl if not present +sudo ./installers/check_install_docker.sh + docker rm -f -v $(docker ps -aq) >/dev/null 2>&1 || true docker volume prune -f || true docker system df || true diff --git a/hack/jenkins/installers/check_install_docker.sh b/hack/jenkins/installers/check_install_docker.sh new file mode 100755 index 000000000..1a9855e80 --- /dev/null +++ b/hack/jenkins/installers/check_install_docker.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Copyright 2016 The Kubernetes Authors All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eux -o pipefail + +function install_docker() { + sudo apt-get -y update + sudo apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - + sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian `lsb_release -cs` stable" + sudo apt-get -y update + sudo apt-get -y install docker-ce docker-ce-cli containerd.io + sudo usermod -aG docker jenkins +} + +function install_kubectl() { + curl -LO "https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl" + chmod +x ./kubectl + sudo mv ./kubectl /usr/local/bin/kubectl +} + +echo "Checking docker" +if ! docker version &>/dev/null; then + echo "No docker installation found, installing docker." + install_docker +fi + +echo "Checking kubectl" +if ! kubectl version &>/dev/null; then + echo "No kubectl installation found, installing kubectl" + install_kubectl +fi diff --git a/hack/jenkins/installers/check_install_golang.sh b/hack/jenkins/installers/check_install_golang.sh index 059daf805..9831a0790 100755 --- a/hack/jenkins/installers/check_install_golang.sh +++ b/hack/jenkins/installers/check_install_golang.sh @@ -18,7 +18,7 @@ set -eux -o pipefail if (($# < 2)); then echo "ERROR: given ! ($#) number of parameters but expect 2." - echo "USAGE: ./check_and_install_golang.sh VERSION_TO_INSTALL INSTALL_PATH" + echo "USAGE: ./check_install_golang.sh VERSION_TO_INSTALL INSTALL_PATH" exit 1 fi -- GitLab