Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 3 | while 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 |
| 32 | done |
| 33 | |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 34 | set -ex |
| 35 | set -eo pipefail |
| 36 | |
| 37 | function 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 | |
| 44 | env |
| 45 | |
| 46 | if [ -d output-images ]; then |
| 47 | echo 'output-images already exists!'; |
| 48 | exit 1; |
| 49 | fi |
| 50 | |
| 51 | for distro in ubuntu1404 fedora23; |
| 52 | do |
| 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 |
| 71 | RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 72 | ${PROXY} |
| 73 | USER ${USER} |
| 74 | ENV HOME ${HOME} |
| 75 | EOF |
| 76 | ) |
| 77 | $DOCKER_PREFIX docker build -t openpower/op-build-$distro - <<< "${Dockerfile}" |
| 78 | mkdir -p output-images/$distro |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 79 | run_docker openpower/op-build-$distro "./ci/build-all-defconfigs.sh output-images/$distro $PLATFORMS" |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 80 | if [ $? = 0 ]; then |
| 81 | mv *-images output-$distro/ |
| 82 | else |
| 83 | exit $?; |
| 84 | fi |
| 85 | done; |
| 86 | |