Skip to content

Commit 9edfa35

Browse files
committed
scripts/coverity-scan: Add Docker support
Add support for running the Coverity Scan tools inside a Docker container rather than directly on the host system. Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Peter Maydell <[email protected]> Message-id: [email protected]
1 parent 9c263d0 commit 9edfa35

File tree

2 files changed

+221
-0
lines changed

2 files changed

+221
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# syntax=docker/dockerfile:1.0.0-experimental
2+
#
3+
# Docker setup for running the "Coverity Scan" tools over the source
4+
# tree and uploading them to the website, as per
5+
# https://scan.coverity.com/projects/qemu/builds/new
6+
# We do this on a fixed config (currently Fedora 30 with a known
7+
# set of dependencies and a configure command that enables a specific
8+
# set of options) so that random changes don't result in our accidentally
9+
# dropping some files from the scan.
10+
#
11+
# We don't build on top of the fedora.docker file because we don't
12+
# want to accidentally change or break the scan config when that
13+
# is updated.
14+
15+
# The work of actually doing the build is handled by the
16+
# run-coverity-scan script.
17+
18+
FROM fedora:30
19+
ENV PACKAGES \
20+
alsa-lib-devel \
21+
bc \
22+
bison \
23+
brlapi-devel \
24+
bzip2 \
25+
bzip2-devel \
26+
ccache \
27+
clang \
28+
curl \
29+
cyrus-sasl-devel \
30+
dbus-daemon \
31+
device-mapper-multipath-devel \
32+
findutils \
33+
flex \
34+
gcc \
35+
gcc-c++ \
36+
gettext \
37+
git \
38+
glib2-devel \
39+
glusterfs-api-devel \
40+
gnutls-devel \
41+
gtk3-devel \
42+
hostname \
43+
libaio-devel \
44+
libasan \
45+
libattr-devel \
46+
libblockdev-mpath-devel \
47+
libcap-devel \
48+
libcap-ng-devel \
49+
libcurl-devel \
50+
libepoxy-devel \
51+
libfdt-devel \
52+
libgbm-devel \
53+
libiscsi-devel \
54+
libjpeg-devel \
55+
libpmem-devel \
56+
libnfs-devel \
57+
libpng-devel \
58+
librbd-devel \
59+
libseccomp-devel \
60+
libssh-devel \
61+
libubsan \
62+
libudev-devel \
63+
libusbx-devel \
64+
libxml2-devel \
65+
libzstd-devel \
66+
llvm \
67+
lzo-devel \
68+
make \
69+
mingw32-bzip2 \
70+
mingw32-curl \
71+
mingw32-glib2 \
72+
mingw32-gmp \
73+
mingw32-gnutls \
74+
mingw32-gtk3 \
75+
mingw32-libjpeg-turbo \
76+
mingw32-libpng \
77+
mingw32-libtasn1 \
78+
mingw32-nettle \
79+
mingw32-nsis \
80+
mingw32-pixman \
81+
mingw32-pkg-config \
82+
mingw32-SDL2 \
83+
mingw64-bzip2 \
84+
mingw64-curl \
85+
mingw64-glib2 \
86+
mingw64-gmp \
87+
mingw64-gnutls \
88+
mingw64-gtk3 \
89+
mingw64-libjpeg-turbo \
90+
mingw64-libpng \
91+
mingw64-libtasn1 \
92+
mingw64-nettle \
93+
mingw64-pixman \
94+
mingw64-pkg-config \
95+
mingw64-SDL2 \
96+
ncurses-devel \
97+
nettle-devel \
98+
nss-devel \
99+
numactl-devel \
100+
perl \
101+
perl-Test-Harness \
102+
pixman-devel \
103+
pulseaudio-libs-devel \
104+
python3 \
105+
python3-sphinx \
106+
PyYAML \
107+
rdma-core-devel \
108+
SDL2-devel \
109+
snappy-devel \
110+
sparse \
111+
spice-server-devel \
112+
systemd-devel \
113+
systemtap-sdt-devel \
114+
tar \
115+
texinfo \
116+
usbredir-devel \
117+
virglrenderer-devel \
118+
vte291-devel \
119+
wget \
120+
which \
121+
xen-devel \
122+
xfsprogs-devel \
123+
zlib-devel
124+
ENV QEMU_CONFIGURE_OPTS --python=/usr/bin/python3
125+
126+
RUN dnf install -y $PACKAGES
127+
RUN rpm -q $PACKAGES | sort > /packages.txt
128+
ENV PATH $PATH:/usr/libexec/python3-sphinx/
129+
ENV COVERITY_TOOL_BASE=/coverity-tools
130+
COPY run-coverity-scan run-coverity-scan
131+
RUN --mount=type=secret,id=coverity.token,required ./run-coverity-scan --update-tools-only --tokenfile /run/secrets/coverity.token

scripts/coverity-scan/run-coverity-scan

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@
2929

