blob: d474d1e0ff4d91c90bd0fbe377a79c966e901108 [file] [log] [blame]
Matthew Barthb4aea672016-11-10 14:59:52 -06001#!/bin/bash -xe
2#
3# Build the required docker image to run package unit tests
4#
5# Parameters:
6# param1: <optional, the name of the docker image to generate>
7# default is openbmc/ubuntu-unit-test
8# param2: <optional, the distro to build a docker image against>
Andrew Geissler8557b962018-06-25 16:10:32 -05009# default is ubuntu:artful
Matthew Barthb4aea672016-11-10 14:59:52 -060010
11set -uo pipefail
12
13DOCKER_IMG_NAME=${1:-"openbmc/ubuntu-unit-test"}
Patrick Venture52164fd2018-08-28 16:12:47 -070014DISTRO=${2:-"ubuntu:bionic"}
Matthew Barthb4aea672016-11-10 14:59:52 -060015
Matthew Barthccb7f852016-11-23 17:43:02 -060016# Disable autom4te cache as workaround to permission issue
17AUTOM4TE_CFG="/root/.autom4te.cfg"
18AUTOM4TE="begin-language: \"Autoconf-without-aclocal-m4\"\nargs: --no-cache\n\
19end-language: \"Autoconf-without-aclocal-m4\""
20
Matthew Barthb4aea672016-11-10 14:59:52 -060021# Determine the architecture
22ARCH=$(uname -m)
23case ${ARCH} in
24 "ppc64le")
25 DOCKER_BASE="ppc64le/"
26 ;;
27 "x86_64")
28 DOCKER_BASE=""
29 ;;
30 *)
31 echo "Unsupported system architecture(${ARCH}) found for docker image"
32 exit 1
33esac
34
William A. Kennington III32deed82018-09-17 20:48:23 -070035# Setup temporary files
36DEPCACHE_FILE=""
37cleanup() {
38 local status="$?"
39 if [ -n "$DEPCACHE_FILE" ]; then
40 rm -f "$DEPCACHE_FILE"
41 fi
42 trap - EXIT ERR
43 exit "$status"
44}
45trap cleanup EXIT ERR INT TERM QUIT
46DEPCACHE_FILE="$(mktemp)"
47
William A. Kennington III4815f702018-10-03 19:27:42 -070048HEAD_PKGS=(
William A. Kennington IIIb4f730a2018-09-12 11:21:20 -070049 phosphor-objmgr
50 sdbusplus
51 sdeventplus
Patrick Venture22329962018-09-14 10:23:04 -070052 gpioplus
William A. Kennington IIIb4f730a2018-09-12 11:21:20 -070053 phosphor-logging
54 phosphor-dbus-interfaces
55 openpower-dbus-interfaces
56)
William A. Kennington III32deed82018-09-17 20:48:23 -070057
58# Generate a list of depcache entries
59# We want to do this in parallel since the package list is growing
60# and the network lookup is low overhead but decently high latency.
61# This doesn't worry about producing a stable DEPCACHE_FILE, that is
62# done by readers who need a stable ordering.
63generate_depcache_entry() {
64 local package="$1"
65
66 local tip
67 tip=$(git ls-remote "https://github.com/openbmc/${package}" |
68 grep 'refs/heads/master' | awk '{ print $1 }')
69
70 # Lock the file to avoid interlaced writes
71 exec 3>> "$DEPCACHE_FILE"
72 flock -x 3
73 echo "$package:$tip" >&3
74 exec 3>&-
75}
William A. Kennington III4815f702018-10-03 19:27:42 -070076for package in "${HEAD_PKGS[@]}"; do
William A. Kennington III32deed82018-09-17 20:48:23 -070077 generate_depcache_entry "$package" &
Andrew Jeffery221eeda2018-03-08 13:32:43 +103078done
William A. Kennington III32deed82018-09-17 20:48:23 -070079wait
Andrew Jeffery221eeda2018-03-08 13:32:43 +103080
William A. Kennington III4815f702018-10-03 19:27:42 -070081# A list of package versions we are building
William A. Kennington IIIc227fb72018-10-03 19:44:33 -070082# Start off by listing the stating versions of third-party sources
83declare -A PKG_REV=(
84 [boost]=1.66.0
85 [cereal]=v1.2.2
86 # Snapshot from 2018-06-14
87 [googletest]=ba96d0b1161f540656efdaed035b3c062b60e006
88 [json]=v3.0.1
89 # libvncserver commit dd873fce451e4b7d7cc69056a62e107aae7c8e7a is required for obmc-ikvm
90 [libvncserver]=dd873fce451e4b7d7cc69056a62e107aae7c8e7a
91 # version from meta-openembedded/meta-oe/recipes-support/libtinyxml2/libtinyxml2_5.0.1.bb
92 [tinyxml2]=37bc3aca429f0164adf68c23444540b4a24b5778
93)
William A. Kennington III4815f702018-10-03 19:27:42 -070094
95# Turn the depcache into a dictionary so we can reference the HEAD of each repo
96for line in $(cat "$DEPCACHE_FILE"); do
97 linearr=($(echo "$line" | tr ':' ' '))
98 PKG_REV["${linearr[0]}"]="${linearr[1]}"
99done
100
William A. Kennington III3cf94fd2018-10-03 19:16:55 -0700101# Define common flags used for builds
102PREFIX="/usr/local"
103CONFIGURE_FLAGS=(
104 "--prefix=${PREFIX}"
105)
William A. Kennington III4a67c402018-10-03 15:53:56 -0700106CMAKE_FLAGS=(
107 "-DCMAKE_BUILD_TYPE=RelWithDebInfo"
108 "-DBUILD_SHARED_LIBS=ON"
William A. Kennington III3cf94fd2018-10-03 19:16:55 -0700109 "-DCMAKE_INSTALL_PREFIX:PATH=${PREFIX}"
William A. Kennington III4a67c402018-10-03 15:53:56 -0700110)
111
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700112# Build the commands needed to compose our final image
113COPY_CMDS=""
114# We must sort the packages, otherwise we might produce an unstable
115# docker file and rebuild the image unnecessarily
116for pkg in $(echo "${!PKG_REV[@]}" | tr ' ' '\n' | LC_COLLATE=C sort -s); do
117 COPY_CMDS+="COPY --from=openbmc-${pkg} ${PREFIX} ${PREFIX}"$'\n'
118done
119
Matthew Barthb4aea672016-11-10 14:59:52 -0600120################################# docker img # #################################
121# Create docker image that can run package unit tests
122if [[ "${DISTRO}" == "ubuntu"* ]]; then
123Dockerfile=$(cat << EOF
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700124FROM ${DOCKER_BASE}${DISTRO} as openbmc-base
Matthew Barthb4aea672016-11-10 14:59:52 -0600125
126ENV DEBIAN_FRONTEND noninteractive
127
William A. Kennington IIIb1da1272018-06-20 13:28:05 -0700128# We need the keys to be imported for dbgsym repos
129# New releases have a package, older ones fall back to manual fetching
130# https://wiki.ubuntu.com/Debug%20Symbol%20Packages
131RUN apt-get update && ( apt-get install ubuntu-dbgsym-keyring || ( apt-get install -yy dirmngr && \
132 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F2EDC64DC5AEE1F6B9C621F0C8CAB6595FDFF622 ) )
133
134# Parse the current repo list into a debug repo list
135RUN sed -n '/^deb /s,^deb [^ ]* ,deb http://ddebs.ubuntu.com ,p' /etc/apt/sources.list >/etc/apt/sources.list.d/debug.list
136
137# Remove non-existent debug repos
138RUN sed -i '/-\(backports\|security\) /d' /etc/apt/sources.list.d/debug.list
139
140RUN cat /etc/apt/sources.list.d/debug.list
141
Matthew Barthb4aea672016-11-10 14:59:52 -0600142RUN apt-get update && apt-get install -yy \
143 gcc \
144 g++ \
William A. Kennington IIIb1da1272018-06-20 13:28:05 -0700145 libc6-dbg \
Matthew Barthb4aea672016-11-10 14:59:52 -0600146 libc6-dev \
147 libtool \
148 cmake \
149 python \
150 python-dev \
Matthew Barthccb7f852016-11-23 17:43:02 -0600151 python-git \
Matthew Barth0e90f3c2017-01-16 13:43:05 -0600152 python-yaml \
Matthew Barth6cc35d82017-01-18 13:36:31 -0600153 python-mako \
Andrew Jefferyb7206972018-04-30 11:57:29 +0930154 python-pip \
Matthew Barthb4aea672016-11-10 14:59:52 -0600155 python-setuptools \
William A. Kennington III22658b02018-06-29 15:55:17 -0700156 python-socks \
Saqib Khan362ca852017-03-21 10:48:46 -0500157 python3 \
158 python3-dev\
159 python3-yaml \
160 python3-mako \
Andrew Jefferyb7206972018-04-30 11:57:29 +0930161 python3-pip \
Saqib Khan362ca852017-03-21 10:48:46 -0500162 python3-setuptools \
Matthew Barthb4aea672016-11-10 14:59:52 -0600163 pkg-config \
164 autoconf \
William A. Kennington III7e46dd82018-06-20 01:17:03 -0700165 autoconf-archive \
Matthew Barthb4aea672016-11-10 14:59:52 -0600166 libsystemd-dev \
William A. Kennington IIIb1da1272018-06-20 13:28:05 -0700167 libsystemd0-dbgsym \
Matthew Barth92f93872017-02-08 11:19:27 -0600168 libssl-dev \
Matthew Barth550bc0d2017-04-10 13:25:50 -0500169 libevdev-dev \
William A. Kennington IIIb1da1272018-06-20 13:28:05 -0700170 libevdev2-dbgsym \
Eddie James61c89bb2018-09-06 13:48:53 -0500171 libjpeg-dev \
William A. Kennington IIIbb71cc02018-10-03 19:19:23 -0700172 libpng-dev \
Matthew Barthb4aea672016-11-10 14:59:52 -0600173 sudo \
William A. Kennington III22658b02018-06-29 15:55:17 -0700174 curl \
Leonel Gonzalez13ca3802017-03-07 14:08:44 -0600175 git \
Saqib Khan5158a322017-10-23 11:31:24 -0500176 dbus \
Andrew Geissler158b0a12018-01-10 10:46:48 -0800177 iputils-ping \
Patrick Venture52164fd2018-08-28 16:12:47 -0700178 clang-format-6.0 \
Ratan Gupta2f03fd72018-03-30 22:48:11 +0530179 iproute2 \
180 libnl-3-dev \
Patrick Venture643d8d02018-05-10 08:57:15 -0700181 libnl-genl-3-dev \
Ratan Guptaa0a1e332018-05-25 10:37:33 +0530182 libconfig++-dev \
William A. Kennington III9e2be202018-06-19 19:35:43 -0700183 libsnmp-dev \
184 valgrind \
William A. Kennington IIIb1da1272018-06-20 13:28:05 -0700185 valgrind-dbg \
Richard Marian Thomaiyar24660002018-06-26 21:50:57 +0530186 lcov \
James Feist878df5c2018-07-26 14:54:28 -0700187 libpam0g-dev \
Ratan Gupta48347e02018-08-08 17:43:10 +0530188 xxd \
James Feist182bbf32018-10-03 09:42:44 -0700189 libi2c-dev \
Andrew Geissler61a33972018-10-05 05:41:30 -0500190 wget \
191 libldap2-dev
Matthew Barthb4aea672016-11-10 14:59:52 -0600192
Matthew Bartha2366d92017-01-31 09:46:20 -0600193RUN pip install inflection
Adriana Kobylak3b02d3f2018-01-10 16:33:26 -0600194RUN pip install pycodestyle
Matthew Bartha2366d92017-01-31 09:46:20 -0600195
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700196FROM openbmc-base as openbmc-googletest
William A. Kennington IIIc227fb72018-10-03 19:44:33 -0700197RUN curl -L https://github.com/google/googletest/archive/${PKG_REV['googletest']}.tar.gz | tar -xz && \
William A. Kennington III5b550082018-10-03 19:25:49 -0700198cd googletest-* && \
William A. Kennington IIIb47eea52018-10-03 17:11:29 -0700199mkdir build && \
200cd build && \
201cmake ${CMAKE_FLAGS[@]} -DBUILD_GTEST=ON -DBUILD_GMOCK=ON .. && \
William A. Kennington III048b5ee2018-10-03 19:37:56 -0700202make -j$(nproc) && \
203make install
Matthew Barthb4aea672016-11-10 14:59:52 -0600204
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700205FROM openbmc-base as openbmc-cereal
William A. Kennington IIIc227fb72018-10-03 19:44:33 -0700206RUN curl -L https://github.com/USCiLab/cereal/archive/${PKG_REV['cereal']}.tar.gz | tar -xz && \
207cp -a cereal-*/include/cereal/ ${PREFIX}/include/
Deepak Kodihallide7767c2017-06-21 02:19:14 -0500208
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700209FROM openbmc-base as openbmc-json
William A. Kennington IIIc8e8b202018-10-03 19:35:59 -0700210RUN mkdir ${PREFIX}/include/nlohmann/ && \
William A. Kennington IIIc227fb72018-10-03 19:44:33 -0700211curl -L -o ${PREFIX}/include/nlohmann/json.hpp https://github.com/nlohmann/json/releases/download/${PKG_REV['json']}/json.hpp
David Cobbleye99c07a2017-12-22 11:39:01 -0800212
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700213FROM openbmc-base as openbmc-boost
William A. Kennington IIIc227fb72018-10-03 19:44:33 -0700214RUN curl -L https://dl.bintray.com/boostorg/release/${PKG_REV['boost']}/source/boost_$(echo "${PKG_REV['boost']}" | tr '.' '_').tar.bz2 | tar -xj && \
215cp -a -r boost_*/boost ${PREFIX}/include
James Feist878df5c2018-07-26 14:54:28 -0700216
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700217FROM openbmc-base as openbmc-tinyxml2
William A. Kennington IIIc227fb72018-10-03 19:44:33 -0700218RUN curl -L https://github.com/leethomason/tinyxml2/archive/${PKG_REV['tinyxml2']}.tar.gz | tar -xz && \
William A. Kennington III5b550082018-10-03 19:25:49 -0700219cd tinyxml2-* && \
William A. Kennington III581c4d42018-10-03 15:48:20 -0700220mkdir build && \
221cd build && \
William A. Kennington III4a67c402018-10-03 15:53:56 -0700222cmake ${CMAKE_FLAGS[@]} .. && \
William A. Kennington III581c4d42018-10-03 15:48:20 -0700223make -j$(nproc) && \
224make install
225
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700226FROM openbmc-base as openbmc-libvncserver
William A. Kennington IIIc227fb72018-10-03 19:44:33 -0700227RUN curl -L https://github.com/LibVNC/libvncserver/archive/${PKG_REV['libvncserver']}.tar.gz | tar -xz && \
William A. Kennington III4815f702018-10-03 19:27:42 -0700228cd libvncserver-* && \
William A. Kennington III581c4d42018-10-03 15:48:20 -0700229mkdir build && \
230cd build && \
William A. Kennington IIIbb71cc02018-10-03 19:19:23 -0700231cmake ${CMAKE_FLAGS[@]} .. && \
William A. Kennington III581c4d42018-10-03 15:48:20 -0700232make -j$(nproc) && \
233make install
234
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700235FROM openbmc-base as openbmc-sdbusplus
William A. Kennington III4815f702018-10-03 19:27:42 -0700236RUN curl -L https://github.com/openbmc/sdbusplus/archive/${PKG_REV['sdbusplus']}.tar.gz | tar -xz && \
237cd sdbusplus-* && \
Andrew Jeffery221eeda2018-03-08 13:32:43 +1030238./bootstrap.sh && \
William A. Kennington III3cf94fd2018-10-03 19:16:55 -0700239./configure ${CONFIGURE_FLAGS[@]} --enable-transaction && \
Andrew Jeffery221eeda2018-03-08 13:32:43 +1030240make -j$(nproc) && \
241make install
242
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700243FROM openbmc-base as openbmc-sdeventplus
William A. Kennington III4815f702018-10-03 19:27:42 -0700244RUN curl -L https://github.com/openbmc/sdeventplus/archive/${PKG_REV['sdeventplus']}.tar.gz | tar -xz && \
245cd sdeventplus-* && \
William A. Kennington IIIb4f730a2018-09-12 11:21:20 -0700246./bootstrap.sh && \
William A. Kennington III3cf94fd2018-10-03 19:16:55 -0700247./configure ${CONFIGURE_FLAGS[@]} --disable-tests --disable-examples && \
William A. Kennington IIIb4f730a2018-09-12 11:21:20 -0700248make -j$(nproc) && \
249make install
250
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700251FROM openbmc-base as openbmc-gpioplus
William A. Kennington III4815f702018-10-03 19:27:42 -0700252RUN curl -L https://github.com/openbmc/gpioplus/archive/${PKG_REV['gpioplus']}.tar.gz | tar -xz && \
253cd gpioplus-* && \
Patrick Venture22329962018-09-14 10:23:04 -0700254./bootstrap.sh && \
William A. Kennington III3cf94fd2018-10-03 19:16:55 -0700255./configure ${CONFIGURE_FLAGS[@]} --disable-tests --disable-examples && \
Patrick Venture22329962018-09-14 10:23:04 -0700256make -j$(nproc) && \
257make install
258
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700259FROM openbmc-base as openbmc-phosphor-dbus-interfaces
260COPY --from=openbmc-sdbusplus ${PREFIX} ${PREFIX}
William A. Kennington III4815f702018-10-03 19:27:42 -0700261RUN curl -L https://github.com/openbmc/phosphor-dbus-interfaces/archive/${PKG_REV['phosphor-dbus-interfaces']}.tar.gz | tar -xz && \
262cd phosphor-dbus-interfaces-* && \
Andrew Jeffery221eeda2018-03-08 13:32:43 +1030263./bootstrap.sh && \
William A. Kennington III3cf94fd2018-10-03 19:16:55 -0700264./configure ${CONFIGURE_FLAGS[@]} && \
Andrew Jeffery221eeda2018-03-08 13:32:43 +1030265make -j$(nproc) && \
266make install
267
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700268FROM openbmc-base as openbmc-openpower-dbus-interfaces
269COPY --from=openbmc-sdbusplus ${PREFIX} ${PREFIX}
William A. Kennington III4815f702018-10-03 19:27:42 -0700270RUN curl -L https://github.com/openbmc/openpower-dbus-interfaces/archive/${PKG_REV['openpower-dbus-interfaces']}.tar.gz | tar -xz && \
271cd openpower-dbus-interfaces-* && \
Andrew Jeffery221eeda2018-03-08 13:32:43 +1030272./bootstrap.sh && \
William A. Kennington III3cf94fd2018-10-03 19:16:55 -0700273./configure ${CONFIGURE_FLAGS[@]} && \
Andrew Jeffery221eeda2018-03-08 13:32:43 +1030274make -j$(nproc) && \
275make install
276
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700277FROM openbmc-base as openbmc-phosphor-logging
278COPY --from=openbmc-cereal ${PREFIX} ${PREFIX}
279COPY --from=openbmc-sdbusplus ${PREFIX} ${PREFIX}
280COPY --from=openbmc-phosphor-dbus-interfaces ${PREFIX} ${PREFIX}
William A. Kennington III4815f702018-10-03 19:27:42 -0700281RUN curl -L https://github.com/openbmc/phosphor-logging/archive/${PKG_REV['phosphor-logging']}.tar.gz | tar -xz && \
282cd phosphor-logging-* && \
Andrew Jeffery221eeda2018-03-08 13:32:43 +1030283./bootstrap.sh && \
William A. Kennington IIIc8e8b202018-10-03 19:35:59 -0700284./configure ${CONFIGURE_FLAGS[@]} --enable-metadata-processing YAML_DIR=${PREFIX}/share/phosphor-dbus-yaml/yaml && \
Andrew Jeffery221eeda2018-03-08 13:32:43 +1030285make -j$(nproc) && \
286make install
287
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700288FROM openbmc-base as openbmc-phosphor-objmgr
289COPY --from=openbmc-boost ${PREFIX} ${PREFIX}
290COPY --from=openbmc-sdbusplus ${PREFIX} ${PREFIX}
291COPY --from=openbmc-tinyxml2 ${PREFIX} ${PREFIX}
292COPY --from=openbmc-phosphor-logging ${PREFIX} ${PREFIX}
William A. Kennington III4815f702018-10-03 19:27:42 -0700293RUN curl -L https://github.com/openbmc/phosphor-objmgr/archive/${PKG_REV['phosphor-objmgr']}.tar.gz | tar -xz && \
294cd phosphor-objmgr-* && \
Andrew Jeffery221eeda2018-03-08 13:32:43 +1030295./bootstrap.sh && \
William A. Kennington III3cf94fd2018-10-03 19:16:55 -0700296./configure ${CONFIGURE_FLAGS[@]} --enable-unpatched-systemd && \
Andrew Jeffery221eeda2018-03-08 13:32:43 +1030297make -j$(nproc) && \
298make install
299
William A. Kennington IIIda70d702018-10-03 19:57:35 -0700300
301# Build the final output image
302FROM openbmc-base
303${COPY_CMDS}
304
William A. Kennington III212cfcb2018-10-03 19:48:26 -0700305RUN echo '${AUTOM4TE}' > ${AUTOM4TE_CFG}
306
307# Some of our infrastructure still relies on the presence of this file
308# even though it is no longer needed to rebuild the docker environment
309# NOTE: The file is sorted to ensure the ordering is stable.
310RUN echo '$(LC_COLLATE=C sort -s "$DEPCACHE_FILE" | tr '\n' ',')' > /root/.depcache
311
312# Final configuration for the workspace
313RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
314RUN mkdir -p $(dirname ${HOME})
315RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
316
Matthew Barthb4aea672016-11-10 14:59:52 -0600317RUN /bin/bash
318EOF
319)
320fi
321################################# docker img # #################################
322
323# Build above image
James Feist4bd2d452018-07-24 12:19:59 -0700324docker build --network=host -t ${DOCKER_IMG_NAME} - <<< "${Dockerfile}"