Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -ex |
| 4 | |
Saheer Babu | 85b7980 | 2025-08-15 12:53:17 +0100 | [diff] [blame] | 5 | buildah --version |
Paul Sokolovsky | d7a2ea7 | 2022-11-15 17:57:56 +0300 | [diff] [blame] | 6 | |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 7 | echo "" |
| 8 | echo "########################################################################" |
| 9 | echo " Gerrit Environment" |
| 10 | env |grep '^GERRIT' |
| 11 | echo "########################################################################" |
| 12 | |
Saheer Babu | e3544f1 | 2025-08-15 12:56:04 +0100 | [diff] [blame] | 13 | # ON_EC2="0" |
| 14 | # if [ -f /sys/hypervisor/uuid ] && grep -q ^ec2 /sys/hypervisor/uuid; then |
| 15 | # ON_EC2="1" |
| 16 | # fi |
Paul Sokolovsky | 73acc7f | 2022-11-15 14:26:20 +0300 | [diff] [blame] | 17 | |
Saheer Babu | e3544f1 | 2025-08-15 12:56:04 +0100 | [diff] [blame] | 18 | # if [ "${ON_EC2}" == "1" ]; then |
| 19 | # # On EC2 instances, stop and remove unattended-upgrades service which |
| 20 | # # may interfere with any apt operations below. |
| 21 | # sudo systemctl stop unattended-upgrades || true |
| 22 | # sudo apt-get remove -y -qq unattended-upgrades |
| 23 | # fi |
Paul Sokolovsky | 73acc7f | 2022-11-15 14:26:20 +0300 | [diff] [blame] | 24 | |
Saheer Babu | 8e44cb2 | 2025-08-15 15:31:29 +0100 | [diff] [blame] | 25 | # For dpkg-architecture call below |
| 26 | if ! type dpkg-architecture |
| 27 | then |
Saheer Babu | ff8bf09 | 2025-08-15 16:43:26 +0100 | [diff] [blame] | 28 | sudo yum update -y -q |
| 29 | sudo yum install dpkg-dev -y -q |
Saheer Babu | 8e44cb2 | 2025-08-15 15:31:29 +0100 | [diff] [blame] | 30 | fi |
Saheer Babu | e3544f1 | 2025-08-15 12:56:04 +0100 | [diff] [blame] | 31 | |
Saheer Babu | 793e014 | 2025-08-15 17:23:39 +0100 | [diff] [blame] | 32 | host_arch=$(dpkg-architecture -qDEB_HOST_ARCH) |
Paul Sokolovsky | b5dca4b | 2022-11-11 21:52:03 +0300 | [diff] [blame] | 33 | |
| 34 | if ! type aws |
| 35 | then |
Saheer Babu | ff8bf09 | 2025-08-15 16:43:26 +0100 | [diff] [blame] | 36 | sudo yum update -y -q |
| 37 | sudo yum install unzip -y -q |
Saheer Babu | 793e014 | 2025-08-15 17:23:39 +0100 | [diff] [blame] | 38 | arch=$(uname -m) |
| 39 | curl "https://awscli.amazonaws.com/awscli-exe-linux-${arch}.zip" -o "awscliv2.zip" |
Paul Sokolovsky | 0810ea2 | 2022-11-11 22:23:41 +0300 | [diff] [blame] | 40 | unzip -q awscliv2.zip |
Paul Sokolovsky | b5dca4b | 2022-11-11 21:52:03 +0300 | [diff] [blame] | 41 | sudo ./aws/install |
| 42 | fi |
| 43 | |
Riku Voipio | b8ffb56 | 2020-10-12 11:44:40 +0300 | [diff] [blame] | 44 | rm -f ${WORKSPACE}/log |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 45 | cd dockerfiles/ |
| 46 | |
Paul Sokolovsky | b5dca4b | 2022-11-11 21:52:03 +0300 | [diff] [blame] | 47 | aws configure list |
Saheer Babu | 734d2ad | 2024-12-19 09:38:47 +0000 | [diff] [blame] | 48 | aws s3 cp --recursive s3://openci-trustedfirmware-private-${INFRA_ENV}/armclang/ . |
Paul Sokolovsky | b5dca4b | 2022-11-11 21:52:03 +0300 | [diff] [blame] | 49 | find . |
| 50 | |
| 51 | df -h |
| 52 | |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 53 | git_previous_commit=$(git rev-parse HEAD~1) |
| 54 | git_commit=$(git rev-parse HEAD) |
| 55 | files=$(git diff --name-only ${git_previous_commit} ${git_commit}) |
| 56 | echo Changes in: ${files} |
Riku Voipio | b8ffb56 | 2020-10-12 11:44:40 +0300 | [diff] [blame] | 57 | changed_dirs=$(dirname ${files}|sort -u) |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 58 | |
| 59 | update_images="" |
| 60 | for dir in ${changed_dirs}; do |
| 61 | # Find the closest directory with build.sh. This is, primarily, |
| 62 | # to handle changes to tcwg-base/tcwg-build/tcwg-builslave/* directories. |
| 63 | while [ ! -e ${dir}/build.sh -a ! -e ${dir}/.git ]; do |
| 64 | dir=$(dirname ${dir}) |
| 65 | done |
| 66 | # Add this and all dependant images in the update. |
| 67 | dir_basename=$(basename ${dir}) |
| 68 | case "${dir_basename}" in |
| 69 | "tcwg-"*) |
| 70 | # ${dir} is one of generic tcwg-base/* directories. Add dependent |
| 71 | # images to the list. |
| 72 | update_images="${update_images} $(dirname $(find . -path "*-${dir_basename}*/build.sh" | sed -e "s#^\./##g"))" |
| 73 | ;; |
Riku Voipio | b8ffb56 | 2020-10-12 11:44:40 +0300 | [diff] [blame] | 74 | ".") |
| 75 | continue |
| 76 | ;; |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 77 | *) |
| 78 | update_images="${update_images} $(dirname $(find ${dir} -name build.sh))" |
| 79 | ;; |
| 80 | esac |
| 81 | done |
| 82 | update_images="$(echo "${update_images}" | tr " " "\n" | sort -u)" |
| 83 | |
Saheer Babu | 793e014 | 2025-08-15 17:23:39 +0100 | [diff] [blame] | 84 | |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 85 | |
| 86 | for image in ${update_images}; do |
| 87 | ( |
| 88 | cd ${image} |
| 89 | image_arch=$(basename ${PWD} | cut -f2 -d '-') |
| 90 | skip="skip" |
| 91 | if [ -f gerrit-branches ]; then |
| 92 | # Build only from branches mentioned in gerrit-branches |
| 93 | if grep -q "^${GERRIT_BRANCH}\$" gerrit-branches; then |
| 94 | skip="no" |
| 95 | fi |
| 96 | elif [ x"${GERRIT_BRANCH}" = x"master" ]; then |
| 97 | # No gerrit-branch file, so build only from "master" branch. |
| 98 | skip="no" |
| 99 | fi |
| 100 | case "${skip}:${host_arch}:${image_arch}" in |
Saheer Babu | aa6f8e9 | 2025-08-15 17:14:52 +0100 | [diff] [blame] | 101 | "skip:"*) |
| 102 | echo "Skipping: don't need to build ${image} on branch ${GERRIT_BRANCH}" |
| 103 | ;; |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 104 | "no:amd64:amd64"|"no:amd64:i386"|"no:arm64:arm64"|"no:armhf:armhf") |
| 105 | echo "=== Start build: ${image} ===" |
Paul Sokolovsky | 9c6dc90 | 2022-01-17 22:55:27 +0300 | [diff] [blame] | 106 | bash -x ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 107 | ;; |
| 108 | *) |
| 109 | echo "Skipping: can't build for ${image_arch} on ${host_arch}" |
| 110 | ;; |
| 111 | esac |
Benjamin Copeland | c78807d | 2019-04-02 08:54:42 +0100 | [diff] [blame] | 112 | )||echo $image failed >> ${WORKSPACE}/log |
| 113 | done |
| 114 | |