3030
# Command line options:
3131
# --dry-run : run the tools, but don't actually do the upload
32+
# --docker : create and work inside a docker container
3233
# --update-tools-only : update the cached copy of the tools, but don't run them
3334
# --tokenfile : file to read Coverity token from
3435
# --version ver : specify version being analyzed (default: ask git)
3536
# --description desc : specify description of this version (default: ask git)
3637
# --srcdir : QEMU source tree to analyze (default: current working dir)
3738
# --results-tarball : path to copy the results tarball to (default: don't
3839
# copy it anywhere, just upload it)
40+
# --src-tarball : tarball to untar into src dir (default: none); this
41+
# is intended mainly for internal use by the Docker support
3942
#
4043
# User-specifiable environment variables:
4144
# COVERITY_TOKEN -- Coverity token
@@ -125,6 +128,7 @@ update_coverity_tools () {
125128
# Check user-provided environment variables and arguments
126129
DRYRUN=no
127130
UPDATE_ONLY=no
131+
DOCKER=no
128132

129133
while [ "$#" -ge 1 ]; do
130134
case "$1" in
@@ -181,6 +185,19 @@ while [ "$#" -ge 1 ]; do
181185
RESULTSTARBALL="$1"
182186
shift
183187
;;
188+
--src-tarball)
189+
shift
190+
if [ $# -eq 0 ]; then
191+
echo "--src-tarball needs an argument"
192+
exit 1
193+
fi
194+
SRCTARBALL="$1"
195+
shift
196+
;;
197+
--docker)
198+
DOCKER=yes
199+
shift
200+
;;
184201
*)
185202
echo "Unexpected argument '$1'"
186203
exit 1
@@ -212,6 +229,10 @@ PROJTOKEN="$COVERITY_TOKEN"
212229
PROJNAME=QEMU
213230
TARBALL=cov-int.tar.xz
214231

232+
if [ "$UPDATE_ONLY" = yes ] && [ "$DOCKER" = yes ]; then
233+
echo "Combining --docker and --update-only is not supported"
234+
exit 1
235+
fi
215236

216237
if [ "$UPDATE_ONLY" = yes ]; then
217238
# Just do the tools update; we don't need to check whether
@@ -221,8 +242,17 @@ if [ "$UPDATE_ONLY" = yes ]; then
221242
exit 0
222243
fi
223244

245+
if [ ! -e "$SRCDIR" ]; then
246+
mkdir "$SRCDIR"
247+
fi
248+
224249
cd "$SRCDIR"
225250

251+
if [ ! -z "$SRCTARBALL" ]; then
252+
echo "Untarring source tarball into $SRCDIR..."
253+
tar xvf "$SRCTARBALL"
254+
fi
255+
226256
echo "Checking this is a QEMU source tree..."
227257
if ! [ -e "$SRCDIR/VERSION" ]; then
228258
echo "Not in a QEMU source tree?"
@@ -242,6 +272,66 @@ if [ -z "$COVERITY_EMAIL" ]; then
242272
COVERITY_EMAIL="$(git config user.email)"
243273
fi
244274

275+
# Run ourselves inside docker if that's what the user wants
276+
if [ "$DOCKER" = yes ]; then
277+
# build docker container including the coverity-scan tools
278+
# Put the Coverity token into a temporary file that only
279+
# we have read access to, and then pass it to docker build
280+
# using --secret. This requires at least Docker 18.09.
281+
# Mostly what we are trying to do here is ensure we don't leak
282+
# the token into the Docker image.
283+
umask 077
284+
SECRETDIR=$(mktemp -d)
285+
if [ -z "$SECRETDIR" ]; then
286+
echo "Failed to create temporary directory"
287+
exit 1
288+
fi
289+
trap 'rm -rf "$SECRETDIR"' INT TERM EXIT
290+
echo "Created temporary directory $SECRETDIR"
291+
SECRET="$SECRETDIR/token"
292+
echo "$COVERITY_TOKEN" > "$SECRET"
293+
echo "Building docker container..."
294+
# TODO: This re-downloads the tools every time, rather than
295+
# caching and reusing the image produced with the downloaded tools.
296+
# Not sure why.
297+
# TODO: how do you get 'docker build' to print the output of the
298+
# commands it is running to its stdout? This would be useful for debug.
299+
DOCKER_BUILDKIT=1 docker build -t coverity-scanner \
300+
--secret id=coverity.token,src="$SECRET" \
301+
-f scripts/coverity-scan/coverity-scan.docker \
302+
scripts/coverity-scan
303+
echo "Archiving sources to be analyzed..."
304+
./scripts/archive-source.sh "$SECRETDIR/qemu-sources.tgz"
305+
if [ "$DRYRUN" = yes ]; then
306+
DRYRUNARG=--dry-run
307+
fi
308+
echo "Running scanner..."
309+
# If we need to capture the output tarball, get the inner run to
310+
# save it to the secrets directory so we can copy it out before the
311+
# directory is cleaned up.
312+
if [ ! -z "$RESULTSTARBALL" ]; then
313+
RTARGS="--results-tarball /work/cov-int.tar.xz"
314+
else
315+
RTARGS=""
316+
fi
317+
# Arrange for this docker run to get access to the sources with -v.
318+
# We pass through all the configuration from the outer script to the inner.
319+
export COVERITY_EMAIL COVERITY_BUILD_CMD
320+
docker run -it --env COVERITY_EMAIL --env COVERITY_BUILD_CMD \
321+
-v "$SECRETDIR:/work" coverity-scanner \
322+
./run-coverity-scan --version "$VERSION" \
323+
--description "$DESCRIPTION" $DRYRUNARG --tokenfile /work/token \
324+
--srcdir /qemu --src-tarball /work/qemu-sources.tgz $RTARGS
325+
if [ ! -z "$RESULTSTARBALL" ]; then
326+
echo "Copying results tarball to $RESULTSTARBALL..."
327+
cp "$SECRETDIR/cov-int.tar.xz" "$RESULTSTARBALL"
328+
fi
329+
echo "Docker work complete."
330+
exit 0
331+
fi
332+
333+
# Otherwise, continue with the full build and upload process.
334+
245335
check_upload_permissions
246336

247337
update_coverity_tools

0 commit comments

Comments
 (0)