From: Jérôme Benoit Date: Sun, 6 Nov 2022 12:06:14 +0000 (+0100) Subject: Automate images build and push to docker registry X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3442a8df78cc38a7b9da9b40aa5c6864a9be7e78;p=mbt-docker.git Automate images build and push to docker registry Signed-off-by: Jérôme Benoit --- diff --git a/build-image.sh b/build-image.sh index bb55f2f..bb2abc8 100755 --- a/build-image.sh +++ b/build-image.sh @@ -4,37 +4,61 @@ images="mbt-node14-java11-docker mbt-node16-java11-docker mbt-node18-java11-dock mbt-node14-java17-docker mbt-node16-java17-docker mbt-node18-java17-docker \ mbt-node14-java19-docker mbt-node16-java19-docker mbt-node18-java19-docker" +repositories="mbt-node14-java11-docker mbt-node16-java11-docker mbt-node18-java11-docker \ + mbt-node14-java17-docker mbt-node16-java17-docker mbt-node18-java17-docker \ + mbt-node14-java19-docker mbt-node16-java19-docker mbt-node18-java19-docker" + usage() { - echo "Usage: $0 [-n <${images// /|}|all>" 1>&2; exit 1; + echo "Usage: ./$(basename $0) [-b <${images// /|}|all>] [-p <${repositories// /|}|all>] [-c]" 1>&2; exit 1; } -all() { +build_all() { for image in ${images}; do make NAME=${image} done } +push_all() { + for repository in ${repositories}; do + make docker-push-registry NAME=${repository} + done +} + [ $# -eq 0 ] && usage -while getopts "n:h" option; do +while getopts ":b:p:ch" option; do case "${option}" in - n) + b) name=${OPTARG} if [[ ${name} == "all" ]]; then - all + build_all elif [[ -z "${images##*$name*}" ]]; then make NAME=${name} else - echo "Error: Unknown image name for option argument -${OPTARG}" >&2; + echo "Error: Unknown image name as option argument '${OPTARG}'" >&2; usage fi ;; - \?) - # Invalid option - echo "Error: Unknown or invalid option argument for -${OPTARG}" >&2; - usage + p) + repository=${OPTARG} + if [[ ${repository} == "all" ]]; then + push_all + elif [[ -z "${repositories##*$repository*}" ]]; then + make docker-push-registry NAME=${repository} + else + echo "Error: Unknown repository name as option argument '${OPTARG}'" >&2; + usage + fi + ;; + c) + make dist-clean ;; :) - echo "Error: Missing option argument for -${OPTARG}" >&2; + echo "Error: Missing option argument for '-${OPTARG}'" >&2; + usage + ;; + \?) + # Invalid option + echo "Error: Unknown or invalid option for '-${OPTARG}'" >&2; usage ;; *|h)