blob: 0bbf14037de04124eed72dcb15aabfca03d4897b [file] [log] [blame]
Stewart Smith098d03e2016-03-01 13:59:42 +11001#!/bin/bash
2
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -03003set -ex
4set -eo pipefail
5
Klaus Heinrich Kiwi34b9a2d2020-07-03 17:17:10 -03006CONTAINERS="ubuntu2004 fedora32"
Stewart Smithc4b9bf62018-08-24 13:30:15 +10007SDK_ONLY=0
8
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -03009opt=$(getopt -o 's:Sab:p:c:hr' -- "$@")
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030010if [ $? -ne 0 ] ; then
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030011 echo "Invalid arguments"
12 exit 1
13fi
14
15eval set -- "$opt"
16unset opt
17
18while true; do
19 case "$1" in
20 '-s')
21 shift
22 echo "SDK Cache dir: $1"
23 SDK_CACHE="$1"
Stewart Smithc4b9bf62018-08-24 13:30:15 +100024 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030025 '-S')
Stewart Smithc4b9bf62018-08-24 13:30:15 +100026 echo "Build SDK Only"
27 SDK_ONLY=1
28 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030029 '-a')
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053030 echo "Build firmware images for all the platforms"
31 PLATFORMS=""
32 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030033 '-b')
34 shift
35 echo "Directory to bind to container: $1"
36 BIND="$1"
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100037 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030038 '-p')
39 shift
40 echo "Build firmware images for the platforms: $1"
41 PLATFORMS="$1"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053042 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030043 '-c')
44 shift
45 echo "Build in container: $1"
46 CONTAINERS="$1"
Stewart Smith6650dd42017-02-16 14:41:10 +110047 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030048 '-h')
49 echo "Usage: ./ci/build.sh [options]"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053050 echo "-h Print this help and exit successfully."
51 echo "-a Build firmware images for all the platform defconfig's."
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100052 echo "-b DIR Bind DIR to container."
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053053 echo "-p List of comma separated platform names to build images for particular platforms."
Joel Stanley4c94b9e2018-11-01 13:20:03 +103054 echo "-s DIR SDK cache dir (must exist)."
Stewart Smithc4b9bf62018-08-24 13:30:15 +100055 echo "-S Build SDK only"
Stewart Smith6650dd42017-02-16 14:41:10 +110056 echo "-c Container to run in"
Joel Stanley3226cf32018-11-01 13:20:08 +103057 echo ""
58 echo "Note: set environment variables HTTP_PROXY and HTTPS_PROXY if a proxy is required."
59 echo ""
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053060 echo "Example:DOCKER_PREFIX=sudo ./ci/build.sh -a"
61 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p firestone"
Joel Stanley33ed8f12019-04-03 12:13:43 +103062 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p garrison,palmetto,opal"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053063 exit 1
64 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030065 '-r')
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100066 echo "Build for release"
67 release_args="-r"
68 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030069 '--')
70 shift
71 break
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053072 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030073 *)
74 echo "Internal Error!"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053075 exit 1
76 ;;
77 esac
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030078 shift
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053079done
80
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030081
82if [ ! -d "$SDK_CACHE" ]; then
83 echo "Error: SDK Cache dir doesn't exist: $SDK_CACHE"
84 exit 1
85fi
Stewart Smith098d03e2016-03-01 13:59:42 +110086
87function run_docker
88{
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100089 if [ -n "$BIND" ]; then
90 BINDARG="--mount=type=bind,src=${BIND},dst=${BIND}"
91 else
92 BINDARG="--mount=type=bind,src=${PWD},dst=${PWD}"
93 fi
Stewart Smith9c20ae22018-10-29 15:24:50 +110094 $DOCKER_PREFIX docker run --init --cap-add=sys_admin --net=host --rm=true \
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100095 --user="${USER}" -w "${PWD}" "${BINDARG}" \
Stewart Smith098d03e2016-03-01 13:59:42 +110096 -t $1 $2
97}
98
Stewart Smith098d03e2016-03-01 13:59:42 +110099
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000100env
Stewart Smith098d03e2016-03-01 13:59:42 +1100101
Stewart Smith6650dd42017-02-16 14:41:10 +1100102for distro in $CONTAINERS;
Stewart Smith098d03e2016-03-01 13:59:42 +1100103do
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +1000104 base_dockerfile=ci/Dockerfile/$distro.`uname -m`
Stewart Smith098d03e2016-03-01 13:59:42 +1100105 if [ ! -f $base_dockerfile ]; then
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +1000106 echo "$distro not supported on $(uname -m).";
Stewart Smith098d03e2016-03-01 13:59:42 +1100107 continue
108 fi
109 if [[ -n "$HTTP_PROXY" ]]; then
110 http_proxy=$HTTP_PROXY
Stewart Smith915cea12018-01-16 16:07:49 +1100111 HTTP_PROXY_ENV="ENV http_proxy $HTTP_PROXY"
112 fi
113 if [[ -n "$HTTPS_PROXY" ]]; then
114 https_proxy=$HTTPS_PROXY
115 HTTPS_PROXY_ENV="ENV https_proxy $HTTPS_PROXY"
Stewart Smith098d03e2016-03-01 13:59:42 +1100116 fi
117 if [[ -n "$http_proxy" ]]; then
Stewart Smith45af3fc2019-07-23 15:45:10 +1000118 if [[ "$distro" == fedora30 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100119 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
120 fi
Stewart Smith26b9f992019-03-27 14:46:49 +1100121 if [[ "$distro" == ubuntu1804 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100122 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
123 fi
124 fi
Joel Stanleyce8ae8d2018-11-01 13:19:50 +1030125 if [ ! -z ${DL_DIR+x} ]; then
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000126 DL_DIR_ENV="ENV DL_DIR $DL_DIR"
127 fi
Joel Stanleyce8ae8d2018-11-01 13:19:50 +1030128 if [ ! -z ${CCACHE_DIR+x} ]; then
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000129 CCACHE_DIR_ENV="ENV CCACHE_DIR $CCACHE_DIR"
130 fi
Stewart Smith098d03e2016-03-01 13:59:42 +1100131
132 Dockerfile=$(head -n1 $base_dockerfile; echo ${PROXY}; tail -n +2 $base_dockerfile; cat << EOF
Stewart Smith098d03e2016-03-01 13:59:42 +1100133${PROXY}
Stewart Smith915cea12018-01-16 16:07:49 +1100134RUN useradd -d ${HOME} -m -u ${UID} ${USER}
Stewart Smith098d03e2016-03-01 13:59:42 +1100135ENV HOME ${HOME}
Stewart Smith915cea12018-01-16 16:07:49 +1100136${HTTP_PROXY_ENV}
137${HTTPS_PROXY_ENV}
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000138${DL_DIR_ENV}
139${CCACHE_DIR_ENV}
Stewart Smith098d03e2016-03-01 13:59:42 +1100140EOF
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000141 )
Samuel Mendoza-Jonas86f9bb82018-08-06 12:51:59 +1000142 $DOCKER_PREFIX docker build --network=host -t openpower/op-build-$distro - <<< "${Dockerfile}"
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -0300143
144 if [ -n "$PLATFORMS" ]; then
145 platform_args="-p $PLATFORMS"
Stewart Smith098d03e2016-03-01 13:59:42 +1100146 else
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -0300147 platform_args=""
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000148 fi
149
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300150 if [ $SDK_ONLY -ne 0 ]; then
151 sdk_args="-S"
152 else
153 sdk_args=""
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000154 fi
155
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300156 run_docker openpower/op-build-$distro "./ci/build-all-defconfigs.sh -o `pwd`/output-$distro ${platform_args} ${release_args} ${sdk_args} -s $SDK_CACHE"
157
158 if [ $? -ne 0 ]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100159 exit $?;
160 fi
161done;
162