Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 3 | CONTAINERS="ubuntu1604 fedora27" |
Stewart Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 4 | |
| 5 | while getopts ":ahp:c:" opt; do |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 6 | 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 Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 15 | c) |
| 16 | echo "Build in container: $OPTARG" |
| 17 | CONTAINERS=$OPTARG |
| 18 | ;; |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 19 | 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 Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 24 | echo "-c Container to run in" |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 25 | 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 |
| 39 | done |
| 40 | |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 41 | set -ex |
| 42 | set -eo pipefail |
| 43 | |
| 44 | function 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 | |
| 51 | env |
| 52 | |
| 53 | if [ -d output-images ]; then |
| 54 | echo 'output-images already exists!'; |
| 55 | exit 1; |
| 56 | fi |
| 57 | |
Stewart Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 58 | for distro in $CONTAINERS; |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 59 | do |
Samuel Mendoza-Jonas | 7972250 | 2018-07-25 14:59:07 +1000 | [diff] [blame^] | 60 | base_dockerfile=ci/Dockerfile/$distro.`uname -m` |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 61 | if [ ! -f $base_dockerfile ]; then |
Samuel Mendoza-Jonas | 7972250 | 2018-07-25 14:59:07 +1000 | [diff] [blame^] | 62 | echo "$distro not supported on $(uname -m)."; |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 63 | continue |
| 64 | fi |
| 65 | if [[ -n "$HTTP_PROXY" ]]; then |
| 66 | http_proxy=$HTTP_PROXY |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 67 | 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 Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 72 | fi |
| 73 | if [[ -n "$http_proxy" ]]; then |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 74 | if [[ "$distro" == fedora27 ]]; then |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 75 | PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf" |
| 76 | fi |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 77 | if [[ "$distro" == ubuntu1604 ]]; then |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 78 | 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 Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 83 | ${PROXY} |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 84 | RUN useradd -d ${HOME} -m -u ${UID} ${USER} |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 85 | ENV HOME ${HOME} |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 86 | ${HTTP_PROXY_ENV} |
| 87 | ${HTTPS_PROXY_ENV} |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 88 | EOF |
| 89 | ) |
| 90 | $DOCKER_PREFIX docker build -t openpower/op-build-$distro - <<< "${Dockerfile}" |
| 91 | mkdir -p output-images/$distro |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 92 | 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] | 93 | if [ $? = 0 ]; then |
| 94 | mv *-images output-$distro/ |
| 95 | else |
| 96 | exit $?; |
| 97 | fi |
| 98 | done; |
| 99 | |