Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This build script is for running the Jenkins builds using docker. |
| 4 | # |
| 5 | # It expects a few variables which are part of Jenkins build job matrix: |
| 6 | # target = palmetto|qemu|habanero|firestone|garrison |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 7 | # distro = ubuntu|fedora |
| 8 | # WORKSPACE = Random Number by Default |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 9 | |
| 10 | # Trace bash processing |
| 11 | set -x |
| 12 | |
| 13 | # Default variables |
| 14 | target=${target:-palmetto} |
| 15 | distro=${distro:-ubuntu} |
| 16 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 17 | |
| 18 | # Timestamp for job |
| 19 | echo "Build started, $(date)" |
| 20 | |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 21 | # if there is no open-power directory clone in master into workspace |
| 22 | if [ ! -e ${WORKSPACE}/op-build ]; then |
| 23 | echo "Clone in openpower master to ${WORKSPACE}/op-build" |
| 24 | git clone --recursive https://github.com/open-power/op-build ${WORKSPACE}/op-build |
| 25 | fi |
| 26 | |
| 27 | # Determine the architecture |
| 28 | ARCH=$(uname -m) |
| 29 | |
| 30 | # Determine the prefix of the Dockerfile's base image |
| 31 | case ${ARCH} in |
| 32 | "ppc64le") |
| 33 | DOCKER_BASE="ppc64le/" |
| 34 | ;; |
| 35 | "x86_64") |
| 36 | DOCKER_BASE="" |
| 37 | ;; |
| 38 | *) |
| 39 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 40 | exit 1 |
| 41 | esac |
| 42 | |
| 43 | |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 44 | # Configure docker build |
| 45 | if [[ "${distro}" == fedora ]];then |
| 46 | |
| 47 | Dockerfile=$(cat << EOF |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 48 | FROM ${DOCKER_BASE}fedora:latest |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 49 | |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 50 | RUN dnf --refresh repolist && dnf install -y \ |
| 51 | bc \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 52 | bison \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 53 | bzip2 \ |
| 54 | cpio \ |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 55 | cscope \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 56 | ctags \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 57 | expat-devel \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 58 | findutils \ |
| 59 | flex \ |
| 60 | gcc-c++ \ |
| 61 | git \ |
| 62 | libxml2-devel \ |
| 63 | ncurses-devel \ |
Joel Stanley | 2ab9a21 | 2017-03-23 10:56:27 +1030 | [diff] [blame^] | 64 | openssl-devel \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 65 | patch \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 66 | perl \ |
| 67 | perl-bignum \ |
| 68 | "perl(Digest::SHA1)" \ |
Chris Smart | 905777e | 2016-03-11 15:01:48 +1100 | [diff] [blame] | 69 | "perl(Env)" \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 70 | "perl(Fatal)" \ |
| 71 | "perl(Thread::Queue)" \ |
| 72 | "perl(XML::SAX)" \ |
| 73 | "perl(XML::Simple)" \ |
| 74 | "perl(YAML)" \ |
| 75 | "perl(XML::LibXML)" \ |
| 76 | python \ |
Saqib Khan | 362ca85 | 2017-03-21 10:48:46 -0500 | [diff] [blame] | 77 | python3 \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 78 | tar \ |
| 79 | unzip \ |
| 80 | vim \ |
| 81 | wget \ |
| 82 | which \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 83 | zlib-devel \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 84 | zlib-static |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 85 | |
| 86 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 87 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 88 | |
| 89 | USER ${USER} |
| 90 | ENV HOME ${HOME} |
| 91 | RUN /bin/bash |
| 92 | EOF |
| 93 | ) |
| 94 | |
| 95 | elif [[ "${distro}" == ubuntu ]]; then |
| 96 | |
| 97 | Dockerfile=$(cat << EOF |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 98 | FROM ${DOCKER_BASE}ubuntu:latest |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 99 | |
| 100 | ENV DEBIAN_FRONTEND noninteractive |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 101 | RUN apt-get update && apt-get install -yy \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 102 | bc \ |
| 103 | bison \ |
| 104 | build-essential \ |
| 105 | cscope \ |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 106 | cpio \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 107 | ctags \ |
| 108 | flex \ |
| 109 | g++ \ |
| 110 | git \ |
Joel Stanley | 2ab9a21 | 2017-03-23 10:56:27 +1030 | [diff] [blame^] | 111 | libssl-dev \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 112 | libexpat-dev \ |
| 113 | libz-dev \ |
| 114 | libxml-sax-perl \ |
| 115 | libxml-simple-perl \ |
| 116 | libxml2-dev \ |
| 117 | libxml2-utils \ |
| 118 | language-pack-en \ |
| 119 | python \ |
Saqib Khan | 362ca85 | 2017-03-21 10:48:46 -0500 | [diff] [blame] | 120 | python3 \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 121 | texinfo \ |
| 122 | unzip \ |
| 123 | vim-common \ |
| 124 | wget\ |
Rahul Maheshwari | d6b829e | 2017-03-20 13:34:35 -0500 | [diff] [blame] | 125 | xsltproc \ |
| 126 | libssl-dev |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 127 | |
| 128 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 129 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 130 | |
| 131 | USER ${USER} |
| 132 | ENV HOME ${HOME} |
| 133 | RUN /bin/bash |
| 134 | EOF |
| 135 | ) |
| 136 | fi |
| 137 | |
| 138 | # Build the docker container |
| 139 | docker build -t op-build/${distro} - <<< "${Dockerfile}" |
| 140 | if [[ "$?" -ne 0 ]]; then |
| 141 | echo "Failed to build docker container." |
| 142 | exit 1 |
| 143 | fi |
| 144 | |
| 145 | mkdir -p ${WORKSPACE} |
| 146 | |
| 147 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 148 | #!/bin/bash |
| 149 | |
| 150 | set -x |
| 151 | |
Joel Stanley | 21e6523 | 2015-12-11 15:40:54 +1030 | [diff] [blame] | 152 | # This ensures that the alias set in op-build-env is |
| 153 | # avalaible in this script |
| 154 | shopt -s expand_aliases |
| 155 | |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 156 | cd ${WORKSPACE}/op-build |
| 157 | |
| 158 | # Source our build env |
| 159 | . op-build-env |
| 160 | |
| 161 | # Configure |
Joel Stanley | f00719d | 2015-12-11 15:16:32 +1030 | [diff] [blame] | 162 | op-build ${target}_defconfig |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 163 | |
| 164 | # Kick off a build |
Joel Stanley | f00719d | 2015-12-11 15:16:32 +1030 | [diff] [blame] | 165 | op-build |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 166 | |
| 167 | EOF_SCRIPT |
| 168 | |
| 169 | chmod a+x ${WORKSPACE}/build.sh |
| 170 | |
| 171 | # Run the docker container, execute the build script we just built |
| 172 | docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
| 173 | -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/${distro} ${WORKSPACE}/build.sh |
| 174 | |
| 175 | # Create link to images for archiving |
| 176 | ln -sf ${WORKSPACE}/op-build/output/images ${WORKSPACE}/images |
| 177 | |
| 178 | # Timestamp for build |
| 179 | echo "Build completed, $(date)" |