blob: 3977465f1dcff0e3fe29613949411dffcea3117c [file] [log] [blame]
Benjamin Copelandc78807d2019-04-02 08:54:42 +01001#!/bin/bash
2
3set -ex
4
Paul Sokolovskyd7a2ea72022-11-15 17:57:56 +03005docker --version
6
Benjamin Copelandc78807d2019-04-02 08:54:42 +01007echo ""
8echo "########################################################################"
9echo " Gerrit Environment"
10env |grep '^GERRIT'
11echo "########################################################################"
12
Paul Sokolovsky73acc7f2022-11-15 14:26:20 +030013ON_EC2="0"
14if [ -f /sys/hypervisor/uuid ] && grep -q ^ec2 /sys/hypervisor/uuid; then
15 ON_EC2="1"
16fi
17
18if [ "${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
22 sudo apt-get remove -y -qq unattended-upgrades
23fi
24
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030025# For dpkg-architecture call below
Paul Sokolovsky09455562022-11-12 11:35:36 +030026if ! type dpkg-architecture
27then
Paul Sokolovskyd681d632022-12-08 19:18:42 +030028 sudo apt-get -y -qq update
Paul Sokolovsky09455562022-11-12 11:35:36 +030029 sudo apt-get -y -qq install --no-install-recommends dpkg-dev
Paul Sokolovsky429589e2022-11-12 11:43:14 +030030fi
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030031
32if ! type aws
33then
34 sudo apt-get -y -qq update
35 sudo apt-get -y -qq install --no-install-recommends unzip
36 curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
Paul Sokolovsky0810ea22022-11-11 22:23:41 +030037 unzip -q awscliv2.zip
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030038 sudo ./aws/install
39fi
40
Riku Voipiob8ffb562020-10-12 11:44:40 +030041rm -f ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +010042cd dockerfiles/
43
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030044aws configure list
Saheer Babu2e499e82024-12-19 09:38:47 +000045aws s3 cp --recursive s3://openci-trustedfirmware-private-${INFRA_ENV}/armclang/ .
Paul Sokolovskyb5dca4b2022-11-11 21:52:03 +030046find .
47
48df -h
49
Benjamin Copelandc78807d2019-04-02 08:54:42 +010050git_previous_commit=$(git rev-parse HEAD~1)
51git_commit=$(git rev-parse HEAD)
52files=$(git diff --name-only ${git_previous_commit} ${git_commit})
53echo Changes in: ${files}
Riku Voipiob8ffb562020-10-12 11:44:40 +030054changed_dirs=$(dirname ${files}|sort -u)
Benjamin Copelandc78807d2019-04-02 08:54:42 +010055
56update_images=""
57for dir in ${changed_dirs}; do
58 # Find the closest directory with build.sh. This is, primarily,
59 # to handle changes to tcwg-base/tcwg-build/tcwg-builslave/* directories.
60 while [ ! -e ${dir}/build.sh -a ! -e ${dir}/.git ]; do
61 dir=$(dirname ${dir})
62 done
63 # Add this and all dependant images in the update.
64 dir_basename=$(basename ${dir})
65 case "${dir_basename}" in
66 "tcwg-"*)
67 # ${dir} is one of generic tcwg-base/* directories. Add dependent
68 # images to the list.
69 update_images="${update_images} $(dirname $(find . -path "*-${dir_basename}*/build.sh" | sed -e "s#^\./##g"))"
70 ;;
Riku Voipiob8ffb562020-10-12 11:44:40 +030071 ".")
72 continue
73 ;;
Benjamin Copelandc78807d2019-04-02 08:54:42 +010074 *)
75 update_images="${update_images} $(dirname $(find ${dir} -name build.sh))"
76 ;;
77 esac
78done
79update_images="$(echo "${update_images}" | tr " " "\n" | sort -u)"
80
81host_arch=$(dpkg-architecture -qDEB_HOST_ARCH)
82
83for image in ${update_images}; do
84 (
85 cd ${image}
86 image_arch=$(basename ${PWD} | cut -f2 -d '-')
87 skip="skip"
88 if [ -f gerrit-branches ]; then
89 # Build only from branches mentioned in gerrit-branches
90 if grep -q "^${GERRIT_BRANCH}\$" gerrit-branches; then
91 skip="no"
92 fi
93 elif [ x"${GERRIT_BRANCH}" = x"master" ]; then
94 # No gerrit-branch file, so build only from "master" branch.
95 skip="no"
96 fi
97 case "${skip}:${host_arch}:${image_arch}" in
98 "skip:"*)
99 echo "Skipping: don't need to build ${image} on branch ${GERRIT_BRANCH}"
100 ;;
101 "no:amd64:amd64"|"no:amd64:i386"|"no:arm64:arm64"|"no:armhf:armhf")
102 echo "=== Start build: ${image} ==="
Paul Sokolovsky9c6dc902022-01-17 22:55:27 +0300103 bash -x ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100104 ;;
105 *)
106 echo "Skipping: can't build for ${image_arch} on ${host_arch}"
107 ;;
108 esac
Benjamin Copelandc78807d2019-04-02 08:54:42 +0100109 )||echo $image failed >> ${WORKSPACE}/log
110done
111