#!bash -e

VERSION_FILE=VERSION
current=$(cat $VERSION_FILE)
tag=$((current + 1))

# Ensure buildx is set up properly for cross-platform builds
docker buildx create --use --name multiplatform || docker buildx use multiplatform

# Build and push with proper multi-platform support
DOCKER_BUILDKIT=1 docker buildx build \
    --platform linux/amd64 \
    --push \
    --progress=plain \
    --provenance=false \
    --sbom=false \
    --output type=registry,oci-mediatypes=false,compression=gzip,compression-level=9,force-compression=true \
    -t docker.bassengvegen.com/openclaw:${tag} \
    --no-cache \
    .

echo $tag > $VERSION_FILE
echo "Successfully built and pushed openclaw:${tag}"