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-04-27 00:54:07 +00:00
set -x -o pipefail
2021-02-17 01:39:46 +00:00
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-19 00:17:09 +00:00
docker login -u ${ DOCKERHUB_USER } -p ${ DOCKERHUB_PASS }
2021-02-17 03:25:22 +00:00
2021-02-24 21:41:56 +00:00
# Make sure gh is installed and configured
./hack/jenkins/installers/check_install_gh.sh
2021-09-02 18:22:53 +00:00
# Make sure golang is installed and configured
2021-09-02 18:47:27 +00:00
./hack/jenkins/installers/check_install_golang.sh "/usr/local" || true
2021-09-02 18:22:53 +00:00
2021-10-26 22:06:54 +00:00
export GOBIN = /usr/local/go/bin
export PATH = $PATH :$GOBIN
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)
2021-10-26 21:30:01 +00:00
CURRENT_KIC_VERSION = $( egrep "Version =" pkg/drivers/kic/types.go | cut -d \" -f 2)
CURRENT_KIC_TS = $( echo $CURRENT_KIC_VERSION | cut -d "-" -f 2)
2021-02-19 01:22:17 +00:00
if [ [ $HEAD_KIC_TIMESTAMP != v* ] ] ; then
2021-02-17 03:25:22 +00:00
diff = $(( CURRENT_KIC_TS-HEAD_KIC_TIMESTAMP))
2021-02-19 01:22:17 +00:00
if [ [ $CURRENT_KIC_TS = = v* ] ] || [ $diff -lt 0 ] ; then
2021-02-24 21:41:56 +00:00
gh pr comment ${ ghprbPullId } --body " Hi ${ ghprbPullAuthorLoginMention } , your kicbase info is out of date. Please rebase. "
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
2021-02-22 21:27:24 +00:00
# Setup variables
2021-02-23 22:07:49 +00:00
if [ [ -z $KIC_VERSION ] ] ; then
# Testing PRs here
release = false
now = $( date +%s)
KV = $( egrep "Version =" pkg/drivers/kic/types.go | cut -d \" -f 2 | cut -d "-" -f 1)
GCR_REPO = gcr.io/k8s-minikube/kicbase-builds
2021-06-10 06:36:38 +00:00
DH_REPO = docker.io/kicbase/build
2021-02-23 22:07:49 +00:00
export KIC_VERSION = $KV -$now -$ghprbPullId
else
# Actual kicbase release here
release = true
GCR_REPO = ${ GCR_REPO :- gcr .io/k8s-minikube/kicbase }
2021-06-10 06:36:38 +00:00
DH_REPO = ${ DH_REPO :- docker .io/kicbase/stable }
2021-02-23 22:07:49 +00:00
export KIC_VERSION
fi
2021-02-22 21:27:24 +00:00
GCR_IMG = ${ GCR_REPO } :${ KIC_VERSION }
DH_IMG = ${ DH_REPO } :${ KIC_VERSION }
2021-02-23 22:07:49 +00:00
export KICBASE_IMAGE_REGISTRIES = " ${ GCR_IMG } ${ DH_IMG } "
2021-02-22 21:27:24 +00:00
2021-10-26 21:30:01 +00:00
if [ " $release " = false ] ; then
# Build a new kicbase image
CIBUILD = yes make push-kic-base-image | tee kic-logs.txt
2021-02-22 21:27:24 +00:00
2021-10-26 21:30:01 +00:00
# Abort with error message if above command failed
ec = $?
if [ $ec -gt 0 ] ; then
if [ " $release " = false ] ; then
gh pr comment ${ ghprbPullId } --body " Hi ${ ghprbPullAuthorLoginMention } , building a new kicbase image failed.
See the logs at: https://storage.cloud.google.com/minikube-builds/logs/${ ghprbPullId } /${ ghprbActualCommit : : 7 } /kic_image_build.txt
"
fi
exit $ec
2021-02-23 22:07:49 +00:00
fi
2021-10-26 21:30:01 +00:00
else
# Install crane, it does exactly what we want it to do
go install github.com/google/go-containerregistry/cmd/crane@latest
CURRENT_GCR_REPO = $( grep "gcrRepo =" pkg/drivers/kic/types.go | cut -d \" -f 2)
CURRENT_DH_REPO = $( grep "dockerhubRepo =" pkg/drivers/kic/types.go | cut -d \" -f 2)
CURRENT_GCR_IMG = $CURRENT_GCR_REPO :$CURRENT_KIC_VERSION
CURRENT_DH_IMG = $CURRENT_DH_REPO :$CURRENT_KIC_VERSION
crane copy $CURRENT_GCR_IMG $GCR_IMG
crane copy $CURRENT_DH_IMG $DH_IMG
2021-02-17 18:51:16 +00:00
fi
2021-02-18 22:48:46 +00:00
# Retrieve the sha from the new image
2021-02-18 22:40:09 +00:00
docker pull $GCR_IMG
2021-02-26 17:39:58 +00:00
fullsha = $( docker inspect --format= '{{index .RepoDigests 0}}' $GCR_IMG )
2021-02-16 22:22:49 +00:00
sha = $( echo ${ fullsha } | cut -d ":" -f 2)
2021-02-25 01:49:58 +00:00
git config user.name "minikube-bot"
git config user.email "minikube-bot@google.com"
2021-02-16 22:22:49 +00:00
2021-02-23 22:07:49 +00:00
if [ " $release " = false ] ; then
2021-02-25 19:20:35 +00:00
# Update the user's PR with the newly built kicbase image.
2021-02-22 21:27:24 +00:00
2021-02-25 18:41:57 +00:00
git remote add ${ ghprbPullAuthorLogin } git@github.com:${ ghprbPullAuthorLogin } /minikube.git
2021-02-25 01:49:58 +00:00
git fetch ${ ghprbPullAuthorLogin }
git checkout -b ${ ghprbPullAuthorLogin } -${ ghprbSourceBranch } ${ ghprbPullAuthorLogin } /${ ghprbSourceBranch }
sed -i " s|Version = .*|Version = \" ${ KIC_VERSION } \"|;s|baseImageSHA = .*|baseImageSHA = \" ${ sha } \"|;s|gcrRepo = .*|gcrRepo = \" ${ GCR_REPO } \"|;s|dockerhubRepo = .*|dockerhubRepo = \" ${ DH_REPO } \"| " pkg/drivers/kic/types.go; make generate-docs;
git commit -am " Updating kicbase image to ${ KIC_VERSION } "
git push ${ ghprbPullAuthorLogin } HEAD:${ ghprbSourceBranch }
2021-02-25 21:00:45 +00:00
message = " Hi ${ ghprbPullAuthorLoginMention } , we have updated your PR with the reference to newly built kicbase image. Pull the changes locally if you want to test with them or update your PR further. "
2021-02-25 19:58:23 +00:00
if [ $? -gt 0 ] ; then
message = " Hi ${ ghprbPullAuthorLoginMention } , we failed to push the reference to the kicbase to your PR. Please run the following command and push manually.
2021-08-09 23:22:46 +00:00
sed -i 's|Version = .*|Version = \"${KIC_VERSION}\"|;s|baseImageSHA = .*|baseImageSHA = \"${sha}\"|;s|gcrRepo = .*|gcrRepo = \"${GCR_REPO}\"|;s|dockerhubRepo = .*|dockerhubRepo = \"${DH_REPO}\"|' pkg/drivers/kic/types.go
2021-02-25 20:46:28 +00:00
2021-02-25 19:58:23 +00:00
"
fi
2021-02-22 21:27:24 +00:00
2021-02-24 21:41:56 +00:00
gh pr comment ${ ghprbPullId } --body " ${ message } "
2021-02-23 22:07:49 +00:00
else
# We're releasing, so open a new PR with the newly released kicbase
2021-02-24 21:41:56 +00:00
branch = kicbase-release-${ KIC_VERSION }
git checkout -b ${ branch }
2021-02-23 22:07:49 +00:00
sed -i " s|Version = .*|Version = \" ${ KIC_VERSION } \"|;s|baseImageSHA = .*|baseImageSHA = \" ${ sha } \"|;s|gcrRepo = .*|gcrRepo = \" ${ GCR_REPO } \"|;s|dockerhubRepo = .*|dockerhubRepo = \" ${ DH_REPO } \"| " pkg/drivers/kic/types.go
2021-02-25 20:50:59 +00:00
make generate-docs
2021-02-16 22:22:49 +00:00
2021-02-26 17:44:54 +00:00
git add pkg/drivers/kic/types.go site/content/en/docs/commands/start.md
git commit -m " Update kicbase to ${ KIC_VERSION } "
2021-02-23 22:07:49 +00:00
git remote add minikube-bot git@github.com:minikube-bot/minikube.git
2021-02-24 21:41:56 +00:00
git push -f minikube-bot ${ branch }
2021-02-23 22:07:49 +00:00
2021-02-24 22:58:23 +00:00
gh pr create --fill --base master --head minikube-bot:${ branch }
2021-02-23 22:07:49 +00:00
fi