blob: 4291414627ed4f3798b281de72529a92707dd2ee [file] [log] [blame]
Stewart Smith098d03e2016-03-01 13:59:42 +11001#!/bin/bash
2
Stewart Smith915cea12018-01-16 16:07:49 +11003CONTAINERS="ubuntu1604 fedora27"
Stewart Smith6650dd42017-02-16 14:41:10 +11004
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +10005while getopts ":ab:hp:c:" opt; do
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +05306 case $opt in
7 a)
8 echo "Build firmware images for all the platforms"
9 PLATFORMS=""
10 ;;
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100011 b)
12 echo "Directory to bind to container: $OPTARG"
13 BIND="$OPTARG"
14 ;;
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053015 p)
16 echo "Build firmware images for the platforms: $OPTARG"
17 PLATFORMS=$OPTARG
18 ;;
Stewart Smith6650dd42017-02-16 14:41:10 +110019 c)
20 echo "Build in container: $OPTARG"
21 CONTAINERS=$OPTARG
22 ;;
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053023 h)
24 echo "Usage: ./ci/build.sh [options] [--]"
25 echo "-h Print this help and exit successfully."
26 echo "-a Build firmware images for all the platform defconfig's."
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100027 echo "-b DIR Bind DIR to container."
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053028 echo "-p List of comma separated platform names to build images for particular platforms."
Stewart Smith6650dd42017-02-16 14:41:10 +110029 echo "-c Container to run in"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053030 echo "Example:DOCKER_PREFIX=sudo ./ci/build.sh -a"
31 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p firestone"
32 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p garrison,palmetto,openpower_p9_mambo"
33 exit 1
34 ;;
35 \?)
36 echo "Invalid option: -$OPTARG"
37 exit 1
38 ;;
39 :)
40 echo "Option -$OPTARG requires an argument."
41 exit 1
42 ;;
43 esac
44done
45
Stewart Smith098d03e2016-03-01 13:59:42 +110046set -ex
47set -eo pipefail
48
49function run_docker
50{
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100051 if [ -n "$BIND" ]; then
52 BINDARG="--mount=type=bind,src=${BIND},dst=${BIND}"
53 else
54 BINDARG="--mount=type=bind,src=${PWD},dst=${PWD}"
55 fi
Stewart Smith098d03e2016-03-01 13:59:42 +110056 $DOCKER_PREFIX docker run --cap-add=sys_admin --net=host --rm=true \
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100057 --user="${USER}" -w "${PWD}" "${BINDARG}" \
Stewart Smith098d03e2016-03-01 13:59:42 +110058 -t $1 $2
59}
60
61env
62
63if [ -d output-images ]; then
64 echo 'output-images already exists!';
65 exit 1;
66fi
67
Stewart Smith6650dd42017-02-16 14:41:10 +110068for distro in $CONTAINERS;
Stewart Smith098d03e2016-03-01 13:59:42 +110069do
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +100070 base_dockerfile=ci/Dockerfile/$distro.`uname -m`
Stewart Smith098d03e2016-03-01 13:59:42 +110071 if [ ! -f $base_dockerfile ]; then
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +100072 echo "$distro not supported on $(uname -m).";
Stewart Smith098d03e2016-03-01 13:59:42 +110073 continue
74 fi
75 if [[ -n "$HTTP_PROXY" ]]; then
76 http_proxy=$HTTP_PROXY
Stewart Smith915cea12018-01-16 16:07:49 +110077 HTTP_PROXY_ENV="ENV http_proxy $HTTP_PROXY"
78 fi
79 if [[ -n "$HTTPS_PROXY" ]]; then
80 https_proxy=$HTTPS_PROXY
81 HTTPS_PROXY_ENV="ENV https_proxy $HTTPS_PROXY"
Stewart Smith098d03e2016-03-01 13:59:42 +110082 fi
83 if [[ -n "$http_proxy" ]]; then
Stewart Smith915cea12018-01-16 16:07:49 +110084 if [[ "$distro" == fedora27 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +110085 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
86 fi
Stewart Smith915cea12018-01-16 16:07:49 +110087 if [[ "$distro" == ubuntu1604 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +110088 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
89 fi
90 fi
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +100091 if [[ -n "DL_DIR" ]]; then
92 DL_DIR_ENV="ENV DL_DIR $DL_DIR"
93 fi
94 if [[ -n "CCACHE_DIR" ]]; then
95 CCACHE_DIR_ENV="ENV CCACHE_DIR $CCACHE_DIR"
96 fi
Stewart Smith098d03e2016-03-01 13:59:42 +110097
98 Dockerfile=$(head -n1 $base_dockerfile; echo ${PROXY}; tail -n +2 $base_dockerfile; cat << EOF
Stewart Smith098d03e2016-03-01 13:59:42 +110099${PROXY}
Stewart Smith915cea12018-01-16 16:07:49 +1100100RUN useradd -d ${HOME} -m -u ${UID} ${USER}
Stewart Smith098d03e2016-03-01 13:59:42 +1100101ENV HOME ${HOME}
Stewart Smith915cea12018-01-16 16:07:49 +1100102${HTTP_PROXY_ENV}
103${HTTPS_PROXY_ENV}
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000104${DL_DIR_ENV}
105${CCACHE_DIR_ENV}
Stewart Smith098d03e2016-03-01 13:59:42 +1100106EOF
107)
Samuel Mendoza-Jonas86f9bb82018-08-06 12:51:59 +1000108 $DOCKER_PREFIX docker build --network=host -t openpower/op-build-$distro - <<< "${Dockerfile}"
Stewart Smith098d03e2016-03-01 13:59:42 +1100109 mkdir -p output-images/$distro
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +0530110 run_docker openpower/op-build-$distro "./ci/build-all-defconfigs.sh output-images/$distro $PLATFORMS"
Stewart Smith098d03e2016-03-01 13:59:42 +1100111 if [ $? = 0 ]; then
112 mv *-images output-$distro/
113 else
114 exit $?;
115 fi
116done;
117