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