blob: 64b862d414bb3d50e5c79617aae8e08202ef67ad [file] [log] [blame]
Stewart Smith098d03e2016-03-01 13:59:42 +11001#!/bin/bash
2
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +05303while getopts ":ahp:" opt; do
4 case $opt in
5 a)
6 echo "Build firmware images for all the platforms"
7 PLATFORMS=""
8 ;;
9 p)
10 echo "Build firmware images for the platforms: $OPTARG"
11 PLATFORMS=$OPTARG
12 ;;
13 h)
14 echo "Usage: ./ci/build.sh [options] [--]"
15 echo "-h Print this help and exit successfully."
16 echo "-a Build firmware images for all the platform defconfig's."
17 echo "-p List of comma separated platform names to build images for particular platforms."
18 echo "Example:DOCKER_PREFIX=sudo ./ci/build.sh -a"
19 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p firestone"
20 echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p garrison,palmetto,openpower_p9_mambo"
21 exit 1
22 ;;
23 \?)
24 echo "Invalid option: -$OPTARG"
25 exit 1
26 ;;
27 :)
28 echo "Option -$OPTARG requires an argument."
29 exit 1
30 ;;
31 esac
32done
33
Stewart Smith098d03e2016-03-01 13:59:42 +110034set -ex
35set -eo pipefail
36
37function run_docker
38{
39 $DOCKER_PREFIX docker run --cap-add=sys_admin --net=host --rm=true \
40 --user="${USER}" -w "${PWD}" -v "${PWD}":"${PWD}":Z \
41 -t $1 $2
42}
43
44env
45
46if [ -d output-images ]; then
47 echo 'output-images already exists!';
48 exit 1;
49fi
50
51for distro in ubuntu1404 fedora23;
52do
53 base_dockerfile=ci/Dockerfile/$distro.`arch`
54 if [ ! -f $base_dockerfile ]; then
55 echo '$distro not supported on `arch`.';
56 continue
57 fi
58 if [[ -n "$HTTP_PROXY" ]]; then
59 http_proxy=$HTTP_PROXY
60 fi
61 if [[ -n "$http_proxy" ]]; then
62 if [[ "$distro" == fedora23 ]]; then
63 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
64 fi
65 if [[ "$distro" == ubuntu1404 ]]; then
66 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
67 fi
68 fi
69
70 Dockerfile=$(head -n1 $base_dockerfile; echo ${PROXY}; tail -n +2 $base_dockerfile; cat << EOF
71RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
72${PROXY}
73USER ${USER}
74ENV HOME ${HOME}
75EOF
76)
77 $DOCKER_PREFIX docker build -t openpower/op-build-$distro - <<< "${Dockerfile}"
78 mkdir -p output-images/$distro
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +053079 run_docker openpower/op-build-$distro "./ci/build-all-defconfigs.sh output-images/$distro $PLATFORMS"
Stewart Smith098d03e2016-03-01 13:59:42 +110080 if [ $? = 0 ]; then
81 mv *-images output-$distro/
82 else
83 exit $?;
84 fi
85done;
86