Merge "Include container id in console log."
[ci-management.git] / jjb / scripts / setup_executor_env.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 echo "---> jjb/scripts/setup_executor_env.sh"
17
18 set -e -o pipefail
19
20 OS_ID=$(grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
21 OS_VERSION_ID=$(grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
22 OS_ARCH=$(uname -m)
23 dockerfile="/scratch/docker-build/Dockerfile"
24 file_delimiter="----- %< -----"
25 long_line="************************************************************************"
26 downloads_cache="/root/Downloads"
27
28 echo "$long_line"
29 echo "Executor Runtime Attributes:"
30 echo "OS: $OS_ID-$OS_VERSION_ID"
31 echo "Arch: $OS_ARCH"
32 echo "Nomad Hostname: $(grep search /etc/resolv.conf | cut -d' ' -f2 | head -1)"
33 echo "Container ID: $(hostname)"
34
35 echo "$long_line"
36 if [ -f "$dockerfile" ] ; then
37     echo -e "Executor Dockerfile: ${dockerfile}\n${file_delimiter}"
38     cat $dockerfile
39     echo "$file_delimiter"
40 else
41     echo "Unknown Executor: '$dockerfile' not found!"
42 fi
43
44 echo "$long_line"
45 echo "Executor package list:"
46 if [ "$OS_ID" == "ubuntu" ] || [ "$OS_ID" = "debian" ] ; then
47     dpkg-query -W -f='${binary:Package}\t${Version}\n' | column -t || true
48 elif [ "$OS_ID" == "centos" ] ; then
49     yum list installed || true
50 fi
51
52 echo "$long_line"
53 echo "Python3 package list:"
54 pip3 list 2>/dev/null | column -t || true
55
56 echo "$long_line"
57 echo "Executor Downloads cache '$downloads_cache':"
58 ls -lh "$downloads_cache" || true
59
60 echo "$long_line"
61 echo "DNS nameserver config in '/etc/resolv.conf':"
62 cat /etc/resolv.conf || true
63
64 if [ -n "${CCACHE_DIR:-}" ] ; then
65     echo "$long_line"
66     if [ -d "$CCACHE_DIR" ] ; then
67         num_ccache_files="$(find $CCACHE_DIR -type f | wc -l)"
68         ccache_conf="$CCACHE_DIR/ccache.conf"
69         echo "CCACHE_DIR='$CCACHE_DIR' ($num_ccache_files ccache files):"
70         du -sh /tmp/ccache
71         df -h /tmp/ccache
72         ls -l $CCACHE_DIR
73         unset -v CCACHE_DISABLE
74         if [ -f "$ccache_conf" ] ; then
75             echo "Contents of $ccache_conf:"
76             cat $ccache_conf
77         fi
78     else
79         echo "CCACHE_DIR='$CCACHE_DIR' is missing, disabling CCACHE..."
80         unset -v CCACHE_DIR
81         export CCACHE_DISABLE="1"
82         echo "CCACHE_DISABLE='${CCACHE_DISABLE:-}'"
83     fi
84 fi
85 echo "$long_line"