feat: add --auto-version flag with registry check to build-image.sh

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 <noreply@anthropic.com>
This commit is contained in:
2026-01-07 13:09:30 +01:00
parent 6cf9b312c0
commit 9d6507c3ae

View File

@@ -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 <version> [--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]$ ]]