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