Skip to content

Commit

Permalink
Rewrite podman_build arg parsing
Browse files Browse the repository at this point in the history
Use getopts to implement help text and a flag for images with no
registry

Move default image tag back to quay.io/ibutsu prefix, use new flag to
control it
  • Loading branch information
mshriver committed Jun 11, 2024
1 parent bebc41d commit 1f9a1b1
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions podman_build.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
#!/bin/bash

if [[ "$1" == "" ]]; then
IMAGES_TO_BUILD=("backend" "scheduler" "worker" "flower" "frontend")
else
function print_usage() {
echo "Usage: podman_build.sh [-h|--help] [--local-tag] [backend|scheduler|worker|flower|frontend]"
echo ""
echo "optional arguments:"
echo " -h show this help message"
echo " -l use a tag with no registry specified"
echo " images* images to build, or nothing to build all images"
echo ""
}

# Defaults for output
IMAGE_PREFIX="quay.io/ibutsu/"
IMAGES_TO_BUILD=("backend" "scheduler" "worker" "flower" "frontend")

# Parse the options
while getopts ':lh' OPTION
do
case "${OPTION}" in
h) print_usage; exit 0;;
l) IMAGE_PREFIX="ibutsu/";;
*) print_usage; exit 1;;
esac
done

# Handle the image args
shift $((OPTIND - 1))
if [[ "$1" != "" ]]; then
IMAGES_TO_BUILD=("$1")
fi

# Image info
# 7 char SHA for tagging
IMAGE_TAG=$(git rev-parse --short=7 HEAD)
IMAGE_PREFIX="ibutsu/"

declare -A RESULTS
# Let the user know what we're going to do
printf "\nCurrent SHA for image tags: %s\n" ${IMAGE_TAG}
echo "Building image(s): ${IMAGES_TO_BUILD[*]}"


# Build images
# Iterate and build images sequentially
declare -A RESULTS
for IMAGE in "${IMAGES_TO_BUILD[@]}"; do
printf -- "\n--------------------- BUILDING: %s ---------------------\n" ${IMAGE}
printf -- "\n---------------- BUILDING: %s%s:%s ----------------\n" ${IMAGE_PREFIX} ${IMAGE} ${IMAGE_TAG}
if [[ "${IMAGE}" == "frontend" ]]; then
BASE_DIR=frontend
else
Expand All @@ -24,6 +51,7 @@ for IMAGE in "${IMAGES_TO_BUILD[@]}"; do
RESULTS[${IMAGE}]=$?
done

# dump results to console at the end
echo "BUILD RESULTS:"
for IMAGE in "${!RESULTS[@]}"; do
printf "%s: %d\n" $IMAGE ${RESULTS[${IMAGE}]}
Expand Down

0 comments on commit 1f9a1b1

Please sign in to comment.