blob: 0d0d2a8b082edf0c3172cd28875e6e393905ba9f [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>
9# default is ubuntu:latest
10
11set -uo pipefail
12
13DOCKER_IMG_NAME=${1:-"openbmc/ubuntu-unit-test"}
14DISTRO=${2:-"ubuntu:latest"}
15
16# Determine the architecture
17ARCH=$(uname -m)
18case ${ARCH} in
19 "ppc64le")
20 DOCKER_BASE="ppc64le/"
21 ;;
22 "x86_64")
23 DOCKER_BASE=""
24 ;;
25 *)
26 echo "Unsupported system architecture(${ARCH}) found for docker image"
27 exit 1
28esac
29
30################################# docker img # #################################
31# Create docker image that can run package unit tests
32if [[ "${DISTRO}" == "ubuntu"* ]]; then
33Dockerfile=$(cat << EOF
34FROM ${DOCKER_BASE}${DISTRO}
35
36ENV DEBIAN_FRONTEND noninteractive
37
38RUN apt-get update && apt-get install -yy \
39 gcc \
40 g++ \
41 libc6-dev \
42 libtool \
43 cmake \
44 python \
45 python-dev \
46 python-setuptools \
47 pkg-config \
48 autoconf \
49 libsystemd-dev \
50 sudo \
51 wget \
52 git
53
54RUN wget http://ftpmirror.gnu.org/autoconf-archive/autoconf-archive-2016.09.16.tar.xz
55RUN tar -xJf autoconf-archive-2016.09.16.tar.xz
56RUN cd autoconf-archive-2016.09.16 && ./configure --prefix=/usr && make && make install
57
58RUN wget https://github.com/google/googletest/archive/release-1.7.0.tar.gz
59RUN tar -xzf release-1.7.0.tar.gz
60RUN cd googletest-release-1.7.0 && cmake -DBUILD_SHARED_LIBS=ON . && make && \
61cp -a include/gtest /usr/include && \
62cp -a libgtest_main.so libgtest.so /usr/lib/
63
64RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
65RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
66
67RUN /bin/bash
68EOF
69)
70fi
71################################# docker img # #################################
72
73# Build above image
74docker build -t ${DOCKER_IMG_NAME} - <<< "${Dockerfile}"