Skip to content

Commit f5bc2ee

Browse files
feat: allow publish and download kicbase image in github release
1 parent af5e8a8 commit f5bc2ee

File tree

4 files changed

+85
-5
lines changed

4 files changed

+85
-5
lines changed

hack/jenkins/release_build_and_upload.sh

+17-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ grep -E "^VERSION_BUILD \\?=" Makefile | grep "${VERSION_BUILD}"
3939

4040
# Force go packages to the Jekins home directory
4141
export GOPATH=$HOME/go
42-
42+
# Make sure docker is installed and configured
43+
./hack/jenkins/installers/check_install_docker.sh
4344
# Verify ISO exists
4445
echo "Verifying ISO exists ..."
4546
make verify-iso
@@ -111,5 +112,20 @@ fi
111112
#echo "Updating Docker images ..."
112113
#make push-gvisor-addon-image push-storage-provisioner-manifest
113114

115+
echo "Generating tarball for docker images"
116+
# first get the correct tag of the kic base image
117+
KIC_VERSION=$(grep -E "Version =" pkg/drivers/kic/types.go | cut -d \" -f 2 | cut -d "-" -f 1)
118+
# then generate tarballs for all achitectures
119+
for ARCH in "amd64" "arm64" "arm/v7" "ppc64le" "s390x"
120+
do
121+
SUFFIX=$(echo $ARCH | sed 's/\///g')
122+
IMAGE_NAME=kicbase/stable:${KIC_VERSION}
123+
TARBALL_NAME=out/kicbase-${KIC_VERSION}-${SUFFIX}.tar
124+
docker pull ${IMAGE_NAME} --platform linux/${ARCH}
125+
docker image save ${IMAGE_NAME} -o ${TARBALL_NAME}
126+
openssl sha256 "${TARBALL_NAME}" | awk '{print $2}' > "${TARBALL_NAME}.sha256"
127+
docker rmi -f ${IMAGE_NAME}
128+
done
129+
114130
echo "Updating latest bucket for ${VERSION} release ..."
115131
gsutil cp -r "gs://${BUCKET}/releases/${TAGNAME}/*" "gs://${BUCKET}/releases/latest/"

pkg/minikube/download/download.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func CreateDstDownloadMock(_, dst string) error {
6565
}
6666

6767
// download is a well-configured atomic download function
68-
func download(src, dst string) error {
68+
func download(src, dst string, options ...getter.ClientOption) error {
6969
var clientOptions []getter.ClientOption
7070
if out.IsTerminal(os.Stdout) && !detect.GithubActionRunner() {
7171
progress := getter.WithProgress(DefaultProgressBar)
@@ -76,6 +76,7 @@ func download(src, dst string) error {
7676
} else {
7777
clientOptions = []getter.ClientOption{}
7878
}
79+
clientOptions = append(clientOptions, options...)
7980
tmpDst := dst + ".download"
8081
client := &getter.Client{
8182
Src: src,

pkg/minikube/download/image.go

+46
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ import (
3232
"github.com/google/go-containerregistry/pkg/v1/daemon"
3333
"github.com/google/go-containerregistry/pkg/v1/remote"
3434
"github.com/google/go-containerregistry/pkg/v1/tarball"
35+
"github.com/hashicorp/go-getter"
3536
"github.com/pkg/errors"
3637
"k8s.io/klog/v2"
3738
"k8s.io/minikube/pkg/minikube/detect"
3839
"k8s.io/minikube/pkg/minikube/image"
3940
"k8s.io/minikube/pkg/minikube/localpath"
4041
"k8s.io/minikube/pkg/minikube/out"
4142
"k8s.io/minikube/pkg/minikube/out/register"
43+
"k8s.io/minikube/pkg/version"
4244
)
4345

4446
var (
@@ -224,6 +226,50 @@ func ImageToCache(img string) error {
224226
}
225227
}
226228

229+
func DownloadImageFromGithubToCache(img string, imgVersion string) (string, error) {
230+
f := imagePathInCache(img)
231+
fileLock := f + ".lock"
232+
233+
kicbaseArch := runtime.GOARCH
234+
if kicbaseArch == "arm" {
235+
kicbaseArch = "armv7"
236+
}
237+
238+
releaser, err := lockDownload(fileLock)
239+
if err != nil {
240+
return "", err
241+
}
242+
if releaser != nil {
243+
defer releaser.Release()
244+
}
245+
downloadUrl := fmt.Sprintf("https://github.com/kubernetes/minikube/releases/download/%s/%s-%s-%s.tar",
246+
version.GetVersion(),
247+
img, imgVersion, kicbaseArch)
248+
// if we reach here, that means the user cannot have access to any docker registry
249+
// this means the user is very likely to have a network issue
250+
// downloading from github via http is the last resort, and we should remind the user
251+
// that he should at least get access to github
252+
// print essential warnings
253+
out.WarningT("minikube cannot pull kicbase image from any docker registry, and is trying to download kicbase tarball from github release page via HTTP.")
254+
out.Ln("The url to the tarball is %s", downloadUrl)
255+
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:")
256+
envs := []string{"HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy", "ALL_PROXY", "NO_PROXY"}
257+
for _, env := range envs {
258+
if v := os.Getenv(env); v != "" {
259+
out.Infof("{{.env}}={{.value}}", out.V{"env": env, "value": v})
260+
}
261+
}
262+
out.Ln("")
263+
264+
// we don't want the tarball to be decompressed
265+
// so we pass client options to supress this behavior
266+
if err := download(downloadUrl, f, getter.WithDecompressors(map[string]getter.Decompressor{})); err != nil {
267+
return "", err
268+
}
269+
return downloadUrl, nil
270+
271+
}
272+
227273
func parseImage(img string) (*name.Tag, name.Reference, error) {
228274

229275
var ref name.Reference

pkg/minikube/node/cache.go

+20-3
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,13 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
133133
if finalImg != "" {
134134
cc.KicBaseImage = finalImg
135135
if image.Tag(finalImg) != image.Tag(baseImg) {
136-
out.WarningT(fmt.Sprintf("minikube was unable to download %s, but successfully downloaded %s as a fallback image", image.Tag(baseImg), image.Tag(finalImg)))
136+
out.WarningT(fmt.Sprintf("minikube was unable to download %s, but successfully downloaded %s as a fallback image", image.Tag(baseImg), finalImg))
137137
}
138138
}
139139
}()
140+
// first we try to download the kicbase image (and fall back images) from docker registry
141+
var err error
140142
for _, img := range append([]string{baseImg}, kic.FallbackImages...) {
141-
var err error
142143

143144
if driver.IsDocker(cc.Driver) && download.ImageExistsInDaemon(img) && !downloadOnly {
144145
klog.Infof("%s exists in daemon, skipping load", img)
@@ -167,7 +168,23 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
167168
}
168169
klog.Infof("failed to download %s, will try fallback image if available: %v", img, err)
169170
}
170-
return fmt.Errorf("failed to download kic base image or any fallback image")
171+
// second if we failed to download any fallback image
172+
// that means probably all registries are blocked by network issues
173+
// we can try to download the image from minikube release page
174+
kicbaseVersion := strings.Split(kic.Version, "-")[0]
175+
finalImg, err = download.DownloadImageFromGithubToCache("kicbase", kicbaseVersion)
176+
if err != nil {
177+
klog.Infof("failed to download %s", finalImg)
178+
return fmt.Errorf("failed to download kic base image or any fallback image")
179+
}
180+
klog.Infof("successfully downloaded %s as fall back image", finalImg)
181+
if !downloadOnly && driver.IsDocker(cc.Driver) {
182+
if finalImg, err = download.CacheToDaemon("kicbase"); err == nil {
183+
klog.Infof("successfully loaded and using kicbase from tarball on github")
184+
}
185+
}
186+
return nil
187+
171188
})
172189
}
173190

0 commit comments

Comments
 (0)