| 1 | #!/usr/bin/env sh |
| 2 | |
| 3 | shopt -s extglob |
| 4 | |
| 5 | images="mbt-node14-java8-docker mbt-node16-java8-docker mbt-node18-java8-docker \ |
| 6 | mbt-node14-java11-docker mbt-node16-java11-docker mbt-node18-java11-docker \ |
| 7 | mbt-node14-java17-docker mbt-node16-java17-docker mbt-node18-java17-docker \ |
| 8 | mbt-node14-java20-docker mbt-node16-java20-docker mbt-node18-java20-docker" |
| 9 | |
| 10 | # repositories="mbt-node14-java8-docker mbt-node16-java8-docker mbt-node18-java8-docker \ |
| 11 | # mbt-node14-java11-docker mbt-node16-java11-docker mbt-node18-java11-docker \ |
| 12 | # mbt-node14-java17-docker mbt-node16-java17-docker mbt-node18-java17-docker \ |
| 13 | # mbt-node14-java20-docker mbt-node16-java20-docker mbt-node18-java20-docker" |
| 14 | |
| 15 | repositories=${images} |
| 16 | |
| 17 | usage() { |
| 18 | echo " Build docker images. |
| 19 | |
| 20 | Usage: |
| 21 | ./$(basename $0) [-b <name>] |
| 22 | ./$(basename $0) [-p <name>] |
| 23 | ./$(basename $0) [-c] |
| 24 | ./$(basename $0) [-h] |
| 25 | |
| 26 | Options: |
| 27 | -h Show this help. |
| 28 | -b <${images//+([[:space:]])/|}|all> Build docker images. |
| 29 | -p <${repositories//+([[:space:]])/|}|all> Push docker images. |
| 30 | -c Clean docker images." 1>&2; exit 1; |
| 31 | } |
| 32 | |
| 33 | build_all() { |
| 34 | for image in ${images}; do |
| 35 | make NAME=${image} |
| 36 | done |
| 37 | } |
| 38 | |
| 39 | push_all() { |
| 40 | for repository in ${repositories}; do |
| 41 | make docker-push-registry NAME=${repository} |
| 42 | done |
| 43 | } |
| 44 | |
| 45 | [ $# -eq 0 ] && usage |
| 46 | while getopts ":b:p:ch" option; do |
| 47 | case "${option}" in |
| 48 | b) |
| 49 | name=${OPTARG} |
| 50 | if [ ${name} = "all" ]; then |
| 51 | build_all |
| 52 | elif [ -z "${images##*$name*}" ]; then |
| 53 | make NAME=${name} |
| 54 | else |
| 55 | echo "Error: Unknown image name as option argument '${OPTARG}'" >&2; |
| 56 | usage |
| 57 | fi |
| 58 | ;; |
| 59 | p) |
| 60 | repository=${OPTARG} |
| 61 | if [ ${repository} = "all" ]; then |
| 62 | push_all |
| 63 | elif [ -z "${repositories##*$repository*}" ]; then |
| 64 | make docker-push-registry NAME=${repository} |
| 65 | else |
| 66 | echo "Error: Unknown repository name as option argument '${OPTARG}'" >&2; |
| 67 | usage |
| 68 | fi |
| 69 | ;; |
| 70 | c) |
| 71 | make dist-clean |
| 72 | ;; |
| 73 | :) |
| 74 | echo "Error: Missing option argument for '-${OPTARG}'" >&2; |
| 75 | usage |
| 76 | ;; |
| 77 | \?) |
| 78 | # Invalid option |
| 79 | echo "Error: Unknown or invalid option for '-${OPTARG}'" >&2; |
| 80 | usage |
| 81 | ;; |
| 82 | *|h) |
| 83 | usage |
| 84 | ;; |
| 85 | esac |
| 86 | done |