| Giorgi Lekveishvili | 285ab62 | 2023-11-22 13:50:45 +0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | usage() { |
| 4 | me=`basename "$0"` |
| 5 | echo >&2 "Usage: $me [--help] [--tag TAG] [--gerrit-url URL] [--base-image IMAGE] [IMAGE]" |
| 6 | exit 1 |
| 7 | } |
| 8 | |
| 9 | while test $# -gt 0 ; do |
| 10 | case "$1" in |
| 11 | --help) |
| 12 | usage |
| 13 | ;; |
| 14 | |
| 15 | --tag) |
| 16 | shift |
| 17 | TAG=$1 |
| 18 | shift |
| 19 | ;; |
| 20 | |
| 21 | --gerrit-url) |
| 22 | shift |
| 23 | GERRIT_WAR_URL=$1 |
| 24 | shift |
| 25 | ;; |
| 26 | |
| 27 | --healthcheck-jar-url) |
| 28 | shift |
| 29 | HEALTHCHECK_JAR_URL=$1 |
| 30 | shift |
| 31 | ;; |
| 32 | |
| 33 | --base-image) |
| 34 | shift |
| 35 | BASE_IMAGE=$1 |
| 36 | shift |
| 37 | ;; |
| 38 | |
| 39 | *) |
| 40 | break |
| 41 | esac |
| 42 | done |
| 43 | |
| 44 | #Get list of images |
| 45 | source container-images/publish_list |
| 46 | IMAGES=$(get_image_list) |
| 47 | |
| 48 | if test -n "$GERRIT_WAR_URL"; then |
| 49 | BUILD_ARGS="--build-arg GERRIT_WAR_URL=$GERRIT_WAR_URL" |
| 50 | fi |
| 51 | |
| 52 | if test -n "$HEALTHCHECK_JAR_URL"; then |
| 53 | BUILD_ARGS="$BUILD_ARGS --build-arg HEALTHCHECK_JAR_URL=$HEALTHCHECK_JAR_URL" |
| 54 | fi |
| 55 | |
| 56 | export REV="$(git describe --always --dirty)" |
| 57 | |
| 58 | docker_build(){ |
| 59 | IMAGE=$1 |
| 60 | |
| 61 | docker build \ |
| 62 | --platform=linux/amd64 \ |
| 63 | --build-arg TAG=$REV \ |
| 64 | -t k8sgerrit/$IMAGE:$TAG \ |
| 65 | ./container-images/$IMAGE |
| 66 | |
| 67 | if test $? -ne 0; then |
| 68 | REPORT="$REPORT Failed: k8sgerrit/$IMAGE.\n" |
| 69 | RETURN_CODE=1 |
| 70 | else |
| 71 | REPORT="$REPORT Success: k8sgerrit/$IMAGE:$TAG\n" |
| 72 | fi |
| 73 | } |
| 74 | |
| 75 | docker_build_gerrit_base(){ |
| 76 | BUILD_ARGS="$BUILD_ARGS --build-arg TAG=$REV" |
| 77 | docker build \ |
| 78 | --platform=linux/amd64 \ |
| 79 | $BUILD_ARGS \ |
| 80 | -t gerrit-base:$REV \ |
| 81 | ./container-images/gerrit-base |
| 82 | if test $? -ne 0; then |
| 83 | echo -e "\n\nFailed to build gerrit-base image." |
| 84 | exit 1 |
| 85 | fi |
| 86 | |
| 87 | if test -z "$TAG"; then |
| 88 | export TAG="$(./get_version.sh)" |
| 89 | fi |
| 90 | } |
| 91 | |
| 92 | REPORT="Build results: \n" |
| 93 | RETURN_CODE=0 |
| 94 | |
| 95 | if test -n "$BASE_IMAGE"; then |
| 96 | BASE_BUILD_ARGS="--build-arg BASE_IMAGE=$BASE_IMAGE" |
| 97 | fi |
| 98 | |
| 99 | docker build $BASE_BUILD_ARGS --platform=linux/amd64 -t base:$REV ./container-images/base |
| 100 | if test $? -ne 0; then |
| 101 | echo -e "\n\nFailed to build base image." |
| 102 | exit 1 |
| 103 | fi |
| 104 | |
| 105 | if test $# -eq 0 ; then |
| 106 | docker_build_gerrit_base |
| 107 | for IMAGE in $IMAGES; do |
| 108 | docker_build $IMAGE |
| 109 | done |
| 110 | else |
| 111 | while test $# -gt 0 ; do |
| 112 | if [[ $1 = gerrit-* ]]; then |
| 113 | docker_build_gerrit_base |
| 114 | else |
| 115 | if test -z "$TAG"; then |
| 116 | TAG="$(git describe --always --dirty)-unknown" |
| 117 | fi |
| 118 | echo -e "\nNo Image containing Gerrit will be built." \ |
| 119 | "The Gerrit-version can thus not be determinded." \ |
| 120 | "Using tag $TAG\n" |
| 121 | fi |
| 122 | docker_build $1 |
| 123 | shift |
| 124 | done |
| 125 | fi |
| 126 | |
| 127 | echo -e "\n\n$REPORT" |
| 128 | exit $RETURN_CODE |