3 # Copyright (c) 2024 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:
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # Log all output to stdout & stderr to a log file
19 export DOCKER_DATE=${DOCKER_DATE:-"$(date -u +%Y_%m_%d_%H%M%S_UTC)"}
20 logname="/tmp/$(basename $0).${DOCKER_DATE}.log"
21 echo -e "\n*** Logging output to $logname ***\n\n"
22 exec > >(tee -a $logname) 2>&1
24 export CIMAN_DOCKER_SCRIPTS=${CIMAN_DOCKER_SCRIPTS:-"$(dirname $BASH_SOURCE)"}
25 . "$CIMAN_DOCKER_SCRIPTS/lib_vpp.sh"
26 . "$CIMAN_DOCKER_SCRIPTS/lib_csit.sh"
27 . "$CIMAN_DOCKER_SCRIPTS/lib_apt.sh"
39 echo "Usage: $0 [-c <class>] [-p] [-r <role>] -a | <os name> [... <os name>]"
40 echo " -a Run all OS's supported on class $EXECUTOR_CLASS & arch $OS_ARCH"
41 echo " -c <class> Default is '$EXECUTOR_DEFAULT_CLASS'"
43 echo " -d Generate Dockerfile, dump it to stdout, and exit"
44 echo " -p Push docker images to Docker Hub"
45 echo " -r <role> Add a role based tag (e.g. sandbox-x86_64):"
47 executor_list_os_names
51 must_be_run_as_root_or_docker_group
52 while getopts ":ac:dhpr:" opt; do
54 a) all_os_names="1" ;;
55 c) if executor_verify_class "$OPTARG" ; then
56 EXECUTOR_CLASS="$OPTARG"
57 EXECUTOR_CLASS_ARCH="$EXECUTOR_CLASS-$OS_ARCH"
59 echo "ERROR: Invalid executor class '$OPTARG'!"
62 d) dump_dockerfile="1"; set +x ;;
64 p) push_to_docker_hub="1" ;;
65 r) if executor_verify_role "$OPTARG" ; then
66 ci_tag="${OPTARG}-$OS_ARCH"
68 echo "ERROR: Invalid executor role: '$OPTARG'!"
72 echo "ERROR: Invalid option: -$OPTARG" >&2
75 echo "ERROR: Option -$OPTARG requires an argument." >&2
79 shift $(( $OPTIND-1 ))
81 if [ -n "$all_os_names" ] ; then
82 os_names="${EXECUTOR_CLASS_ARCH_OS_NAMES[$EXECUTOR_CLASS_ARCH]}"
88 if [ -z "$os_names" ] ; then
89 echo "ERROR: Missing executor OS name(s) for class '$EXECUTOR_CLASS'!"
92 for executor_os_name in $os_names ; do
93 if ! executor_verify_os_name "$executor_os_name" ; then
95 set +x # disable trace output
96 echo "ERROR: Invalid executor OS name for class '$EXECUTOR_CLASS': $executor_os_name!"
97 executor_list_os_names
103 # Build the specified docker images
104 docker_build_setup_ciman
105 docker_build_setup_vpp
106 docker_build_setup_csit
107 for executor_os_name in $os_names ; do
108 docker_from_image="${executor_os_name/-/:}"
109 # Remove '-' and '.' from executor_os_name in Docker Hub repo name
110 os_name="${executor_os_name//-}"
111 repository="fdiotools/${EXECUTOR_CLASS}-${os_name//.}"
112 executor_docker_image="$repository:$DOCKER_TAG"
114 case "$executor_os_name" in
116 generate_apt_dockerfile "$EXECUTOR_CLASS" "$executor_os_name" \
117 "$docker_from_image" "$executor_docker_image" ;;
119 generate_apt_dockerfile "$EXECUTOR_CLASS" "$executor_os_name" \
120 "$docker_from_image" "$executor_docker_image" ;;
122 echo "ERROR: Don't know how to generate dockerfile for OS $executor_os_name!"
126 if [ -n "$dump_dockerfile" ] ; then
127 line="==========================================================================="
128 echo -e "\nDockerfile for '$EXECUTOR_CLASS' executor docker image on OS '$executor_os_name':\n$line"
132 docker build -t "$executor_docker_image" "$DOCKER_BUILD_DIR"
134 if [ -n "$ci_tag" ] ; then
135 ci_image="$repository:$ci_tag"
136 echo -e "\nAdding docker tag $ci_image to $executor_docker_image"
137 docker tag "$executor_docker_image" "$ci_image"
139 if [ -n "$push_to_docker_hub" ] ; then
140 echo -e "\nPushing $executor_docker_image to Docker Hub..."
142 docker push "$executor_docker_image"
143 if [ -n "$ci_image" ] ; then
144 echo -e "\nPushing $ci_image to Docker Hub..."
145 docker push "$ci_image"
151 echo -e "\n$(basename $BASH_SOURCE) COMPLETE\nHave a great day! :D"