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