Matthew Barth | b4aea67 | 2016-11-10 14:59:52 -0600 | [diff] [blame^] | 1 | #!/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 | |
| 11 | set -uo pipefail |
| 12 | |
| 13 | DOCKER_IMG_NAME=${1:-"openbmc/ubuntu-unit-test"} |
| 14 | DISTRO=${2:-"ubuntu:latest"} |
| 15 | |
| 16 | # Determine the architecture |
| 17 | ARCH=$(uname -m) |
| 18 | case ${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 |
| 28 | esac |
| 29 | |
| 30 | ################################# docker img # ################################# |
| 31 | # Create docker image that can run package unit tests |
| 32 | if [[ "${DISTRO}" == "ubuntu"* ]]; then |
| 33 | Dockerfile=$(cat << EOF |
| 34 | FROM ${DOCKER_BASE}${DISTRO} |
| 35 | |
| 36 | ENV DEBIAN_FRONTEND noninteractive |
| 37 | |
| 38 | RUN 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 | |
| 54 | RUN wget http://ftpmirror.gnu.org/autoconf-archive/autoconf-archive-2016.09.16.tar.xz |
| 55 | RUN tar -xJf autoconf-archive-2016.09.16.tar.xz |
| 56 | RUN cd autoconf-archive-2016.09.16 && ./configure --prefix=/usr && make && make install |
| 57 | |
| 58 | RUN wget https://github.com/google/googletest/archive/release-1.7.0.tar.gz |
| 59 | RUN tar -xzf release-1.7.0.tar.gz |
| 60 | RUN cd googletest-release-1.7.0 && cmake -DBUILD_SHARED_LIBS=ON . && make && \ |
| 61 | cp -a include/gtest /usr/include && \ |
| 62 | cp -a libgtest_main.so libgtest.so /usr/lib/ |
| 63 | |
| 64 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 65 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 66 | |
| 67 | RUN /bin/bash |
| 68 | EOF |
| 69 | ) |
| 70 | fi |
| 71 | ################################# docker img # ################################# |
| 72 | |
| 73 | # Build above image |
| 74 | docker build -t ${DOCKER_IMG_NAME} - <<< "${Dockerfile}" |