blob: 0ace0e1a62654c66066d7113382e1e1329b08b4a [file] [log] [blame]
Stewart Smith098d03e2016-03-01 13:59:42 +11001#!/bin/bash
2
Stewart Smith6650dd42017-02-16 14:41:10 +11003CONTAINERS="ubuntu1404 fedora25"
4
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
60 base_dockerfile=ci/Dockerfile/$distro.`arch`
61 if [ ! -f $base_dockerfile ]; then
62 echo '$distro not supported on `arch`.';
63 continue
64 fi
65 if [[ -n "$HTTP_PROXY" ]]; then
66 http_proxy=$HTTP_PROXY
67 fi
68 if [[ -n "$http_proxy" ]]; then
Stewart Smith6650dd42017-02-16 14:41:10 +110069 if [[ "$distro" == fedora25 ]]; then
Stewart Smith098d03e2016-03-01 13:59:42 +110070 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
71 fi
72 if [[ "$distro" == ubuntu1404 ]]; then
73 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
74 fi
75 fi
76
77 Dockerfile=$(head -n1 $base_dockerfile; echo ${PROXY}; tail -n +2 $base_dockerfile; cat << EOF
78RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
79${PROXY}
80USER ${USER}
81ENV HOME ${HOME}
82EOF
83)
84 $DOCKER_PREFIX docker build -t openpower/op-build-$distro - <<< "${Dockerfile}"
85 mkdir -p output-images/$distro
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053086 run_docker openpower/op-build-$distro "./ci/build-all-defconfigs.sh output-images/$distro $PLATFORMS"
Stewart Smith098d03e2016-03-01 13:59:42 +110087 if [ $? = 0 ]; then
88 mv *-images output-$distro/
89 else
90 exit $?;
91 fi
92done;
93