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 \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 64 | patch \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 65 | perl \ |
| 66 | perl-bignum \ |
| 67 | "perl(Digest::SHA1)" \ |
Chris Smart | 905777e | 2016-03-11 15:01:48 +1100 | [diff] [blame] | 68 | "perl(Env)" \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 69 | "perl(Fatal)" \ |
| 70 | "perl(Thread::Queue)" \ |
| 71 | "perl(XML::SAX)" \ |
| 72 | "perl(XML::Simple)" \ |
| 73 | "perl(YAML)" \ |
| 74 | "perl(XML::LibXML)" \ |
| 75 | python \ |
Saqib Khan | 362ca85 | 2017-03-21 10:48:46 -0500 | [diff] [blame] | 76 | python3 \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 77 | tar \ |
| 78 | unzip \ |
| 79 | vim \ |
| 80 | wget \ |
| 81 | which \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 82 | zlib-devel \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 83 | zlib-static |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 84 | |
| 85 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 86 | 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] | 87 | |
| 88 | USER ${USER} |
| 89 | ENV HOME ${HOME} |
| 90 | RUN /bin/bash |
| 91 | EOF |
| 92 | ) |
| 93 | |
| 94 | elif [[ "${distro}" == ubuntu ]]; then |
| 95 | |
| 96 | Dockerfile=$(cat << EOF |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 97 | FROM ${DOCKER_BASE}ubuntu:latest |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 98 | |
| 99 | ENV DEBIAN_FRONTEND noninteractive |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 100 | RUN apt-get update && apt-get install -yy \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 101 | bc \ |
| 102 | bison \ |
| 103 | build-essential \ |
| 104 | cscope \ |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 105 | cpio \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 106 | ctags \ |
| 107 | flex \ |
| 108 | g++ \ |
| 109 | git \ |
| 110 | libexpat-dev \ |
| 111 | libz-dev \ |
| 112 | libxml-sax-perl \ |
| 113 | libxml-simple-perl \ |
| 114 | libxml2-dev \ |
| 115 | libxml2-utils \ |
| 116 | language-pack-en \ |
| 117 | python \ |
Saqib Khan | 362ca85 | 2017-03-21 10:48:46 -0500 | [diff] [blame] | 118 | python3 \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 119 | texinfo \ |
| 120 | unzip \ |
| 121 | vim-common \ |
| 122 | wget\ |
Rahul Maheshwari | d6b829e | 2017-03-20 13:34:35 -0500 | [diff] [blame] | 123 | xsltproc \ |
| 124 | libssl-dev |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 125 | |
| 126 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 127 | 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] | 128 | |
| 129 | USER ${USER} |
| 130 | ENV HOME ${HOME} |
| 131 | RUN /bin/bash |
| 132 | EOF |
| 133 | ) |
| 134 | fi |
| 135 | |
| 136 | # Build the docker container |
| 137 | docker build -t op-build/${distro} - <<< "${Dockerfile}" |
| 138 | if [[ "$?" -ne 0 ]]; then |
| 139 | echo "Failed to build docker container." |
| 140 | exit 1 |
| 141 | fi |
| 142 | |
| 143 | mkdir -p ${WORKSPACE} |
| 144 | |
| 145 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 146 | #!/bin/bash |
| 147 | |
| 148 | set -x |
| 149 | |
Joel Stanley | 21e6523 | 2015-12-11 15:40:54 +1030 | [diff] [blame] | 150 | # This ensures that the alias set in op-build-env is |
| 151 | # avalaible in this script |
| 152 | shopt -s expand_aliases |
| 153 | |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 154 | cd ${WORKSPACE}/op-build |
| 155 | |
| 156 | # Source our build env |
| 157 | . op-build-env |
| 158 | |
| 159 | # Configure |
Joel Stanley | f00719d | 2015-12-11 15:16:32 +1030 | [diff] [blame] | 160 | op-build ${target}_defconfig |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 161 | |
| 162 | # Kick off a build |
Joel Stanley | f00719d | 2015-12-11 15:16:32 +1030 | [diff] [blame] | 163 | op-build |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 164 | |
| 165 | EOF_SCRIPT |
| 166 | |
| 167 | chmod a+x ${WORKSPACE}/build.sh |
| 168 | |
| 169 | # Run the docker container, execute the build script we just built |
| 170 | docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
| 171 | -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/${distro} ${WORKSPACE}/build.sh |
| 172 | |
| 173 | # Create link to images for archiving |
| 174 | ln -sf ${WORKSPACE}/op-build/output/images ${WORKSPACE}/images |
| 175 | |
| 176 | # Timestamp for build |
| 177 | echo "Build completed, $(date)" |