diff --git a/hack/jenkins/common.sh b/hack/jenkins/common.sh index 2fdbfb4b2c..beb58f7d08 100755 --- a/hack/jenkins/common.sh +++ b/hack/jenkins/common.sh @@ -36,6 +36,52 @@ export PATH=$PATH:"/usr/local/bin/:/usr/local/go/bin/:$GOPATH/bin" readonly TIMEOUT=${1:-120m} +public_log_url="https://storage.googleapis.com/minikube-builds/logs/${MINIKUBE_LOCATION}/${COMMIT:0:7}/${JOB_NAME}.html" + +# retry_github_status provides reliable github status updates +function retry_github_status() { + local commit=$1 + local context=$2 + local state=$3 + local token=$4 + local target=$5 + local desc=$6 + + # Retry in case we hit our GitHub API quota or fail other ways. + local attempt=0 + local timeout=2 + local code=-1 + + echo "set GitHub status $context to $desc" + + while [[ "${attempt}" -lt 8 ]]; do + local out=$(mktemp) + code=$(curl -o "${out}" -s --write-out "%{http_code}" -L -u minikube-bot:${token} \ + "https://api.github.com/repos/kubernetes/minikube/statuses/${commit}" \ + -H "Content-Type: application/json" \ + -X POST \ + -d "{\"state\": \"${state}\", \"description\": \"Jenkins: ${desc}\", \"target_url\": \"${target}\", \"context\": \"${context}\"}" || echo 999) + + # 2xx HTTP codes + if [[ "${code}" =~ ^2 ]]; then + break + fi + + cat "${out}" && rm -f "${out}" + echo "HTTP code ${code}! Retrying in ${timeout} .." + sleep "${timeout}" + attempt=$(( attempt + 1 )) + timeout=$(( timeout * 5 )) + done +} + +if [ "$(uname)" = "Darwin" ]; then + if ! bash setup_docker_desktop_macos.sh; then + retry_github_status "${COMMIT}" "${JOB_NAME}" "failure" "${access_token}" "${public_log_url}" "Jenkins: docker failed to start" + exit 1 + fi +fi + # We need pstree for the restart cronjobs if [ "$(uname)" != "Darwin" ]; then sudo apt-get -y install lsof psmisc @@ -423,45 +469,6 @@ if [[ "${MINIKUBE_LOCATION}" == "master" ]]; then exit "$result" fi -public_log_url="https://storage.googleapis.com/minikube-builds/logs/${MINIKUBE_LOCATION}/${COMMIT:0:7}/${JOB_NAME}.html" - -# retry_github_status provides reliable github status updates -function retry_github_status() { - local commit=$1 - local context=$2 - local state=$3 - local token=$4 - local target=$5 - local desc=$6 - - # Retry in case we hit our GitHub API quota or fail other ways. - local attempt=0 - local timeout=2 - local code=-1 - - echo "set GitHub status $context to $desc" - - while [[ "${attempt}" -lt 8 ]]; do - local out=$(mktemp) - code=$(curl -o "${out}" -s --write-out "%{http_code}" -L -u minikube-bot:${token} \ - "https://api.github.com/repos/kubernetes/minikube/statuses/${commit}" \ - -H "Content-Type: application/json" \ - -X POST \ - -d "{\"state\": \"${state}\", \"description\": \"Jenkins: ${desc}\", \"target_url\": \"${target}\", \"context\": \"${context}\"}" || echo 999) - - # 2xx HTTP codes - if [[ "${code}" =~ ^2 ]]; then - break - fi - - cat "${out}" && rm -f "${out}" - echo "HTTP code ${code}! Retrying in ${timeout} .." - sleep "${timeout}" - attempt=$(( attempt + 1 )) - timeout=$(( timeout * 5 )) - done -} - retry_github_status "${COMMIT}" "${JOB_NAME}" "${status}" "${access_token}" "${public_log_url}" "${description}" exit "$result" diff --git a/hack/jenkins/setup_docker_desktop_macos.sh b/hack/jenkins/setup_docker_desktop_macos.sh new file mode 100755 index 0000000000..ed090ddb5b --- /dev/null +++ b/hack/jenkins/setup_docker_desktop_macos.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# Copyright 2021 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 -x + +if docker system info > /dev/null 2>&1; then + echo "Docker is already running, exiting" + exit 0 +fi + +# kill docker first +osascript -e 'quit app "Docker"' + +# wait 2 minutes for it to start back up +timeout=120 +elapsed=0 +echo "Starting Docker Desktop..." +open --background -a Docker +echo "Waiting at most two minutes..." +while ! docker system info > /dev/null 2>&1; +do + sleep 1 + elapsed=$((elapsed+1)) + if [ $elapsed -gt $timeout ]; then + echo "Start Docker Desktop failed" + exit 1 + fi +done + +echo "Docker Desktop started!"