blob: b313291ecbfddbca167970439a351f07deaaf380 [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-Jonas8d102aa2018-08-10 13:47:48 +10005while getopts ":ab:hp:c:r" 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 ;;
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100035 r)
36 echo "Build for release"
37 release_args="-r"
38 ;;
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053039 \?)
40 echo "Invalid option: -$OPTARG"
41 exit 1
42 ;;
43 :)
44 echo "Option -$OPTARG requires an argument."
45 exit 1
46 ;;
47 esac
48done
49
Stewart Smith098d03e2016-03-01 13:59:42 +110050set -ex
51set -eo pipefail
52
53function run_docker
54{
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100055 if [ -n "$BIND" ]; then
56 BINDARG="--mount=type=bind,src=${BIND},dst=${BIND}"
57 else
58 BINDARG="--mount=type=bind,src=${PWD},dst=${PWD}"
59 fi
Stewart Smith098d03e2016-03-01 13:59:42 +110060 $DOCKER_PREFIX docker run --cap-add=sys_admin --net=host --rm=true \
Samuel Mendoza-Jonasae0d13e2018-08-06 15:16:32 +100061 --user="${USER}" -w "${PWD}" "${BINDARG}" \
Stewart Smith098d03e2016-03-01 13:59:42 +110062 -t $1 $2
63}
64
65env
66
67if [ -d output-images ]; then
68 echo 'output-images already exists!';
69 exit 1;
70fi
71
Stewart Smith6650dd42017-02-16 14:41:10 +110072for distro in $CONTAINERS;
Stewart Smith098d03e2016-03-01 13:59:42 +110073do
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +100074 base_dockerfile=ci/Dockerfile/$distro.`uname -m`
Stewart Smith098d03e2016-03-01 13:59:42 +110075 if [ ! -f $base_dockerfile ]; then
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +100076 echo "$distro not supported on $(uname -m).";
Stewart Smith098d03e2016-03-01 13:59:42 +110077 continue
78 fi
79 if [[ -n "$HTTP_PROXY" ]]; then
80 http_proxy=$HTTP_PROXY
Stewart Smith915cea12018-01-16 16:07:49 +110081 HTTP_PROXY_ENV="ENV http_proxy $HTTP_PROXY"
82 fi
83 if [[ -n "$HTTPS_PROXY" ]]; then
84 https_proxy=$HTTPS_PROXY
85 HTTPS_PROXY_ENV="ENV https_proxy $HTTPS_PROXY"
Stewart Smith098d03e2016-03-01 13:59:42 +110086 fi
87 if [[ -n "$http_proxy" ]]; then
Stewart Smith915cea12018-01-16 16:07:49 +110088 if [[ "$distro" == fedora27 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +110089 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
90 fi
Stewart Smith915cea12018-01-16 16:07:49 +110091 if [[ "$distro" == ubuntu1604 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +110092 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
93 fi
94 fi
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +100095 if [[ -n "DL_DIR" ]]; then
96 DL_DIR_ENV="ENV DL_DIR $DL_DIR"
97 fi
98 if [[ -n "CCACHE_DIR" ]]; then
99 CCACHE_DIR_ENV="ENV CCACHE_DIR $CCACHE_DIR"
100 fi
Stewart Smith098d03e2016-03-01 13:59:42 +1100101
102 Dockerfile=$(head -n1 $base_dockerfile; echo ${PROXY}; tail -n +2 $base_dockerfile; cat << EOF
Stewart Smith098d03e2016-03-01 13:59:42 +1100103${PROXY}
Stewart Smith915cea12018-01-16 16:07:49 +1100104RUN useradd -d ${HOME} -m -u ${UID} ${USER}
Stewart Smith098d03e2016-03-01 13:59:42 +1100105ENV HOME ${HOME}
Stewart Smith915cea12018-01-16 16:07:49 +1100106${HTTP_PROXY_ENV}
107${HTTPS_PROXY_ENV}
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000108${DL_DIR_ENV}
109${CCACHE_DIR_ENV}
Stewart Smith098d03e2016-03-01 13:59:42 +1100110EOF
111)
Samuel Mendoza-Jonas86f9bb82018-08-06 12:51:59 +1000112 $DOCKER_PREFIX docker build --network=host -t openpower/op-build-$distro - <<< "${Dockerfile}"
Stewart Smith098d03e2016-03-01 13:59:42 +1100113 mkdir -p output-images/$distro
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +1000114 run_docker openpower/op-build-$distro "./ci/build-all-defconfigs.sh -o output-images/$distro -p $PLATFORMS ${release_args}"
Stewart Smith098d03e2016-03-01 13:59:42 +1100115 if [ $? = 0 ]; then
116 mv *-images output-$distro/
117 else
118 exit $?;
119 fi
120done;
121