add usage (help) to build script
parent
f50c85cce9
commit
6cef778b83
45
build
45
build
|
@ -1,7 +1,30 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
declare targets=(dev arm amd deploy private multi)
|
declare targets=(dev arm amd deploy private multi)
|
||||||
declare OPTION; declare OPTARG; declare OPTIND
|
declare OPTION; declare OPTARG; declare OPTIND
|
||||||
while getopts 'b:d:t:nyr:u:px' OPTION; do
|
|
||||||
|
usage() { # Function: Print a help message.
|
||||||
|
echo "Image Build Script: Creates one or more images using a target in the docker-bake.hcl file"
|
||||||
|
echo "USAGE: $0 <setup options> buildtarget <imagename, imageuser>"
|
||||||
|
echo "valid targets: ${targets[*]}; default: dev"
|
||||||
|
echo no argument options:
|
||||||
|
echo "-c try out the image by starting a container terminal therein, for dev target this is the default;"
|
||||||
|
echo "-x exclude distro from image name;"
|
||||||
|
echo "-n for --no_cache"
|
||||||
|
echo "-p push to repository; after build push to repository default is hub.docker.common (not need for deploy target)"
|
||||||
|
echo required argument options:
|
||||||
|
echo "-t <TAG> tag following : in output image name (i.e. REPO/USER/NAME:TAG), default: latest"
|
||||||
|
echo "-u <USER>; repository user prefix in output image name (i.e. REPO/USER/NAME:TAG)"
|
||||||
|
echo "-r <REPO>; private repo name, do not use for hub.docker.com (docker.io)"
|
||||||
|
echo "-b <BASE_IMAGE>; used in FROM in Dockerfile, default is official distro image (e.g. alpine:latest)"
|
||||||
|
}
|
||||||
|
|
||||||
|
exit_abnormal() { # Function: Exit with error.
|
||||||
|
usage
|
||||||
|
exit ${1:-1}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
while getopts ':b:d:t:ncr:u:pxh' OPTION; do
|
||||||
# echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND}
|
# echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND}
|
||||||
case "$OPTION" in
|
case "$OPTION" in
|
||||||
b)
|
b)
|
||||||
|
@ -22,35 +45,35 @@ declare OPTION; declare OPTARG; declare OPTIND
|
||||||
u)
|
u)
|
||||||
RUSER=$OPTARG
|
RUSER=$OPTARG
|
||||||
;;
|
;;
|
||||||
y)
|
c)
|
||||||
try=true
|
try=true
|
||||||
;;
|
;;
|
||||||
p)
|
p)
|
||||||
push=true
|
push=true
|
||||||
;;
|
;;
|
||||||
n)
|
n)
|
||||||
NO_CACHE=true
|
nocache="--no-cache"
|
||||||
;;
|
;;
|
||||||
r)
|
r)
|
||||||
REPO=$OPTARG
|
REPO=$OPTARG
|
||||||
;;
|
;;
|
||||||
*) echo unknown run option -$OPTARG
|
h)
|
||||||
echo "USAGE: build <setup options> target(or target)"
|
exit_abnormal 0
|
||||||
echo "available options -d <LINUX_DISTRO>; -t <TAG>; -e execute test script after build; -n for --no_cache "
|
;;
|
||||||
|
*)
|
||||||
|
echo "unknown $0 option -$OPTARG"
|
||||||
|
exit_abnormal 4
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
|
|
||||||
[ $NO_CACHE ] && nocache="--no-cache" || nocache=""
|
|
||||||
target=${1:-dev}
|
target=${1:-dev}
|
||||||
LINUX_DISTRO=${LINUX_DISTRO:-alpine}
|
LINUX_DISTRO=${LINUX_DISTRO:-alpine}
|
||||||
name=$2
|
name=$2
|
||||||
RUSER=${3:-$RUSER}
|
RUSER=${3:-$RUSER}
|
||||||
|
|
||||||
|
|
||||||
IMAGE_NAME=$([[ $RUSER ]] && echo ${RUSER}/)${name}$([[ (! $exclude_distro) && $name ]] && echo "-")$([[ ! $exclude_distro ]] && echo ${LINUX_DISTRO})
|
IMAGE_NAME=$([[ $RUSER ]] && echo ${RUSER}/)${name}$([[ (! $exclude_distro) && $name ]] && echo "-")$([[ ! $exclude_distro ]] && echo ${LINUX_DISTRO})
|
||||||
if [[ $BASE_IMAGE ]]; then
|
if [[ $BASE_IMAGE ]]; then
|
||||||
echo determining DISTRO of base image: $BASE_IMAGE
|
echo determining DISTRO of base image: $BASE_IMAGE
|
||||||
|
|
Loading…
Reference in New Issue