minikube/hack/jenkins/kicbase_auto_build.sh

70 lines
3.9 KiB
Bash
Raw Normal View History

2021-02-16 22:22:49 +00:00
#!/bin/bash
2021-02-16 22:28:58 +00:00
# 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.
2021-02-17 01:39:46 +00:00
set -x
2021-02-17 19:57:12 +00:00
# Make sure docker is installed and configured
2021-02-16 22:22:49 +00:00
./hack/jenkins/installers/check_install_docker.sh
yes|gcloud auth configure-docker
2021-02-17 19:57:12 +00:00
# Setup variables
2021-02-16 22:22:49 +00:00
now=$(date +%s)
2021-02-17 03:25:22 +00:00
KV=$(egrep "Version =" pkg/drivers/kic/types.go | cut -d \" -f 2 | cut -d "-" -f 1)
2021-02-18 19:47:59 +00:00
GCR_REPO=gcr.io/k8s-minikube/kicbase-builds
DH_REPO=kicbase/build
2021-02-17 17:23:30 +00:00
export KIC_VERSION=$KV-$now-$ghprbPullId
2021-02-18 22:20:08 +00:00
export KICBASE_IMAGE_REGISTRIES="${GCR_REPO}:${KIC_VERSION} ${DH_REPO}:${KIC_VERSION}"
2021-02-17 03:25:22 +00:00
2021-02-17 19:57:12 +00:00
# Let's make sure we have the newest kicbase reference
2021-02-17 03:25:22 +00:00
curl -L https://github.com/kubernetes/minikube/raw/master/pkg/drivers/kic/types.go --output types-head.go
2021-02-18 19:47:59 +00:00
# kicbase tags are of the form VERSION-TIMESTAMP-PR, so this grep finds that TIMESTAMP in the middle
# if it doesn't exist, it will just return VERSION, which is covered in the if statement below
2021-02-17 03:25:22 +00:00
HEAD_KIC_TIMESTAMP=$(egrep "Version =" types-head.go | cut -d \" -f 2 | cut -d "-" -f 2)
CURRENT_KIC_TS=$(egrep "Version =" pkg/drivers/kic/types.go | cut -d \" -f 2 | cut -d "-" -f 2)
if [[ $HEAD_KIC_TIMESTAMP != v* ]] && [[ $CURRENT_KIC_TS != v* ]]; then
diff=$((CURRENT_KIC_TS-HEAD_KIC_TIMESTAMP))
if [ $diff -lt 0 ]; then
curl -s -H "Authorization: token ${access_token}" \
-H "Accept: application/vnd.github.v3+json" \
-X POST -d "{\"body\": \"Hi ${ghprbPullAuthorLoginMention}, your kicbase info is out of date. Please rebase.\"}" "https://api.github.com/repos/kubernetes/minikube/issues/$ghprbPullId/comments"
2021-02-17 18:57:25 +00:00
exit 1
2021-02-17 03:25:22 +00:00
fi
fi
rm types-head.go
2021-02-17 19:57:12 +00:00
# Build a new kicbase image
2021-02-16 22:22:49 +00:00
yes|make push-kic-base-image
2021-02-17 18:51:16 +00:00
# Abort with error message if above command failed
if [ $? -gt 0 ]; then
curl -s -H "Authorization: token ${access_token}" \
-H "Accept: application/vnd.github.v3+json" \
-X POST -d "{\"body\": \"Hi ${ghprbPullAuthorLoginMention}, building a new kicbase image failed, please try again.\"}" "https://api.github.com/repos/kubernetes/minikube/issues/$ghprbPullId/comments"
exit $?
fi
2021-02-17 19:57:12 +00:00
# Retrieve the sha from the new imnage
2021-02-16 22:22:49 +00:00
docker pull $KICBASE_IMAGE_REGISTRIES
fullsha=$(docker inspect --format='{{index .RepoDigests 0}}' $KICBASE_IMAGE_REGISTRIES)
sha=$(echo ${fullsha} | cut -d ":" -f 2)
2021-02-17 19:57:12 +00:00
# Display the message to the user
2021-02-18 22:20:08 +00:00
message="Hi ${ghprbPullAuthorLoginMention},\\n\\nA new kicbase image is available, please update your PR with the new tag and SHA.\\nIn pkg/drivers/kic/types.go:\\n\\n\\t// Version is the current version of kic\\n\\tVersion = \\\"${KIC_VERSION}\\\"\\n\\t// SHA of the kic base image\\n\\tbaseImageSHA = \\\"${sha}\\\"\\n\\t// The name of the GCR kicbase repository\\n\\tgcrRepo = \\\"${GCR_REPO}\\\"\\n\\t// The name of the Dockerhub kicbase repository\\n\\tdockerhubRepo = \\\"${DH_REPO}\\\"\\nThen run \`make generate-docs\` to update our documentation to reference the new image.\n\nAlternatively, run the following command and commit the changes:\\n\`\`\`\\n sed 's|Version = .*|Version = \\\"${KIC_VERSION}\\\"|;s|baseImageSHA = .*|baseImageSHA = \\\"${sha}\\\"|;s|gcrRepo = .*|gcrRepo = \\\"${GCR_REPO}\\\"|;s|dockerhubRepo = .*|dockerhubRepo = ${DH_REPO}|' pkg/drivers/kic/types.go > new-types.go; mv new-types.go pkg/drivers/kic/types.go; make generate-docs\\n\`\`\`"
2021-02-16 22:22:49 +00:00
curl -s -H "Authorization: token ${access_token}" \
-H "Accept: application/vnd.github.v3+json" \
-X POST -d "{\"body\": \"${message}\"}" "https://api.github.com/repos/kubernetes/minikube/issues/$ghprbPullId/comments"