@@ -393,6 +393,59 @@ function load-docker-images {
393
393
fi
394
394
}
395
395
396
+ # If we are on ubuntu we can try to install docker
397
+ function install-docker {
398
+ # bailout if we are not on ubuntu
399
+ if ! command -v apt-get > /dev/null 2>&1 ; then
400
+ echo " Unable to install automatically install docker. Bailing out..."
401
+ return
402
+ fi
403
+ # Install Docker deps, some of these are already installed in the image but
404
+ # that's fine since they won't re-install and we can reuse the code below
405
+ # for another image someday.
406
+ apt-get update
407
+ apt-get install -y --no-install-recommends \
408
+ apt-transport-https \
409
+ ca-certificates \
410
+ socat \
411
+ curl \
412
+ gnupg2 \
413
+ software-properties-common \
414
+ lsb-release
415
+
416
+ # Add the Docker apt-repository
417
+ curl -fsSL https://download.docker.com/linux/$( . /etc/os-release; echo " $ID " ) /gpg \
418
+ | apt-key add -
419
+ add-apt-repository \
420
+ " deb [arch=amd64] https://download.docker.com/linux/$( . /etc/os-release; echo " $ID " ) \
421
+ $( lsb_release -cs) stable"
422
+
423
+ # Install Docker
424
+ apt-get update && \
425
+ apt-get install -y --no-install-recommends ${GCI_DOCKER_VERSION:- " docker-ce=5:19.03.*" }
426
+ rm -rf /var/lib/apt/lists/*
427
+ }
428
+
429
+ function ensure-container-runtime {
430
+ container_runtime=" ${CONTAINER_RUNTIME:- docker} "
431
+ if [[ " ${container_runtime} " == " docker" ]]; then
432
+ if ! command -v docker > /dev/null 2>&1 ; then
433
+ install-docker
434
+ if ! command -v docker > /dev/null 2>&1 ; then
435
+ echo " ERROR docker not found. Aborting."
436
+ exit 2
437
+ fi
438
+ fi
439
+ docker version
440
+ elif [[ " ${container_runtime} " == " containerd" ]]; then
441
+ if ! command -v ctr > /dev/null 2>&1 ; then
442
+ echo " ERROR ctr not found. Aborting."
443
+ exit 2
444
+ fi
445
+ ctr version
446
+ fi
447
+ }
448
+
396
449
# Downloads kubernetes binaries and kube-system manifest tarball, unpacks them,
397
450
# and places them into suitable directories. Files are placed in /home/kubernetes.
398
451
function install-kube-binary-config {
@@ -492,6 +545,9 @@ if [[ "${KUBERNETES_MASTER:-}" == "true" ]]; then
492
545
download-kube-master-certs
493
546
fi
494
547
548
+ # ensure chosen container runtime is present
549
+ ensure-container-runtime
550
+
495
551
# binaries and kube-system manifests
496
552
install-kube-binary-config
497
553
0 commit comments