| 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 | 
|  | 7 | #   distro = ubuntu | 
|  | 8 | #   WORKSPACE = | 
|  | 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}} | 
|  | 17 | http_proxy=${http_proxy:-} | 
|  | 18 |  | 
|  | 19 | # Timestamp for job | 
|  | 20 | echo "Build started, $(date)" | 
|  | 21 |  | 
|  | 22 | # Configure docker build | 
|  | 23 | if [[ "${distro}" == fedora ]];then | 
|  | 24 |  | 
|  | 25 | Dockerfile=$(cat << EOF | 
|  | 26 | FROM fedora:latest | 
|  | 27 |  | 
| Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 28 | RUN dnf --refresh repolist && dnf install -y \ | 
|  | 29 | bc \ | 
| Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 30 | bison \ | 
| Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 31 | bzip2 \ | 
|  | 32 | cpio \ | 
| Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 33 | cscope \ | 
| Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 34 | ctags \ | 
| Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 35 | expat-devel \ | 
| Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 36 | findutils \ | 
|  | 37 | flex \ | 
|  | 38 | gcc-c++ \ | 
|  | 39 | git \ | 
|  | 40 | libxml2-devel \ | 
|  | 41 | ncurses-devel \ | 
| Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 42 | patch \ | 
| Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 43 | perl \ | 
|  | 44 | perl-bignum \ | 
|  | 45 | "perl(Digest::SHA1)" \ | 
| Chris Smart | 905777e | 2016-03-11 15:01:48 +1100 | [diff] [blame] | 46 | "perl(Env)" \ | 
| Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 47 | "perl(Fatal)" \ | 
|  | 48 | "perl(Thread::Queue)" \ | 
|  | 49 | "perl(XML::SAX)" \ | 
|  | 50 | "perl(XML::Simple)" \ | 
|  | 51 | "perl(YAML)" \ | 
|  | 52 | "perl(XML::LibXML)" \ | 
|  | 53 | python \ | 
|  | 54 | tar \ | 
|  | 55 | unzip \ | 
|  | 56 | vim \ | 
|  | 57 | wget \ | 
|  | 58 | which \ | 
| Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 59 | zlib-devel \ | 
| Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 60 | zlib-static | 
| Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 61 |  | 
|  | 62 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} | 
|  | 63 | 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] | 64 |  | 
|  | 65 | USER ${USER} | 
|  | 66 | ENV HOME ${HOME} | 
|  | 67 | RUN /bin/bash | 
|  | 68 | EOF | 
|  | 69 | ) | 
|  | 70 |  | 
|  | 71 | elif [[ "${distro}" == ubuntu ]]; then | 
|  | 72 |  | 
|  | 73 | Dockerfile=$(cat << EOF | 
|  | 74 | FROM ubuntu:15.10 | 
|  | 75 |  | 
|  | 76 | ENV DEBIAN_FRONTEND noninteractive | 
| Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 77 | RUN apt-get update && apt-get install -yy \ | 
| Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 78 | bc \ | 
|  | 79 | bison \ | 
|  | 80 | build-essential \ | 
|  | 81 | cscope \ | 
|  | 82 | cpio \ | 
|  | 83 | ctags \ | 
|  | 84 | flex \ | 
|  | 85 | g++ \ | 
|  | 86 | git \ | 
|  | 87 | libexpat-dev \ | 
|  | 88 | libz-dev \ | 
|  | 89 | libxml-sax-perl \ | 
|  | 90 | libxml-simple-perl \ | 
|  | 91 | libxml2-dev \ | 
|  | 92 | libxml2-utils \ | 
|  | 93 | language-pack-en \ | 
|  | 94 | python \ | 
|  | 95 | texinfo \ | 
|  | 96 | unzip \ | 
|  | 97 | vim-common \ | 
|  | 98 | wget\ | 
|  | 99 | xsltproc | 
|  | 100 |  | 
|  | 101 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} | 
|  | 102 | 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] | 103 |  | 
|  | 104 | USER ${USER} | 
|  | 105 | ENV HOME ${HOME} | 
|  | 106 | RUN /bin/bash | 
|  | 107 | EOF | 
|  | 108 | ) | 
|  | 109 | fi | 
|  | 110 |  | 
|  | 111 | # Build the docker container | 
|  | 112 | docker build -t op-build/${distro} - <<< "${Dockerfile}" | 
|  | 113 | if [[ "$?" -ne 0 ]]; then | 
|  | 114 | echo "Failed to build docker container." | 
|  | 115 | exit 1 | 
|  | 116 | fi | 
|  | 117 |  | 
|  | 118 | mkdir -p ${WORKSPACE} | 
|  | 119 |  | 
|  | 120 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT | 
|  | 121 | #!/bin/bash | 
|  | 122 |  | 
|  | 123 | set -x | 
|  | 124 |  | 
| Joel Stanley | 21e6523 | 2015-12-11 15:40:54 +1030 | [diff] [blame] | 125 | # This ensures that the alias set in op-build-env is | 
|  | 126 | # avalaible in this script | 
|  | 127 | shopt -s expand_aliases | 
|  | 128 |  | 
| Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 129 | cd ${WORKSPACE}/op-build | 
|  | 130 |  | 
|  | 131 | # Source our build env | 
|  | 132 | . op-build-env | 
|  | 133 |  | 
|  | 134 | # Configure | 
| Joel Stanley | f00719d | 2015-12-11 15:16:32 +1030 | [diff] [blame] | 135 | op-build ${target}_defconfig | 
| Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 136 |  | 
|  | 137 | # Kick off a build | 
| Joel Stanley | f00719d | 2015-12-11 15:16:32 +1030 | [diff] [blame] | 138 | op-build | 
| Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 139 |  | 
|  | 140 | EOF_SCRIPT | 
|  | 141 |  | 
|  | 142 | chmod a+x ${WORKSPACE}/build.sh | 
|  | 143 |  | 
|  | 144 | # Run the docker container, execute the build script we just built | 
|  | 145 | docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ | 
|  | 146 | -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/${distro} ${WORKSPACE}/build.sh | 
|  | 147 |  | 
|  | 148 | # Create link to images for archiving | 
|  | 149 | ln -sf ${WORKSPACE}/op-build/output/images ${WORKSPACE}/images | 
|  | 150 |  | 
|  | 151 | # Timestamp for build | 
|  | 152 | echo "Build completed, $(date)" |