Automate generation of docker builder images.
[ci-management.git] / docker / scripts / dbld_dump_build_logs.sh
1 #! /bin/bash
2
3 # Copyright (c) 2020 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 set -euxo pipefail
17
18 export CIMAN_DOCKER_SCRIPTS=${CIMAN_DOCKER_SCRIPTS:-"$(dirname $BASH_SOURCE)"}
19 export CIMAN_ROOT=${CIMAN_ROOT:-"$(dirname $(dirname $CIMAN_DOCKER_SCRIPTS))"}
20 . $CIMAN_DOCKER_SCRIPTS/lib_common.sh
21
22 must_be_run_as_root
23 must_be_run_in_docker_build
24
25 dump_build_logs() {
26     local set_opts=$-
27     grep -q e <<< $set_opts && set +e # disable exit on errors
28
29     # Find errors
30     local found="$(grep -nisH error $DOCKER_BUILD_LOG_DIR/*-bld.log)"
31     if [ -n "$found" ] ; then
32         echo -e "\nErrors found in build log files:\n$found\n"
33     else
34         echo -e "\nNo errors found in build logs\n"
35     fi
36
37     # Find warnings
38     found="$(grep -nisH warning $DOCKER_BUILD_LOG_DIR/*-bld.log)"
39     if [ -n "$found" ] ; then
40         echo -e "\nWarnings found in build log files:\n$found\n"
41     else
42         echo -e "\nNo warnings found in build logs\n"
43     fi
44
45     grep -q e <<< $set_opts && set -e # re-enable exit on errors
46 }
47
48 dump_cache_files() {
49     local cache_files_log="$DOCKER_BUILD_LOG_DIR/cached_files.json"
50     tree -a --timefmt "+%Y-%m-%d %H:%M:%S" --prune /root
51     tree -afJ --timefmt "+%Y-%m-%d %H:%M:%S" --prune -o $cache_files_log /root
52 }
53
54 dump_cache_files
55 dump_build_logs
56 dump_echo_log