|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +### |
| 4 | +# Script Name: verify |
| 5 | +# |
| 6 | +# Description: This runs a smoke test to verify that the packages can be installed corrected |
| 7 | +### |
| 8 | + |
| 9 | +# packaging/build/${DIST_ID}/${DIST_VERSION}/${ARCH} - location of all packages |
| 10 | +# Manually Testing: docker run --rm -it -v $(pwd):/v -w /v "centos:7" ./verify |
| 11 | + |
| 12 | +set -e |
| 13 | + |
| 14 | +source install-containerd-helpers |
| 15 | + |
| 16 | +function verify() { |
| 17 | + if dpkg --version >/dev/null 2>/dev/null; then |
| 18 | + verify_deb |
| 19 | + elif rpm --version >/dev/null 2>/dev/null; then |
| 20 | + verify_rpm |
| 21 | + else |
| 22 | + echo "[ERROR] Unable to determine base os:" |
| 23 | + cat /etc/os-release |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | +} |
| 27 | + |
| 28 | +function verify_deb() { |
| 29 | + # First install prerequisites for our script and dpkg and apt to run correctly. |
| 30 | + # This list SHOULD NOT include dependencies of docker itself, otherwise we would |
| 31 | + # not be able to verify that our packages specify all the required dependencies. |
| 32 | + apt-get update |
| 33 | + apt-get -y install --no-install-recommends \ |
| 34 | + apt-transport-https \ |
| 35 | + ca-certificates \ |
| 36 | + curl \ |
| 37 | + gnupg2 \ |
| 38 | + lsb-release \ |
| 39 | + software-properties-common |
| 40 | + |
| 41 | + DIST_ID=$(source /etc/os-release; echo "$ID") |
| 42 | + DIST_VERSION=$(lsb_release -sc) |
| 43 | + if [ "${DIST_VERSION}" = "sid" ]; then |
| 44 | + echo 'Debian sid ("unstable") cannot be used for packaging: replace with the actual codename' |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + |
| 48 | + install_debian_containerd |
| 49 | + |
| 50 | + packages=$(find "packaging/deb/debbuild/${DIST_ID}-${DIST_VERSION}/" -type f -name "*.deb") |
| 51 | + # All local packages need to be prefixed with `./` or else apt-get doesn't understand where to pull from |
| 52 | + packages=$(echo "${packages}" | awk '$0="./"$0' | xargs) |
| 53 | + |
| 54 | + ( |
| 55 | + set -x |
| 56 | + # Install the locally built packages using 'dpkg' because installing with |
| 57 | + # 'apt-get' would attempt to install dependency packages (such as the CLI) |
| 58 | + # from download.docker.com instead of the locally built CLI package. Given |
| 59 | + # that 'dpkg -i' does not install any dependency (but will fail if depen- |
| 60 | + # dencies are missing), we use the '--ignore-depends' option to ignore |
| 61 | + # packages we know to be missing at this stage, and '--force-depends' to |
| 62 | + # only warn about any other missing dependency. |
| 63 | + # |
| 64 | + # shellcheck disable=SC2086 |
| 65 | + dpkg \ |
| 66 | + --ignore-depends=containerd.io,iptables,libdevmapper,libdevmapper1.02.1 \ |
| 67 | + --force-depends \ |
| 68 | + -i ${packages} |
| 69 | + |
| 70 | + # After installing the local packages, we run 'apt-get install' with the |
| 71 | + # '--fix-broken' option to trigger installation of the dependencies, which |
| 72 | + # should succeed successfully. This step is to verify that not only the |
| 73 | + # packages can be installed, but also that all dependencies (including |
| 74 | + # containerd.io) can be resolved correctly for the distro that we built for, |
| 75 | + # before going through the whole pipeline and publishing the packages. |
| 76 | + # |
| 77 | + # The '--no-upgrade' option is set to prevent apt from attempting to install |
| 78 | + # packages from download(-stage).docker.com that we already installed using |
| 79 | + # the local packages above. Without this, installing (e.g.) ./docker-ce-cli |
| 80 | + # would result in apt installing "docker-ce" from the package repository and |
| 81 | + # produce a "the following packages will be DOWNGRADED" error. |
| 82 | + # |
| 83 | + # shellcheck disable=SC2086 |
| 84 | + apt-get -y install --no-install-recommends --no-upgrade --fix-broken ${packages} |
| 85 | + ) |
| 86 | + docker --version |
| 87 | + # FIXME this tries to connect to the docker daemon, which isn't started |
| 88 | + #if [ "$(uname -m)" = "x86_64" ]; then |
| 89 | + # docker scan --accept-license --version; |
| 90 | + #fi |
| 91 | + dockerd --version |
| 92 | + containerd --version |
| 93 | + runc --version |
| 94 | +} |
| 95 | + |
| 96 | +function verify_rpm() { |
| 97 | + DIST_ID=$(. /etc/os-release; echo "${ID}") |
| 98 | + DIST_VERSION=$(. /etc/os-release; echo "${VERSION_ID}" | cut -d'.' -f1) |
| 99 | + |
| 100 | + pkg_manager="yum" |
| 101 | + pkg_config_manager="yum-config-manager" |
| 102 | + if dnf --version; then |
| 103 | + pkg_manager="dnf" |
| 104 | + pkg_config_manager="dnf config-manager" |
| 105 | + dnf clean all && dnf upgrade -y |
| 106 | + ${pkg_manager} install -y 'dnf-command(config-manager)' |
| 107 | + fi |
| 108 | + |
| 109 | + case ${DIST_ID}:${DIST_VERSION} in |
| 110 | + ol:7*) |
| 111 | + # Needed for container-selinux |
| 112 | + ${pkg_config_manager} --enable ol7_addons |
| 113 | + ;; |
| 114 | + fedora*) |
| 115 | + dnf install -y findutils |
| 116 | + ;; |
| 117 | + esac |
| 118 | + |
| 119 | + install_rpm_containerd |
| 120 | + |
| 121 | + # find all rpm packages, exclude src package |
| 122 | + echo "[DEBUG] Installing engine rpms" |
| 123 | + packages=$(find "packaging/rpm/rpmbuild/${DIST_ID}-${DIST_VERSION}/RPMS/" -type f -name "*.rpm" | sed '/src/d') |
| 124 | + |
| 125 | + # install all non-source packages |
| 126 | + ( |
| 127 | + set -x |
| 128 | + ${pkg_manager} install -y ${packages} |
| 129 | + ) |
| 130 | + |
| 131 | + docker --version |
| 132 | + # FIXME this tries to connect to the docker daemon, which isn't started |
| 133 | + #if [ "$(uname -m)" = "x86_64" ]; then |
| 134 | + # docker scan --accept-license --version; |
| 135 | + #fi |
| 136 | + dockerd --version |
| 137 | + containerd --version |
| 138 | + runc --version |
| 139 | + |
| 140 | +} |
| 141 | + |
| 142 | +verify |
0 commit comments