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 |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 22 | if [ ! -e "${WORKSPACE}"/op-build ]; then |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 23 | echo "Clone in openpower master to ${WORKSPACE}/op-build" |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 24 | git clone --recursive https://github.com/open-power/op-build "${WORKSPACE}"/op-build |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 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 | ;; |
Thang Q. Nguyen | 051b05b | 2021-12-10 08:30:35 +0000 | [diff] [blame^] | 38 | "aarch64") |
| 39 | DOCKER_BASE="" |
| 40 | ;; |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 41 | *) |
| 42 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 43 | exit 1 |
| 44 | esac |
| 45 | |
| 46 | |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 47 | # Configure docker build |
| 48 | if [[ "${distro}" == fedora ]];then |
| 49 | |
| 50 | Dockerfile=$(cat << EOF |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 51 | FROM ${DOCKER_BASE}fedora:latest |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 52 | |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 53 | RUN dnf --refresh repolist && dnf install -y \ |
| 54 | bc \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 55 | bison \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 56 | bzip2 \ |
| 57 | cpio \ |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 58 | cscope \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 59 | ctags \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 60 | expat-devel \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 61 | findutils \ |
| 62 | flex \ |
| 63 | gcc-c++ \ |
| 64 | git \ |
| 65 | libxml2-devel \ |
| 66 | ncurses-devel \ |
Joel Stanley | 2ab9a21 | 2017-03-23 10:56:27 +1030 | [diff] [blame] | 67 | openssl-devel \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 68 | patch \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 69 | perl \ |
| 70 | perl-bignum \ |
| 71 | "perl(Digest::SHA1)" \ |
Chris Smart | 905777e | 2016-03-11 15:01:48 +1100 | [diff] [blame] | 72 | "perl(Env)" \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 73 | "perl(Fatal)" \ |
| 74 | "perl(Thread::Queue)" \ |
| 75 | "perl(XML::SAX)" \ |
| 76 | "perl(XML::Simple)" \ |
| 77 | "perl(YAML)" \ |
| 78 | "perl(XML::LibXML)" \ |
| 79 | python \ |
Saqib Khan | 362ca85 | 2017-03-21 10:48:46 -0500 | [diff] [blame] | 80 | python3 \ |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 81 | tar \ |
| 82 | unzip \ |
| 83 | vim \ |
| 84 | wget \ |
| 85 | which \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 86 | zlib-devel \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame] | 87 | zlib-static \ |
| 88 | iputils-ping |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 89 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 90 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 91 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 92 | |
| 93 | USER ${USER} |
| 94 | ENV HOME ${HOME} |
| 95 | RUN /bin/bash |
| 96 | EOF |
| 97 | ) |
| 98 | |
| 99 | elif [[ "${distro}" == ubuntu ]]; then |
| 100 | |
| 101 | Dockerfile=$(cat << EOF |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 102 | FROM ${DOCKER_BASE}ubuntu:latest |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 103 | |
| 104 | ENV DEBIAN_FRONTEND noninteractive |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 105 | RUN apt-get update && apt-get install -yy \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 106 | bc \ |
| 107 | bison \ |
| 108 | build-essential \ |
| 109 | cscope \ |
AlannyLopez | 266312e | 2017-02-17 10:37:28 -0600 | [diff] [blame] | 110 | cpio \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 111 | ctags \ |
| 112 | flex \ |
| 113 | g++ \ |
| 114 | git \ |
Joel Stanley | 2ab9a21 | 2017-03-23 10:56:27 +1030 | [diff] [blame] | 115 | libssl-dev \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 116 | libexpat-dev \ |
| 117 | libz-dev \ |
| 118 | libxml-sax-perl \ |
| 119 | libxml-simple-perl \ |
| 120 | libxml2-dev \ |
| 121 | libxml2-utils \ |
| 122 | language-pack-en \ |
| 123 | python \ |
Saqib Khan | 362ca85 | 2017-03-21 10:48:46 -0500 | [diff] [blame] | 124 | python3 \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 125 | texinfo \ |
| 126 | unzip \ |
| 127 | vim-common \ |
| 128 | wget\ |
Rahul Maheshwari | d6b829e | 2017-03-20 13:34:35 -0500 | [diff] [blame] | 129 | xsltproc \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame] | 130 | libssl-dev \ |
| 131 | iputils-ping |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 132 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 133 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 134 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 135 | |
| 136 | USER ${USER} |
| 137 | ENV HOME ${HOME} |
| 138 | RUN /bin/bash |
| 139 | EOF |
| 140 | ) |
| 141 | fi |
| 142 | |
| 143 | # Build the docker container |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 144 | if ! docker build -t op-build/"${distro}" - <<< "${Dockerfile}" ; then |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 145 | echo "Failed to build docker container." |
| 146 | exit 1 |
| 147 | fi |
| 148 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 149 | mkdir -p "${WORKSPACE}" |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 150 | |
| 151 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 152 | #!/bin/bash |
| 153 | |
| 154 | set -x |
| 155 | |
Joel Stanley | 21e6523 | 2015-12-11 15:40:54 +1030 | [diff] [blame] | 156 | # This ensures that the alias set in op-build-env is |
| 157 | # avalaible in this script |
| 158 | shopt -s expand_aliases |
| 159 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 160 | cd "${WORKSPACE}"/op-build |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 161 | |
| 162 | # Source our build env |
| 163 | . op-build-env |
| 164 | |
| 165 | # Configure |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 166 | op-build "${target}_defconfig" |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 167 | |
| 168 | # Kick off a build |
Joel Stanley | f00719d | 2015-12-11 15:16:32 +1030 | [diff] [blame] | 169 | op-build |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 170 | |
| 171 | EOF_SCRIPT |
| 172 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 173 | chmod a+x "${WORKSPACE}"/build.sh |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 174 | |
| 175 | # Run the docker container, execute the build script we just built |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 176 | docker run --net=host --rm=true -e WORKSPACE="${WORKSPACE}" --user="${USER}" \ |
| 177 | -w "${HOME}" -v "${HOME}":"${HOME}" -t op-build/"${distro}" "${WORKSPACE}"/build.sh |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 178 | |
| 179 | # Create link to images for archiving |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 180 | ln -sf "${WORKSPACE}"/op-build/output/images "${WORKSPACE}"/images |
Joel Stanley | 2ed389f | 2015-12-11 15:07:07 +1030 | [diff] [blame] | 181 | |
| 182 | # Timestamp for build |
| 183 | echo "Build completed, $(date)" |