Skip to content

Commit

Permalink
feat: allow publish and download kicbase image in github release
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeProgrammer committed Aug 17, 2024
1 parent af5e8a8 commit f5bc2ee
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
18 changes: 17 additions & 1 deletion hack/jenkins/release_build_and_upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ grep -E "^VERSION_BUILD \\?=" Makefile | grep "${VERSION_BUILD}"

# Force go packages to the Jekins home directory
export GOPATH=$HOME/go

# Make sure docker is installed and configured
./hack/jenkins/installers/check_install_docker.sh
# Verify ISO exists
echo "Verifying ISO exists ..."
make verify-iso
Expand Down Expand Up @@ -111,5 +112,20 @@ fi
#echo "Updating Docker images ..."
#make push-gvisor-addon-image push-storage-provisioner-manifest

echo "Generating tarball for docker images"
# first get the correct tag of the kic base image
KIC_VERSION=$(grep -E "Version =" pkg/drivers/kic/types.go | cut -d \" -f 2 | cut -d "-" -f 1)
# then generate tarballs for all achitectures
for ARCH in "amd64" "arm64" "arm/v7" "ppc64le" "s390x"
do
SUFFIX=$(echo $ARCH | sed 's/\///g')
IMAGE_NAME=kicbase/stable:${KIC_VERSION}
TARBALL_NAME=out/kicbase-${KIC_VERSION}-${SUFFIX}.tar
docker pull ${IMAGE_NAME} --platform linux/${ARCH}
docker image save ${IMAGE_NAME} -o ${TARBALL_NAME}
openssl sha256 "${TARBALL_NAME}" | awk '{print $2}' > "${TARBALL_NAME}.sha256"
docker rmi -f ${IMAGE_NAME}
done

echo "Updating latest bucket for ${VERSION} release ..."
gsutil cp -r "gs://${BUCKET}/releases/${TAGNAME}/*" "gs://${BUCKET}/releases/latest/"
3 changes: 2 additions & 1 deletion pkg/minikube/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func CreateDstDownloadMock(_, dst string) error {
}

// download is a well-configured atomic download function
func download(src, dst string) error {
func download(src, dst string, options ...getter.ClientOption) error {
var clientOptions []getter.ClientOption
if out.IsTerminal(os.Stdout) && !detect.GithubActionRunner() {
progress := getter.WithProgress(DefaultProgressBar)
Expand All @@ -76,6 +76,7 @@ func download(src, dst string) error {
} else {
clientOptions = []getter.ClientOption{}
}
clientOptions = append(clientOptions, options...)
tmpDst := dst + ".download"
client := &getter.Client{
Src: src,
Expand Down
46 changes: 46 additions & 0 deletions pkg/minikube/download/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ import (
"github.com/google/go-containerregistry/pkg/v1/daemon"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/hashicorp/go-getter"
"github.com/pkg/errors"
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/detect"
"k8s.io/minikube/pkg/minikube/image"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/out/register"
"k8s.io/minikube/pkg/version"
)

var (
Expand Down Expand Up @@ -224,6 +226,50 @@ func ImageToCache(img string) error {
}
}

func DownloadImageFromGithubToCache(img string, imgVersion string) (string, error) {

Check failure on line 229 in pkg/minikube/download/image.go

View workflow job for this annotation

GitHub Actions / lint

exported: func name will be used as download.DownloadImageFromGithubToCache by other packages, and that stutters; consider calling this ImageFromGithubToCache (revive)
f := imagePathInCache(img)
fileLock := f + ".lock"

kicbaseArch := runtime.GOARCH
if kicbaseArch == "arm" {
kicbaseArch = "armv7"
}

releaser, err := lockDownload(fileLock)
if err != nil {
return "", err
}
if releaser != nil {
defer releaser.Release()
}
downloadUrl := fmt.Sprintf("https://github.com/kubernetes/minikube/releases/download/%s/%s-%s-%s.tar",

Check failure on line 245 in pkg/minikube/download/image.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var downloadUrl should be downloadURL (revive)
version.GetVersion(),
img, imgVersion, kicbaseArch)
// if we reach here, that means the user cannot have access to any docker registry
// this means the user is very likely to have a network issue
// downloading from github via http is the last resort, and we should remind the user
// that he should at least get access to github
// print essential warnings
out.WarningT("minikube cannot pull kicbase image from any docker registry, and is trying to download kicbase tarball from github release page via HTTP.")
out.Ln("The url to the tarball is %s", downloadUrl)
out.WarningT("It's very likely that you have an internet issue. Please ensure that you can access the internet at least via HTTP, directly or with proxy. Currently your proxy configure is:")
envs := []string{"HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy", "ALL_PROXY", "NO_PROXY"}
for _, env := range envs {
if v := os.Getenv(env); v != "" {
out.Infof("{{.env}}={{.value}}", out.V{"env": env, "value": v})
}
}
out.Ln("")

// we don't want the tarball to be decompressed
// so we pass client options to supress this behavior

Check failure on line 265 in pkg/minikube/download/image.go

View workflow job for this annotation

GitHub Actions / lint

`supress` is a misspelling of `suppress` (misspell)
if err := download(downloadUrl, f, getter.WithDecompressors(map[string]getter.Decompressor{})); err != nil {
return "", err
}
return downloadUrl, nil

}

func parseImage(img string) (*name.Tag, name.Reference, error) {

var ref name.Reference
Expand Down
23 changes: 20 additions & 3 deletions pkg/minikube/node/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
if finalImg != "" {
cc.KicBaseImage = finalImg
if image.Tag(finalImg) != image.Tag(baseImg) {
out.WarningT(fmt.Sprintf("minikube was unable to download %s, but successfully downloaded %s as a fallback image", image.Tag(baseImg), image.Tag(finalImg)))
out.WarningT(fmt.Sprintf("minikube was unable to download %s, but successfully downloaded %s as a fallback image", image.Tag(baseImg), finalImg))
}
}
}()
// first we try to download the kicbase image (and fall back images) from docker registry
var err error
for _, img := range append([]string{baseImg}, kic.FallbackImages...) {
var err error

if driver.IsDocker(cc.Driver) && download.ImageExistsInDaemon(img) && !downloadOnly {
klog.Infof("%s exists in daemon, skipping load", img)
Expand Down Expand Up @@ -167,7 +168,23 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
}
klog.Infof("failed to download %s, will try fallback image if available: %v", img, err)
}
return fmt.Errorf("failed to download kic base image or any fallback image")
// second if we failed to download any fallback image
// that means probably all registries are blocked by network issues
// we can try to download the image from minikube release page
kicbaseVersion := strings.Split(kic.Version, "-")[0]
finalImg, err = download.DownloadImageFromGithubToCache("kicbase", kicbaseVersion)
if err != nil {
klog.Infof("failed to download %s", finalImg)
return fmt.Errorf("failed to download kic base image or any fallback image")
}
klog.Infof("successfully downloaded %s as fall back image", finalImg)
if !downloadOnly && driver.IsDocker(cc.Driver) {
if finalImg, err = download.CacheToDaemon("kicbase"); err == nil {
klog.Infof("successfully loaded and using kicbase from tarball on github")
}
}
return nil

})
}

Expand Down

0 comments on commit f5bc2ee

Please sign in to comment.