-
Notifications
You must be signed in to change notification settings - Fork 30
/
build_docker_images.sh
executable file
·117 lines (96 loc) · 2.94 KB
/
build_docker_images.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
### enable debug
#set -exvfC
set -e
###################################################
# This script builds and uploads ROS docker images.
###################################################
################
# User Setting #
################
DOCKERHUB_USERNAME="${DOCKERHUB_USERNAME:-tomoyafujita}"
ARCH=$(dpkg --print-architecture)
ros_distros=(
"noetic"
"rolling"
)
build_manifest=false
### Functions Implementation
function print_usage() {
echo "Usage: $0 [-m]"
echo "Options(default):"
echo " -m : build and upload manifest along with container images for multi-arch support. (default: false)"
exit 1
}
function exit_trap() {
if [ $? != 0 ]; then
echo "Command [$BASH_COMMAND] is failed"
exit 1
fi
}
function check_dockerhub_setting () {
trap exit_trap ERR
echo "[${FUNCNAME[0]}]: checking dockerhub setting and configuration."
if [ -z "$DOCKERHUB_USERNAME" ]; then
echo "DOCKERHUB_USERNAME is not set."
exit 1
fi
# check if docker login succeeds
docker login
}
function build_images() {
trap exit_trap ERR
echo "[${FUNCNAME[0]}]: building ROS docker container images."
for distro in "${ros_distros[@]}"; do
echo "----- $distro image building for $ARCH"
docker build --rm -f ./docker/Dockerfile.$distro -t $DOCKERHUB_USERNAME/ros:$distro-$ARCH .
done
echo "----- all images successfully generated!!! -----"
}
function build_manifest_for_images() {
trap exit_trap ERR
echo "[${FUNCNAME[0]}]: building multi-arch manifest ROS docker container images."
for distro in "${ros_distros[@]}"; do
echo "----- $distro manifest"
docker manifest create $DOCKERHUB_USERNAME/ros:$distro $DOCKERHUB_USERNAME/ros:$distro-amd64 --amend $DOCKERHUB_USERNAME/ros:$distro-arm64
docker manifest inspect $DOCKERHUB_USERNAME/ros:$distro
docker manifest push $DOCKERHUB_USERNAME/ros:$distro
done
echo "----- all manifest successfully updated!!! -----"
}
function upload_images() {
trap exit_trap ERR
echo "[${FUNCNAME[0]}]: uploading ROS docker container images."
for distro in "${ros_distros[@]}"; do
echo "----- $distro image uploading for $ARCH"
docker push $DOCKERHUB_USERNAME/ros:$distro-$ARCH
done
echo "----- all images successfully uploaded!!! -----"
}
### Main
# set the trap on error
trap exit_trap ERR
# parse command line options
while getopts ":m" opt; do
case $opt in
m)
build_manifest=true
;;
\?)
echo "Invalid option: -$OPTARG"
print_usage
;;
esac
done
shift $((OPTIND-1))
echo "Check Docker Environment ----------"
check_dockerhub_setting
echo "Buiding Container Images ----------"
build_images
if [ "$build_manifest" == true ]; then
echo "Building Container Manifest ----------"
build_manifest_for_images
fi
echo "Uploading Container Images ----------"
upload_images
exit 0