@@ -10,7 +10,7 @@ usage() {
10
10
cat >&2 << EOF
11
11
Usage:
12
12
sudo ./build_docker.sh [-i DOCKER_IMAGE_NAME] [-t DOCKER_IMAGE_TAG] DOCKER_BUILD_DIR [REGISTRY_SERVER REGISTRY_PORT REGISTRY_USERNAME REGISTRY_PASSWD]
13
-
13
+
14
14
Description:
15
15
-i DOCKER_IMAGE_NAME
16
16
Specify the docker image's name, by default it is DOCKER_BUILD_DIR
@@ -22,14 +22,15 @@ Description:
22
22
The server name of the docker registry
23
23
REGISTRY_PORT
24
24
The port of the docker registry
25
-
25
+
26
26
Example:
27
27
./build_docker.sh -i docker-orchagent-mlnx docker-orchagent
28
28
EOF
29
29
}
30
30
31
31
docker_image_name=' '
32
32
docker_image_tag=latest
33
+ retry_times=3
33
34
# # The option-string tells getopts which options to expect and which of them must have an argument
34
35
# # When you want getopts to expect an argument for an option, just place a : (colon) after the proper option flag
35
36
# # If the very first character of the option-string is a :, getopts switches to "silent error reporting mode".
@@ -78,9 +79,41 @@ cp -r files $DOCKER_BUILD_DIR/files
78
79
docker_try_rmi $docker_image_name
79
80
80
81
# # Build the docker image
81
- docker build --no-cache -t $docker_image_name $DOCKER_BUILD_DIR
82
+ set +e
83
+ for (( i= $retry_times ; i> 0 ; i-- )) ; do
84
+ timeout 1h docker build --no-cache -t $docker_image_name $DOCKER_BUILD_DIR
85
+ ret_code=$?
86
+ case $ret_code in
87
+ # Docker build without error.
88
+ " 0" )
89
+ break
90
+ ;;
91
+ # Docker build timeout
92
+ " 124" )
93
+ docker_try_rmi $docker_image_name # Remove the exist image
94
+ if [[ $i -eq 1 ]]; then
95
+ echo " Failed to build container [$docker_image_name ] in $retry_times times, exit. "
96
+ rm -rf $DOCKER_BUILD_DIR
97
+ exit $ret_code
98
+ else
99
+ echo " Failed to build container [$docker_image_name ], retry. "
100
+ fi
101
+ ;;
102
+ # Command "Timeout" return error.
103
+ " 125" |" 126" |" 127" |" 137" )
104
+ echo " Error with command \" timeout\" , exit. "
105
+ break
106
+ ;;
107
+ # Docker build got error
108
+ * )
109
+ rm -rf $DOCKER_BUILD_DIR # Replace the trap_up function
110
+ exit $ret_code ;;
111
+ esac
112
+ done
113
+
82
114
# # Get the ID of the built image
83
115
# # Note: inspect output has quotation characters, so sed to remove it as an argument
116
+ set -e
84
117
image_id=$( docker inspect --format=" {{json .Id}}" $docker_image_name | sed -e ' s/^"//' -e ' s/"$//' )
85
118
86
119
# # Flatten the image by importing an exported container on this image
0 commit comments