From 9d6507c3aee09c75d9979a36fd6afef2693c4e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Wed, 7 Jan 2026 13:09:30 +0100 Subject: [PATCH] feat: add --auto-version flag with registry check to build-image.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add --auto-version flag to automatically use version from package.json and check if image already exists in registry before building. If image exists, script exits to prevent duplicate versions. Rename --autopush to --auto-push for consistent flag naming. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- mailgun-webhook/build-image.sh | 54 ++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/mailgun-webhook/build-image.sh b/mailgun-webhook/build-image.sh index 7a41675..be7c6f2 100755 --- a/mailgun-webhook/build-image.sh +++ b/mailgun-webhook/build-image.sh @@ -1,13 +1,54 @@ #!/bin/bash -if [ "$1" == "" ] ; then +# Parse flags +AUTO_VERSION=false +AUTO_PUSH=false +IMAGE_VERSION="" + +for arg in "$@"; do + case $arg in + --auto-version) + AUTO_VERSION=true + ;; + --auto-push) + AUTO_PUSH=true + ;; + *) + if [ "$IMAGE_VERSION" == "" ] && [[ ! "$arg" =~ ^-- ]]; then + IMAGE_VERSION=$arg + fi + ;; + esac +done + +# Determine version +if [ "$AUTO_VERSION" = true ]; then + IMAGE_VERSION=$(node -p "require('./package.json').version") + printf "\nAuto-version enabled. Using version from package.json: %s\n" "$IMAGE_VERSION" +elif [ "$IMAGE_VERSION" == "" ]; then printf "\nYou did not specify the Docker image version to build" - printf "\n\nSyntax:\n\n build-image.sh 1.0.0 [--autopush]\n\n" + printf "\n\nSyntax:\n\n build-image.sh [--auto-push]" + printf "\n build-image.sh --auto-version [--auto-push]\n\n" exit 1 fi -# Check for --autopush flag -if [ "$2" == "--autopush" ]; then +REGISTRY_URL="registry.budakova.org" +IMAGE_NAME=$(node -p "require('./package.json').name") +IMAGE_TAG=$REGISTRY_URL/$IMAGE_NAME:$IMAGE_VERSION + +# Check if image already exists in registry (only when using auto-version) +if [ "$AUTO_VERSION" = true ]; then + printf "\nChecking if image %s already exists in registry...\n" "$IMAGE_TAG" + if docker manifest inspect $IMAGE_TAG > /dev/null 2>&1; then + printf "\nERROR: Image %s already exists in registry.\n" "$IMAGE_TAG" + printf "Please update the version in package.json before building.\n\n" + exit 1 + fi + printf "Image does not exist in registry. Proceeding with build.\n" +fi + +# Check for push preference +if [ "$AUTO_PUSH" = true ]; then PUSH_IMAGE="y" printf "\nAuto-push enabled. Image will be pushed to registry.\n" else @@ -18,11 +59,6 @@ fi printf "\nBUILD START ...\n\n" -REGISTRY_URL="registry.budakova.org" -IMAGE_NAME=$(node -p "require('./package.json').name") -IMAGE_VERSION=$1 - -IMAGE_TAG=$REGISTRY_URL/$IMAGE_NAME:$IMAGE_VERSION docker build . -t $IMAGE_TAG if [[ "$PUSH_IMAGE" =~ ^[Yy]$ ]]