diff --git a/build-and-tag.sh b/build-and-tag.sh index a7caad7..823fb3a 100755 --- a/build-and-tag.sh +++ b/build-and-tag.sh @@ -1,13 +1,28 @@ #!/usr/bin/env bash # Build the container image and tag it for the registry. -# Usage: ./build-and-tag.sh e.g. ./build-and-tag.sh v1 +# Usage: ./build-and-tag.sh # reads version.txt, increments, builds, pushes +# Usage: ./build-and-tag.sh # explicit tag (e.g. ./build-and-tag.sh v6) set -e IMAGE=hardings-service REGISTRY=registry.digitalsorcery.net -TAG="${1:?usage: $0 }" +VERSION_FILE="$(dirname "$0")/version.txt" +if [ -n "$1" ]; then + TAG="$1" +else + # Read current version, increment the numeric portion + CURRENT=$(cat "$VERSION_FILE" | tr -d '[:space:]') + NUM=$(echo "$CURRENT" | sed 's/v//') + TAG="v$((NUM + 1))" +fi + +echo "Building ${IMAGE}:${TAG} ..." podman build -t "${IMAGE}:${TAG}" -f Containerfile . podman tag "${IMAGE}:${TAG}" "${REGISTRY}/${IMAGE}:${TAG}" +podman push "${REGISTRY}/${IMAGE}:${TAG}" -echo "Push with: podman push ${REGISTRY}/${IMAGE}:${TAG}" +# Update version.txt to match the tag we just pushed +echo "$TAG" > "$VERSION_FILE" + +echo "Done. ${REGISTRY}/${IMAGE}:${TAG} pushed." diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..9c0be88 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +v6