Files
linux_docker/build.sh
T
John Colvin 56c61231f3 Upgrade ubuntu to latest LTS (22.10)
This is a big upgrade, from 18.04!
2022-10-04 13:49:25 -05:00

96 lines
2.0 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 The user (name) to add to the image (defaults to the current user)
-p,--pass The password for the <--user> in the image (defaults to the username in the image)
-i,--image The name to give the image
-h,--help Print this help message and exit
EOF
exit $1
}
declare docker_user=""
declare docker_pass=""
declare image_name=""
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
;;
-h)
;&
--help)
print_help_and_exit 0
;;
*)
echo "Unexpected argument '$1'"
print_help_and_exit 1
;;
esac
done
if [[ -z "$image_name" ]]; then
image_name="bluetradingsystems/spark-crypto-dev"
echo "Pulling image '$image_name' from Dockerhub (use --image <name> to build a new image)"
docker pull "$image_name"
declare -n pull_status=$?
if [[ $pull_status -ne 0 ]]; then
echo "docker pull exited with code $pull_status"
fi
exit $?
fi
if [[ -z "$docker_user" ]]; then
docker_user="$USER"
fi
if [[ -z "$docker_pass" ]]; then
docker_pass="$docker_user"
echo "Giving user '$docker_user' a secure password: $docker_pass"
fi
echo "Building image
image_name : $image_name
user : $docker_user"
docker build \
--build-arg docker_user=$docker_user \
--build-arg docker_password=$docker_pass \
-t "$image_name" \
.