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 | |
| 28 | RUN dnf --refresh upgrade -y && \ |
| 29 | dnf install -y vim gcc-c++ flex bison git ctags cscope expat-devel \ |
| 30 | patch zlib-devel zlib-static perl |
| 31 | RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 32 | |
| 33 | USER ${USER} |
| 34 | ENV HOME ${HOME} |
| 35 | RUN /bin/bash |
| 36 | EOF |
| 37 | ) |
| 38 | |
| 39 | elif [[ "${distro}" == ubuntu ]]; then |
| 40 | |
| 41 | Dockerfile=$(cat << EOF |
| 42 | FROM ubuntu:15.10 |
| 43 | |
| 44 | ENV DEBIAN_FRONTEND noninteractive |
| 45 | RUN echo $(date +%s) && apt-get update && \ |
| 46 | apt-get install -y \ |
| 47 | cscope ctags libz-dev libexpat-dev python language-pack-en texinfo \ |
| 48 | build-essential g++ git bison flex unzip libxml-simple-perl \ |
| 49 | libxml-sax-perl libxml2-dev libxml2-utils xsltproc |
| 50 | RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 51 | |
| 52 | USER ${USER} |
| 53 | ENV HOME ${HOME} |
| 54 | RUN /bin/bash |
| 55 | EOF |
| 56 | ) |
| 57 | fi |
| 58 | |
| 59 | # Build the docker container |
| 60 | docker build -t op-build/${distro} - <<< "${Dockerfile}" |
| 61 | if [[ "$?" -ne 0 ]]; then |
| 62 | echo "Failed to build docker container." |
| 63 | exit 1 |
| 64 | fi |
| 65 | |
| 66 | mkdir -p ${WORKSPACE} |
| 67 | |
| 68 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 69 | #!/bin/bash |
| 70 | |
| 71 | set -x |
| 72 | |
| 73 | cd ${WORKSPACE}/op-build |
| 74 | |
| 75 | # Source our build env |
| 76 | . op-build-env |
| 77 | |
| 78 | # Configure |
Joel Stanley | f00719d | 2015-12-11 15:16:32 +1030 | [diff] [blame^] | 79 | op-build ${target}_defconfig |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 80 | |
| 81 | # Kick off a build |
Joel Stanley | f00719d | 2015-12-11 15:16:32 +1030 | [diff] [blame^] | 82 | op-build |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 83 | |
| 84 | EOF_SCRIPT |
| 85 | |
| 86 | chmod a+x ${WORKSPACE}/build.sh |
| 87 | |
| 88 | # Run the docker container, execute the build script we just built |
| 89 | docker run --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
| 90 | -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/${distro} ${WORKSPACE}/build.sh |
| 91 | |
| 92 | # Create link to images for archiving |
| 93 | ln -sf ${WORKSPACE}/op-build/output/images ${WORKSPACE}/images |
| 94 | |
| 95 | # Timestamp for build |
| 96 | echo "Build completed, $(date)" |