From 3442a8df78cc38a7b9da9b40aa5c6864a9be7e78 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 6 Nov 2022 13:06:14 +0100 Subject: [PATCH] Automate images build and push to docker registry MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- build-image.sh | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) 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) -- 2.34.1