forked from osrf/vrx-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_image.bash
executable file
·72 lines (58 loc) · 1.54 KB
/
build_image.bash
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
#!/bin/bash
# build_image.bash: A bash script to build the vrx server image
#
# E.g.: ./build_image.bash # non-Nvidia
# or ./build_image.bash -n # Nvidia
echo "Building vrx-server image"
echo "================================="
set -e
# Constants.
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NOCOLOR='\033[0m'
# Get directory of this file
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Setup docker args
USERID=`id -u`
GROUPID=`id -g`
if [[ ${USERID} != 0 ]]; then
DOCKER_ARGS="--build-arg USERID=${USERID} --build-arg GROUPID=${GROUPID}"
fi
# DOCKER_ARGS="$DOCKER_ARGS --no-cache"
# Parse arguments
BUILD_BASE=""
image_name="vrx-server-noetic"
# Parse args related to NVIDIA
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-n|--nvidia)
BUILD_BASE="--build-arg BASEIMG=nvidia/opengl:1.0-glvnd-devel-ubuntu20.04"
image_name="$image_name-nvidia"
shift
;;
*) # unknown option
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}"
# Usage
if [ $# -gt 0 ]
then
echo "Usage: $0 [-n --nvidia]"
exit 1
fi
# Build image
echo "Build image: $image_name"
set -x
image_plus_tag=$image_name:$(export LC_ALL=C; date +%Y_%m_%d_%H%M)
docker build --force-rm ${DOCKER_ARGS} --tag $image_plus_tag --build-arg USER=$USER --build-arg GROUP=$USER $BUILD_BASE $DIR/vrx-server && \
docker tag $image_plus_tag $image_name:latest && \
echo "Built $image_plus_tag and tagged as $image_name:latest"
set +x
echo -e "${GREEN}Done.${NOCOLOR}\n"