This is a more accurate and appropriate name than 'spark-dev' because the image is designed to build/run Sparkd and the Spark Api Server (both of which are daemons, hence the appropriateness of the 'd' suffix). It isn't designed to build/run the front-end desktop application, Spark.
111 lines
2.2 KiB
Bash
Executable File
111 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
function print_help_and_exit() {
|
|
cat <<EOF
|
|
Build the (dev) docker image
|
|
Usage: build.sh [OPTIONS]
|
|
|
|
Options:
|
|
-u,--user USER or USER:UID The user to add to the image (defaults to 'bts')
|
|
-p,--pass The password for USER in the image (defaults to USER)
|
|
-i,--image The name to give the image (defaults to "USER:sparkd-dev")
|
|
-h,--help Print this help message and exit
|
|
|
|
EOF
|
|
exit "$1"
|
|
}
|
|
|
|
|
|
declare docker_user=""
|
|
declare docker_pass=""
|
|
declare image_name=""
|
|
declare -i docker_pull=1
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
-i)
|
|
;&
|
|
--image)
|
|
if [[ -z "$2" ]]; then
|
|
echo "Image (-i,--image) must be non-empty"
|
|
print_help_and_exit 1
|
|
fi
|
|
image_name="$2"
|
|
shift 2
|
|
;;
|
|
-u)
|
|
;&
|
|
--user)
|
|
if [[ -z "$2" ]]; then
|
|
echo "User (-u,--user) must be non-empty"
|
|
print_help_and_exit 1
|
|
fi
|
|
docker_user="$2"
|
|
shift 2
|
|
;;
|
|
-p)
|
|
;&
|
|
--pass)
|
|
if [[ -z "$2" ]]; then
|
|
echo "Password (-p,--pass) must be non-empty"
|
|
print_help_and_exit 1
|
|
fi
|
|
docker_pass="$2"
|
|
shift 2
|
|
;;
|
|
--no-pull)
|
|
docker_pull=0
|
|
shift 1
|
|
;;
|
|
-h)
|
|
;&
|
|
--help)
|
|
print_help_and_exit 0
|
|
;;
|
|
*)
|
|
echo "Unexpected argument '$1'"
|
|
print_help_and_exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
declare -a docker_user_args=($(echo "$docker_user" | sed -e 's/:/ /g'))
|
|
case ${#docker_user_args[@]} in
|
|
0)
|
|
docker_user="bts"
|
|
docker_uid="$(id -u)"
|
|
;;
|
|
1)
|
|
docker_user="${docker_user_args[0]}"
|
|
docker_uid="$(id -u)"
|
|
;;
|
|
2)
|
|
docker_user="${docker_user_args[0]}"
|
|
docker_uid="${docker_user_args[1]}"
|
|
;;
|
|
*)
|
|
echo "Invalid docker_user: $docker_user"
|
|
print_help_and_exit 1
|
|
;;
|
|
esac
|
|
|
|
if [[ -z "$image_name" ]]; then
|
|
image_name="${docker_user}:sparkd-dev"
|
|
fi
|
|
|
|
echo "Building image
|
|
image_name : $image_name
|
|
user : $docker_user"
|
|
|
|
if [[ -z "$docker_pass" ]]; then
|
|
docker_pass="$docker_user"
|
|
echo "Giving user '$docker_user' a secure password: $docker_pass"
|
|
fi
|
|
|
|
docker build \
|
|
--build-arg docker_user="$docker_user" \
|
|
--build-arg docker_pass="$docker_pass" \
|
|
--build-arg docker_uid="$docker_uid" \
|
|
-t "$image_name" \
|
|
.
|