blob: 0fa6238eec7c75ec128b72ef32a2ee809722c0b8 [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
5while getopts ":ahp: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 ;;
11 p)
12 echo "Build firmware images for the platforms: $OPTARG"
13 PLATFORMS=$OPTARG
14 ;;
Stewart Smith6650dd42017-02-16 14:41:10 +110015 c)
16 echo "Build in container: $OPTARG"
17 CONTAINERS=$OPTARG
18 ;;
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053019 h)
20 echo "Usage: ./ci/build.sh [options] [--]"
21 echo "-h Print this help and exit successfully."
22 echo "-a Build firmware images for all the platform defconfig's."
23 echo "-p List of comma separated platform names to build images for particular platforms."
Stewart Smith6650dd42017-02-16 14:41:10 +110024 echo "-c Container to run in"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053025 echo "Example:DOCKER_PREFIX=sudo ./ci/build.sh -a"
26 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p firestone"
27 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p garrison,palmetto,openpower_p9_mambo"
28 exit 1
29 ;;
30 \?)
31 echo "Invalid option: -$OPTARG"
32 exit 1
33 ;;
34 :)
35 echo "Option -$OPTARG requires an argument."
36 exit 1
37 ;;
38 esac
39done
40
Stewart Smith098d03e2016-03-01 13:59:42 +110041set -ex
42set -eo pipefail
43
44function run_docker
45{
46 $DOCKER_PREFIX docker run --cap-add=sys_admin --net=host --rm=true \
47 --user="${USER}" -w "${PWD}" -v "${PWD}":"${PWD}":Z \
48 -t $1 $2
49}
50
51env
52
53if [ -d output-images ]; then
54 echo 'output-images already exists!';
55 exit 1;
56fi
57
Stewart Smith6650dd42017-02-16 14:41:10 +110058for distro in $CONTAINERS;
Stewart Smith098d03e2016-03-01 13:59:42 +110059do
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +100060 base_dockerfile=ci/Dockerfile/$distro.`uname -m`
Stewart Smith098d03e2016-03-01 13:59:42 +110061 if [ ! -f $base_dockerfile ]; then
Samuel Mendoza-Jonas79722502018-07-25 14:59:07 +100062 echo "$distro not supported on $(uname -m).";
Stewart Smith098d03e2016-03-01 13:59:42 +110063 continue
64 fi
65 if [[ -n "$HTTP_PROXY" ]]; then
66 http_proxy=$HTTP_PROXY
Stewart Smith915cea12018-01-16 16:07:49 +110067 HTTP_PROXY_ENV="ENV http_proxy $HTTP_PROXY"
68 fi
69 if [[ -n "$HTTPS_PROXY" ]]; then
70 https_proxy=$HTTPS_PROXY
71 HTTPS_PROXY_ENV="ENV https_proxy $HTTPS_PROXY"
Stewart Smith098d03e2016-03-01 13:59:42 +110072 fi
73 if [[ -n "$http_proxy" ]]; then
Stewart Smith915cea12018-01-16 16:07:49 +110074 if [[ "$distro" == fedora27 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +110075 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
76 fi
Stewart Smith915cea12018-01-16 16:07:49 +110077 if [[ "$distro" == ubuntu1604 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +110078 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
79 fi
80 fi
81
82 Dockerfile=$(head -n1 $base_dockerfile; echo ${PROXY}; tail -n +2 $base_dockerfile; cat << EOF
Stewart Smith098d03e2016-03-01 13:59:42 +110083${PROXY}
Stewart Smith915cea12018-01-16 16:07:49 +110084RUN useradd -d ${HOME} -m -u ${UID} ${USER}
Stewart Smith098d03e2016-03-01 13:59:42 +110085ENV HOME ${HOME}
Stewart Smith915cea12018-01-16 16:07:49 +110086${HTTP_PROXY_ENV}
87${HTTPS_PROXY_ENV}
Stewart Smith098d03e2016-03-01 13:59:42 +110088EOF
89)
90 $DOCKER_PREFIX docker build -t openpower/op-build-$distro - <<< "${Dockerfile}"
91 mkdir -p output-images/$distro
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053092 run_docker openpower/op-build-$distro "./ci/build-all-defconfigs.sh output-images/$distro $PLATFORMS"
Stewart Smith098d03e2016-03-01 13:59:42 +110093 if [ $? = 0 ]; then
94 mv *-images output-$distro/
95 else
96 exit $?;
97 fi
98done;
99