Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 3 | set -ex |
| 4 | set -eo pipefail |
| 5 | |
Klaus Heinrich Kiwi | 34b9a2d | 2020-07-03 17:17:10 -0300 | [diff] [blame] | 6 | CONTAINERS="ubuntu2004 fedora32" |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 7 | SDK_ONLY=0 |
| 8 | |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 9 | opt=$(getopt -o 's:Sab:p:c:hr' -- "$@") |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 10 | if [ $? -ne 0 ] ; then |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 11 | echo "Invalid arguments" |
| 12 | exit 1 |
| 13 | fi |
| 14 | |
| 15 | eval set -- "$opt" |
| 16 | unset opt |
| 17 | |
| 18 | while true; do |
| 19 | case "$1" in |
| 20 | '-s') |
| 21 | shift |
| 22 | echo "SDK Cache dir: $1" |
| 23 | SDK_CACHE="$1" |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 24 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 25 | '-S') |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 26 | echo "Build SDK Only" |
| 27 | SDK_ONLY=1 |
| 28 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 29 | '-a') |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 30 | echo "Build firmware images for all the platforms" |
| 31 | PLATFORMS="" |
| 32 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 33 | '-b') |
| 34 | shift |
| 35 | echo "Directory to bind to container: $1" |
| 36 | BIND="$1" |
Samuel Mendoza-Jonas | ae0d13e | 2018-08-06 15:16:32 +1000 | [diff] [blame] | 37 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 38 | '-p') |
| 39 | shift |
| 40 | echo "Build firmware images for the platforms: $1" |
| 41 | PLATFORMS="$1" |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 42 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 43 | '-c') |
| 44 | shift |
| 45 | echo "Build in container: $1" |
| 46 | CONTAINERS="$1" |
Stewart Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 47 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 48 | '-h') |
| 49 | echo "Usage: ./ci/build.sh [options]" |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 50 | echo "-h Print this help and exit successfully." |
| 51 | echo "-a Build firmware images for all the platform defconfig's." |
Samuel Mendoza-Jonas | ae0d13e | 2018-08-06 15:16:32 +1000 | [diff] [blame] | 52 | echo "-b DIR Bind DIR to container." |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 53 | echo "-p List of comma separated platform names to build images for particular platforms." |
Joel Stanley | 4c94b9e | 2018-11-01 13:20:03 +1030 | [diff] [blame] | 54 | echo "-s DIR SDK cache dir (must exist)." |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 55 | echo "-S Build SDK only" |
Stewart Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 56 | echo "-c Container to run in" |
Joel Stanley | 3226cf3 | 2018-11-01 13:20:08 +1030 | [diff] [blame] | 57 | echo "" |
| 58 | echo "Note: set environment variables HTTP_PROXY and HTTPS_PROXY if a proxy is required." |
| 59 | echo "" |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 60 | echo "Example:DOCKER_PREFIX=sudo ./ci/build.sh -a" |
| 61 | echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p firestone" |
Joel Stanley | 33ed8f1 | 2019-04-03 12:13:43 +1030 | [diff] [blame] | 62 | echo -e "\tDOCKER_PREFIX=sudo ./ci/build.sh -p garrison,palmetto,opal" |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 63 | exit 1 |
| 64 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 65 | '-r') |
Samuel Mendoza-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame] | 66 | echo "Build for release" |
| 67 | release_args="-r" |
| 68 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 69 | '--') |
| 70 | shift |
| 71 | break |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 72 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 73 | *) |
| 74 | echo "Internal Error!" |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 75 | exit 1 |
| 76 | ;; |
| 77 | esac |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 78 | shift |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 79 | done |
| 80 | |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 81 | |
| 82 | if [ ! -d "$SDK_CACHE" ]; then |
| 83 | echo "Error: SDK Cache dir doesn't exist: $SDK_CACHE" |
| 84 | exit 1 |
| 85 | fi |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 86 | |
| 87 | function run_docker |
| 88 | { |
Samuel Mendoza-Jonas | ae0d13e | 2018-08-06 15:16:32 +1000 | [diff] [blame] | 89 | if [ -n "$BIND" ]; then |
| 90 | BINDARG="--mount=type=bind,src=${BIND},dst=${BIND}" |
| 91 | else |
| 92 | BINDARG="--mount=type=bind,src=${PWD},dst=${PWD}" |
| 93 | fi |
Stewart Smith | 9c20ae2 | 2018-10-29 15:24:50 +1100 | [diff] [blame] | 94 | $DOCKER_PREFIX docker run --init --cap-add=sys_admin --net=host --rm=true \ |
Samuel Mendoza-Jonas | ae0d13e | 2018-08-06 15:16:32 +1000 | [diff] [blame] | 95 | --user="${USER}" -w "${PWD}" "${BINDARG}" \ |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 96 | -t $1 $2 |
| 97 | } |
| 98 | |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 99 | |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 100 | env |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 101 | |
Stewart Smith | 6650dd4 | 2017-02-16 14:41:10 +1100 | [diff] [blame] | 102 | for distro in $CONTAINERS; |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 103 | do |
Samuel Mendoza-Jonas | 7972250 | 2018-07-25 14:59:07 +1000 | [diff] [blame] | 104 | base_dockerfile=ci/Dockerfile/$distro.`uname -m` |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 105 | if [ ! -f $base_dockerfile ]; then |
Samuel Mendoza-Jonas | 7972250 | 2018-07-25 14:59:07 +1000 | [diff] [blame] | 106 | echo "$distro not supported on $(uname -m)."; |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 107 | continue |
| 108 | fi |
| 109 | if [[ -n "$HTTP_PROXY" ]]; then |
| 110 | http_proxy=$HTTP_PROXY |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 111 | HTTP_PROXY_ENV="ENV http_proxy $HTTP_PROXY" |
| 112 | fi |
| 113 | if [[ -n "$HTTPS_PROXY" ]]; then |
| 114 | https_proxy=$HTTPS_PROXY |
| 115 | HTTPS_PROXY_ENV="ENV https_proxy $HTTPS_PROXY" |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 116 | fi |
| 117 | if [[ -n "$http_proxy" ]]; then |
Stewart Smith | 45af3fc | 2019-07-23 15:45:10 +1000 | [diff] [blame] | 118 | if [[ "$distro" == fedora30 ]]; then |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 119 | PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf" |
| 120 | fi |
Stewart Smith | 26b9f99 | 2019-03-27 14:46:49 +1100 | [diff] [blame] | 121 | if [[ "$distro" == ubuntu1804 ]]; then |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 122 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 123 | fi |
| 124 | fi |
Joel Stanley | ce8ae8d | 2018-11-01 13:19:50 +1030 | [diff] [blame] | 125 | if [ ! -z ${DL_DIR+x} ]; then |
Samuel Mendoza-Jonas | 94ec86a | 2018-08-06 15:18:26 +1000 | [diff] [blame] | 126 | DL_DIR_ENV="ENV DL_DIR $DL_DIR" |
| 127 | fi |
Joel Stanley | ce8ae8d | 2018-11-01 13:19:50 +1030 | [diff] [blame] | 128 | if [ ! -z ${CCACHE_DIR+x} ]; then |
Samuel Mendoza-Jonas | 94ec86a | 2018-08-06 15:18:26 +1000 | [diff] [blame] | 129 | CCACHE_DIR_ENV="ENV CCACHE_DIR $CCACHE_DIR" |
| 130 | fi |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 131 | |
| 132 | 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] | 133 | ${PROXY} |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 134 | RUN useradd -d ${HOME} -m -u ${UID} ${USER} |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 135 | ENV HOME ${HOME} |
Stewart Smith | 915cea1 | 2018-01-16 16:07:49 +1100 | [diff] [blame] | 136 | ${HTTP_PROXY_ENV} |
| 137 | ${HTTPS_PROXY_ENV} |
Samuel Mendoza-Jonas | 94ec86a | 2018-08-06 15:18:26 +1000 | [diff] [blame] | 138 | ${DL_DIR_ENV} |
| 139 | ${CCACHE_DIR_ENV} |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 140 | EOF |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 141 | ) |
Samuel Mendoza-Jonas | 86f9bb8 | 2018-08-06 12:51:59 +1000 | [diff] [blame] | 142 | $DOCKER_PREFIX docker build --network=host -t openpower/op-build-$distro - <<< "${Dockerfile}" |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 143 | |
| 144 | if [ -n "$PLATFORMS" ]; then |
| 145 | platform_args="-p $PLATFORMS" |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 146 | else |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 147 | platform_args="" |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 148 | fi |
| 149 | |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 150 | if [ $SDK_ONLY -ne 0 ]; then |
| 151 | sdk_args="-S" |
| 152 | else |
| 153 | sdk_args="" |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 154 | fi |
| 155 | |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 156 | run_docker openpower/op-build-$distro "./ci/build-all-defconfigs.sh -o `pwd`/output-$distro ${platform_args} ${release_args} ${sdk_args} -s $SDK_CACHE" |
| 157 | |
| 158 | if [ $? -ne 0 ]; then |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 159 | exit $?; |
| 160 | fi |
| 161 | done; |
| 162 | |