@@ -407,7 +407,7 @@ function load-docker-images {
407
407
function install-docker {
408
408
# bailout if we are not on ubuntu
409
409
if ! command -v apt-get > /dev/null 2>&1 ; then
410
- echo " Unable to install automatically install docker. Bailing out..."
410
+ echo " Unable to automatically install docker. Bailing out..."
411
411
return
412
412
fi
413
413
# Install Docker deps, some of these are already installed in the image but
@@ -436,6 +436,55 @@ function install-docker {
436
436
rm -rf /var/lib/apt/lists/*
437
437
}
438
438
439
+ # If we are on ubuntu we can try to install containerd
440
+ function install-containerd-ubuntu {
441
+ # bailout if we are not on ubuntu
442
+ if [[ -z " $( command -v lsb_release) " || $( lsb_release -si) != " Ubuntu" ]]; then
443
+ echo " Unable to automatically install containerd in non-ubuntu image. Bailing out..."
444
+ exit 2
445
+ fi
446
+
447
+ if [[ $( dpkg --print-architecture) != " amd64" ]]; then
448
+ echo " Unable to automatically install containerd in non-amd64 image. Bailing out..."
449
+ exit 2
450
+ fi
451
+
452
+ # Install dependencies, some of these are already installed in the image but
453
+ # that's fine since they won't re-install and we can reuse the code below
454
+ # for another image someday.
455
+ apt-get update
456
+ apt-get install -y --no-install-recommends \
457
+ apt-transport-https \
458
+ ca-certificates \
459
+ socat \
460
+ curl \
461
+ gnupg2 \
462
+ software-properties-common \
463
+ lsb-release
464
+
465
+ # Add the Docker apt-repository (as we install containerd from there)
466
+ curl -fsSL https://download.docker.com/linux/$( . /etc/os-release; echo " $ID " ) /gpg \
467
+ | apt-key add -
468
+ add-apt-repository \
469
+ " deb [arch=amd64] https://download.docker.com/linux/$( . /etc/os-release; echo " $ID " ) \
470
+ $( lsb_release -cs) stable"
471
+
472
+ # Install containerd from Docker repo
473
+ apt-get update && \
474
+ apt-get install -y --no-install-recommends containerd
475
+ rm -rf /var/lib/apt/lists/*
476
+
477
+ # Override to latest versions of containerd and runc
478
+ systemctl stop containerd
479
+ if [[ ! -z " ${UBUNTU_INSTALL_CONTAINERD_VERSION:- } " ]]; then
480
+ curl -fsSL " https://github.com/containerd/containerd/releases/download/${UBUNTU_INSTALL_CONTAINERD_VERSION} /containerd-${UBUNTU_INSTALL_CONTAINERD_VERSION: 1} .linux-amd64.tar.gz" | tar --overwrite -xzv -C /usr/
481
+ fi
482
+ if [[ ! -z " ${UBUNTU_INSTALL_RUNC_VERSION:- } " ]]; then
483
+ curl -fsSL " https://github.com/opencontainers/runc/releases/download/${UBUNTU_INSTALL_RUNC_VERSION} /runc.amd64" --output /usr/sbin/runc && chmod 755 /usr/sbin/runc
484
+ fi
485
+ sudo systemctl start containerd
486
+ }
487
+
439
488
function ensure-container-runtime {
440
489
container_runtime=" ${CONTAINER_RUNTIME:- docker} "
441
490
if [[ " ${container_runtime} " == " docker" ]]; then
@@ -448,11 +497,28 @@ function ensure-container-runtime {
448
497
fi
449
498
docker version
450
499
elif [[ " ${container_runtime} " == " containerd" ]]; then
500
+ # Install containerd/runc if requested
501
+ if [[ ! -z " ${UBUNTU_INSTALL_CONTAINERD_VERSION:- } " || ! -z " ${UBUNTU_INSTALL_RUNC_VERSION} " ]]; then
502
+ install-containerd-ubuntu
503
+ fi
504
+ # Verify presence and print versions of ctr, containerd, runc
451
505
if ! command -v ctr > /dev/null 2>&1 ; then
452
506
echo " ERROR ctr not found. Aborting."
453
507
exit 2
454
508
fi
455
- ctr version
509
+ ctr --version
510
+
511
+ if ! command -v containerd > /dev/null 2>&1 ; then
512
+ echo " ERROR containerd not found. Aborting."
513
+ exit 2
514
+ fi
515
+ containerd --version
516
+
517
+ if ! command -v runc > /dev/null 2>&1 ; then
518
+ echo " ERROR runc not found. Aborting."
519
+ exit 2
520
+ fi
521
+ runc --version
456
522
fi
457
523
}
458
524
0 commit comments