Skip to content

Commit 9e18d43

Browse files
authored
Merge pull request #697 from thaJeztah/integrate_verify
[master] Makefile: add "verify" target to test install of packages
2 parents 80b286b + 6978154 commit 9e18d43

File tree

5 files changed

+234
-6
lines changed

5 files changed

+234
-6
lines changed

Jenkinsfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ def genBuildStep(LinkedHashMap pkg, String arch) {
4444
sh 'docker info'
4545
}
4646
stage("build") {
47-
try {
48-
checkout scm
49-
sh "make REF=$branch ${pkg.target}"
50-
} finally {
51-
sh "make clean"
52-
}
47+
checkout scm
48+
sh "make clean"
49+
sh "make REF=$branch ${pkg.target}"
50+
}
51+
stage("verify") {
52+
sh "make IMAGE=${pkg.image} verify"
5353
}
5454
}
5555
}

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,13 @@ static: checkout ## build static-compiled packages
9797
for p in $(DOCKER_BUILD_PKGS); do \
9898
$(MAKE) -C $@ VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) TARGETPLATFORM=$(TARGETPLATFORM) CONTAINERD_VERSION=$(CONTAINERD_VERSION) RUNC_VERSION=$(RUNC_VERSION) $${p}; \
9999
done
100+
101+
.PHONY: verify
102+
verify: ## verify installation of packages
103+
# to verify using packages from staging, use: make VERIFY_PACKAGE_REPO=stage IMAGE=ubuntu:focal verify
104+
docker run $(VERIFY_PLATFORM) --rm -i \
105+
-v "$$(pwd):/v" \
106+
-e DEBIAN_FRONTEND=noninteractive \
107+
-e PACKAGE_REPO=$(VERIFY_PACKAGE_REPO) \
108+
-w /v \
109+
$(IMAGE) ./verify

common.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ DOCKER_SCAN_REF ?= v0.17.0
4343
DOCKER_COMPOSE_REF ?= v2.5.1
4444
DOCKER_BUILDX_REF ?= v0.8.2
4545

46+
# Use "stage" to install dependencies from download-stage.docker.com during the
47+
# verify step. Leave empty or use any other value to install from download.docker.com
48+
VERIFY_PACKAGE_REPO ?= staging
49+
50+
# Optional flags like --platform=linux/armhf
51+
VERIFY_PLATFORM ?=
52+
4653
export BUILDTIME
4754
export DEFAULT_PRODUCT_LICENSE
4855
export PACKAGER_NAME

install-containerd-helpers

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bash
2+
3+
###
4+
# Script Name: install-containerd-helpers
5+
#
6+
# Description: A library that containers helpers to install containerd on different
7+
# distributions based on a package manager
8+
###
9+
set -x extglob
10+
11+
# Steps taken from: https://docs.docker.com/install/linux/docker-ce/centos/
12+
function install_rpm_containerd() {
13+
if [ "${PACKAGE_REPO}" = "stage" ]; then
14+
REPO_URL="https://download-stage.docker.com/linux/${DIST_ID}/docker-ce-staging.repo"
15+
else
16+
REPO_URL="https://download.docker.com/linux/${DIST_ID}/docker-ce.repo"
17+
fi
18+
19+
# Install containerd dependency for non-zypper dependecies
20+
echo "[DEBUG] Installing engine dependencies from ${REPO_URL}"
21+
22+
# Note: we enable test channel to be able to test non-stable containerd packages as well.
23+
# Once a containerd package becomes stable it will also be available in the test channel,
24+
# so this logic works for both cases.
25+
# (See also same logic in install_debian_containerd)
26+
27+
if dnf --version; then
28+
dnf config-manager --add-repo "${REPO_URL}"
29+
dnf config-manager --set-disabled docker-ce-*
30+
dnf config-manager --set-enabled docker-ce-test
31+
dnf makecache
32+
else
33+
yum-config-manager --add-repo "${REPO_URL}"
34+
yum-config-manager --disable docker-ce-*
35+
yum-config-manager --enable docker-ce-test
36+
yum makecache
37+
fi
38+
}
39+
40+
# Steps taken from: https://docs.docker.com/install/linux/docker-ce/ubuntu/
41+
function install_debian_containerd() {
42+
if [ "${PACKAGE_REPO}" = "stage" ]; then
43+
REPO_URL="https://download-stage.docker.com/linux/${DIST_ID}"
44+
else
45+
REPO_URL="https://download.docker.com/linux/${DIST_ID}"
46+
fi
47+
48+
echo "[DEBUG] Installing engine dependencies from ${REPO_URL}"
49+
50+
#TODO include this step in the get.docker.com installation script
51+
# Make sure ca-certificates are up-to-date
52+
update-ca-certificates -f
53+
54+
curl -fsSL "${REPO_URL}/gpg" | apt-key add -
55+
56+
if [ "${DIST_VERSION}" = "sid" ]; then
57+
echo 'Debian sid ("unstable") cannot be used for packaging: replace with the actual codename'
58+
exit 1
59+
fi
60+
ARCH=$(dpkg --print-architecture)
61+
62+
# Note: we enable test channel to be able to test non-stable containerd packages as well.
63+
# Once a containerd package becomes stable it will also be available in the test channel,
64+
# so this logic works for both cases.
65+
# (See also same logic in install_rpm_containerd)
66+
echo "deb [arch=${ARCH}] ${REPO_URL} ${DIST_VERSION} test" > /etc/apt/sources.list.d/docker.list
67+
68+
apt-get update
69+
}

verify

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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+
# 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 "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 "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

Comments
 (0)