blob: e4f58e00247ae63d07a5edf72498a44c9ef78136 [file] [log] [blame]
Benjamin Copelandc78807d2019-04-02 08:54:42 +01001#!/bin/bash
2
3set -ex
4
5trap cleanup_exit INT TERM EXIT
6
7cleanup_exit()
8{
9 rm -rf ${HOME}/.docker
10 rm -f ${WORKSPACE}/{log,config.json,version.txt}
11}
12
13mkdir -p ${HOME}/.docker
Benjamin Copelandbfb78482019-07-10 12:56:15 +010014wget https://ci.trustedfirmware.org/userContent/config.json
Benjamin Copelandc78807d2019-04-02 08:54:42 +010015sed -e "s|\${DOCKER_AUTH}|${DOCKER_AUTH}|" < ${WORKSPACE}/config.json > ${HOME}/.docker/config.json
16chmod 0600 ${HOME}/.docker/config.json
17
18echo ""
19echo "########################################################################"
20echo " Gerrit Environment"
21env |grep '^GERRIT'
22echo "########################################################################"
23
24rm -f ${WORKSPACE}/{log,config.json,version.txt}
25cd dockerfiles/
26
27git_previous_commit=$(git rev-parse HEAD~1)
28git_commit=$(git rev-parse HEAD)
29files=$(git diff --name-only ${git_previous_commit} ${git_commit})
30echo Changes in: ${files}
31changed_dirs=$(dirname ${files})
32
33update_images=""
34for dir in ${changed_dirs}; do
35 # Find the closest directory with build.sh. This is, primarily,
36 # to handle changes to tcwg-base/tcwg-build/tcwg-builslave/* directories.
37 while [ ! -e ${dir}/build.sh -a ! -e ${dir}/.git ]; do
38 dir=$(dirname ${dir})
39 done
40 # Add this and all dependant images in the update.
41 dir_basename=$(basename ${dir})
42 case "${dir_basename}" in
43 "tcwg-"*)
44 # ${dir} is one of generic tcwg-base/* directories. Add dependent
45 # images to the list.
46 update_images="${update_images} $(dirname $(find . -path "*-${dir_basename}*/build.sh" | sed -e "s#^\./##g"))"
47 ;;
48 *)
49 update_images="${update_images} $(dirname $(find ${dir} -name build.sh))"
50 ;;
51 esac
52done
53update_images="$(echo "${update_images}" | tr " " "\n" | sort -u)"
54
55host_arch=$(dpkg-architecture -qDEB_HOST_ARCH)
56
57for image in ${update_images}; do
58 (
59 cd ${image}
60 image_arch=$(basename ${PWD} | cut -f2 -d '-')
61 skip="skip"
62 if [ -f gerrit-branches ]; then
63 # Build only from branches mentioned in gerrit-branches
64 if grep -q "^${GERRIT_BRANCH}\$" gerrit-branches; then
65 skip="no"
66 fi
67 elif [ x"${GERRIT_BRANCH}" = x"master" ]; then
68 # No gerrit-branch file, so build only from "master" branch.
69 skip="no"
70 fi
71 case "${skip}:${host_arch}:${image_arch}" in
72 "skip:"*)
73 echo "Skipping: don't need to build ${image} on branch ${GERRIT_BRANCH}"
74 ;;
75 "no:amd64:amd64"|"no:amd64:i386"|"no:arm64:arm64"|"no:armhf:armhf")
76 echo "=== Start build: ${image} ==="
77 ./build.sh || echo "=== FAIL: ${image} ===" >> ${WORKSPACE}/log
78 ;;
79 *)
80 echo "Skipping: can't build for ${image_arch} on ${host_arch}"
81 ;;
82 esac
83 if [ -r .docker-tag ]; then
84 docker_tag=$(cat .docker-tag)
85 if [ x"${GERRIT_BRANCH}" != x"master" ]; then
86 new_tag=${docker_tag}-${GERRIT_BRANCH}
87 docker tag ${docker_tag} ${new_tag}
88 docker_tag=${new_tag}
89 fi
90 docker push ${docker_tag}
91 fi
92 )||echo $image failed >> ${WORKSPACE}/log
93done
94
95if [ -e ${WORKSPACE}/log ]
96then
97 echo "some images failed:"
98 cat ${WORKSPACE}/log
99 exit 1
100fi