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 | |
Samuel Mendoza-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame^] | 5 | while getopts ":ab:hp:c:r" 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 | ;; |
Samuel Mendoza-Jonas | ae0d13e | 2018-08-06 15:16:32 +1000 | [diff] [blame] | 11 | b) |
| 12 | echo "Directory to bind to container: $OPTARG" |
| 13 | BIND="$OPTARG" |
| 14 | ;; |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 15 | p) |
| 16 | echo "Build firmware images for the platforms: $OPTARG" |
| 17 | PLATFORMS=$OPTARG |
| 18 | ;; |
Stewart Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 19 | c) |
| 20 | echo "Build in container: $OPTARG" |
| 21 | CONTAINERS=$OPTARG |
| 22 | ;; |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 23 | h) |
| 24 | echo "Usage: ./ci/build.sh [options] [--]" |
| 25 | echo "-h Print this help and exit successfully." |
| 26 | echo "-a Build firmware images for all the platform defconfig's." |
Samuel Mendoza-Jonas | ae0d13e | 2018-08-06 15:16:32 +1000 | [diff] [blame] | 27 | echo "-b DIR Bind DIR to container." |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 28 | 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] | 29 | echo "-c Container to run in" |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 30 | echo "Example:DOCKER_PREFIX=sudo ./ci/build.sh -a" |
| 31 | echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p firestone" |
| 32 | echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p garrison,palmetto,openpower_p9_mambo" |
| 33 | exit 1 |
| 34 | ;; |
Samuel Mendoza-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame^] | 35 | r) |
| 36 | echo "Build for release" |
| 37 | release_args="-r" |
| 38 | ;; |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 39 | \?) |
| 40 | echo "Invalid option: -$OPTARG" |
| 41 | exit 1 |
| 42 | ;; |
| 43 | :) |
| 44 | echo "Option -$OPTARG requires an argument." |
| 45 | exit 1 |
| 46 | ;; |
| 47 | esac |
| 48 | done |
| 49 | |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 50 | set -ex |
| 51 | set -eo pipefail |
| 52 | |
| 53 | function run_docker |
| 54 | { |
Samuel Mendoza-Jonas | ae0d13e | 2018-08-06 15:16:32 +1000 | [diff] [blame] | 55 | if [ -n "$BIND" ]; then |
| 56 | BINDARG="--mount=type=bind,src=${BIND},dst=${BIND}" |
| 57 | else |
| 58 | BINDARG="--mount=type=bind,src=${PWD},dst=${PWD}" |
| 59 | fi |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 60 | $DOCKER_PREFIX docker run --cap-add=sys_admin --net=host --rm=true \ |
Samuel Mendoza-Jonas | ae0d13e | 2018-08-06 15:16:32 +1000 | [diff] [blame] | 61 | --user="${USER}" -w "${PWD}" "${BINDARG}" \ |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 62 | -t $1 $2 |
| 63 | } |
| 64 | |
| 65 | env |
| 66 | |
| 67 | if [ -d output-images ]; then |
| 68 | echo 'output-images already exists!'; |
| 69 | exit 1; |
| 70 | fi |
| 71 | |
Stewart Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 72 | for distro in $CONTAINERS; |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 73 | do |
Samuel Mendoza-Jonas | 7972250 | 2018-07-25 14:59:07 +1000 | [diff] [blame] | 74 | base_dockerfile=ci/Dockerfile/$distro.`uname -m` |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 75 | if [ ! -f $base_dockerfile ]; then |
Samuel Mendoza-Jonas | 7972250 | 2018-07-25 14:59:07 +1000 | [diff] [blame] | 76 | echo "$distro not supported on $(uname -m)."; |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 77 | continue |
| 78 | fi |
| 79 | if [[ -n "$HTTP_PROXY" ]]; then |
| 80 | http_proxy=$HTTP_PROXY |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 81 | HTTP_PROXY_ENV="ENV http_proxy $HTTP_PROXY" |
| 82 | fi |
| 83 | if [[ -n "$HTTPS_PROXY" ]]; then |
| 84 | https_proxy=$HTTPS_PROXY |
| 85 | HTTPS_PROXY_ENV="ENV https_proxy $HTTPS_PROXY" |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 86 | fi |
| 87 | if [[ -n "$http_proxy" ]]; then |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 88 | if [[ "$distro" == fedora27 ]]; then |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 89 | PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf" |
| 90 | fi |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 91 | if [[ "$distro" == ubuntu1604 ]]; then |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 92 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 93 | fi |
| 94 | fi |
Samuel Mendoza-Jonas | 94ec86a | 2018-08-06 15:18:26 +1000 | [diff] [blame] | 95 | if [[ -n "DL_DIR" ]]; then |
| 96 | DL_DIR_ENV="ENV DL_DIR $DL_DIR" |
| 97 | fi |
| 98 | if [[ -n "CCACHE_DIR" ]]; then |
| 99 | CCACHE_DIR_ENV="ENV CCACHE_DIR $CCACHE_DIR" |
| 100 | fi |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 101 | |
| 102 | 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] | 103 | ${PROXY} |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 104 | RUN useradd -d ${HOME} -m -u ${UID} ${USER} |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 105 | ENV HOME ${HOME} |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 106 | ${HTTP_PROXY_ENV} |
| 107 | ${HTTPS_PROXY_ENV} |
Samuel Mendoza-Jonas | 94ec86a | 2018-08-06 15:18:26 +1000 | [diff] [blame] | 108 | ${DL_DIR_ENV} |
| 109 | ${CCACHE_DIR_ENV} |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 110 | EOF |
| 111 | ) |
Samuel Mendoza-Jonas | 86f9bb8 | 2018-08-06 12:51:59 +1000 | [diff] [blame] | 112 | $DOCKER_PREFIX docker build --network=host -t openpower/op-build-$distro - <<< "${Dockerfile}" |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 113 | mkdir -p output-images/$distro |
Samuel Mendoza-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame^] | 114 | run_docker openpower/op-build-$distro "./ci/build-all-defconfigs.sh -o output-images/$distro -p $PLATFORMS ${release_args}" |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 115 | if [ $? = 0 ]; then |
| 116 | mv *-images output-$distro/ |
| 117 | else |
| 118 | exit $?; |
| 119 | fi |
| 120 | done; |
| 121 | |