From b5f30ec343bdb50b30f6410e7d8d7f80a0873cc3 Mon Sep 17 00:00:00 2001 From: Ljubisa Gacevic Date: Tue, 24 Jun 2025 17:31:09 +0200 Subject: [PATCH 1/3] feat: update compare_batches.sh to ignore .batchTTL field --- .gitignore | 5 +++++ scripts/compare_batches.sh | 41 +++++++++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 3726681..5b2e97d 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,8 @@ go.work.sum # Folders dist/ .vscode/ + +**/1.txt +**/2.txt +**/tmp1.json +**/tmp2.json diff --git a/scripts/compare_batches.sh b/scripts/compare_batches.sh index 6f141eb..c5e7637 100755 --- a/scripts/compare_batches.sh +++ b/scripts/compare_batches.sh @@ -10,14 +10,16 @@ DOMAIN1=$1 DOMAIN2=$2 FILE1="1.txt" FILE2="2.txt" +TMP1="tmp1.json" +TMP2="tmp2.json" -# Perform curl requests in parallel -curl -s "http://${DOMAIN1}/batches" | jq > "$FILE1" & +# Fetch both responses in parallel +curl -s "http://${DOMAIN1}/batches" > "$TMP1" & PID1=$! -curl -s "http://${DOMAIN2}/batches" | jq > "$FILE2" & +curl -s "http://${DOMAIN2}/batches" > "$TMP2" & PID2=$! -# Wait for both curl commands to complete +# Wait and check each curl wait $PID1 if [ $? -ne 0 ]; then echo "Error fetching data from ${DOMAIN1}" @@ -30,13 +32,34 @@ if [ $? -ne 0 ]; then exit 1 fi +# Get batch counts +COUNT1=$(jq '.batches | length' "$TMP1" 2>/dev/null) +COUNT2=$(jq '.batches | length' "$TMP2" 2>/dev/null) + +# Validate batch presence +if [ -z "$COUNT1" ] || [ "$COUNT1" -eq 0 ]; then + echo "No batches found in response from ${DOMAIN1}" + exit 1 +fi + +if [ -z "$COUNT2" ] || [ "$COUNT2" -eq 0 ]; then + echo "No batches found in response from ${DOMAIN2}" + exit 1 +fi + +# Print batch counts +echo "Batch count from ${DOMAIN1}: $COUNT1" +echo "Batch count from ${DOMAIN2}: $COUNT2" + +# Strip batchTTL and save for comparison +jq '.batches | map(del(.batchTTL))' "$TMP1" > "$FILE1" +jq '.batches | map(del(.batchTTL))' "$TMP2" > "$FILE2" + # Compare the files and show differences side by side echo "Differences between ${FILE1} and ${FILE2} (side by side):" -diff --side-by-side --suppress-common-lines "$FILE1" "$FILE2" - -# Check if there were any differences -if [ $? -eq 0 ]; then - echo "No differences found." +if diff --side-by-side --suppress-common-lines "$FILE1" "$FILE2"; then + echo "No differences found. Cleaning up..." + rm -f "$FILE1" "$FILE2" "$TMP1" "$TMP2" else echo "Differences found (see above)." fi From 7b55db831bb43ca6ebca8470e1fe0681fa8eeeaf Mon Sep 17 00:00:00 2001 From: Ljubisa Gacevic Date: Tue, 24 Jun 2025 17:56:30 +0200 Subject: [PATCH 2/3] feat: add dockerfile for the compare_batches.sh --- scripts/Dockerfile | 8 ++++++++ scripts/README.md | 11 +++++++++++ scripts/compare_batches.sh | 4 ++-- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 scripts/Dockerfile diff --git a/scripts/Dockerfile b/scripts/Dockerfile new file mode 100644 index 0000000..bfb2164 --- /dev/null +++ b/scripts/Dockerfile @@ -0,0 +1,8 @@ +FROM alpine:3.20 + +RUN apk add --no-cache bash curl jq diffutils + +COPY compare_batches.sh /compare_batches.sh +RUN chmod +x /compare_batches.sh + +ENTRYPOINT ["/compare_batches.sh"] diff --git a/scripts/README.md b/scripts/README.md index b6d3f10..3686c24 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -7,11 +7,13 @@ This directory contains the `compare_batches.sh` script for comparing batch data To use the `compare_batches.sh` script: 1. Make the script executable: + ```bash chmod +x compare_batches.sh ``` 2. Run it with two domain names: + ```bash ./compare_batches.sh localhost:1633 other_domain ``` @@ -32,3 +34,12 @@ The `compare_batches.sh` script: ## Output The script will display differences between the two batch endpoints side by side, or report "No differences found" if the responses are identical. + +## Build & Push + +To build and push the Docker image for this script, you can use the following commands: + +```bash +docker build -t your_dockerhub_username/compare_batches.sh:latest . +docker push your_dockerhub_username/compare_batches.sh:latest +``` diff --git a/scripts/compare_batches.sh b/scripts/compare_batches.sh index c5e7637..ac4672a 100755 --- a/scripts/compare_batches.sh +++ b/scripts/compare_batches.sh @@ -58,8 +58,8 @@ jq '.batches | map(del(.batchTTL))' "$TMP2" > "$FILE2" # Compare the files and show differences side by side echo "Differences between ${FILE1} and ${FILE2} (side by side):" if diff --side-by-side --suppress-common-lines "$FILE1" "$FILE2"; then - echo "No differences found. Cleaning up..." - rm -f "$FILE1" "$FILE2" "$TMP1" "$TMP2" + echo "No differences found." + rm -f "$TMP1" "$TMP2" else echo "Differences found (see above)." fi From 7db8010ffe7ee389f8c4833199f3634bfef547e7 Mon Sep 17 00:00:00 2001 From: Ljubisa Gacevic Date: Tue, 24 Jun 2025 20:21:51 +0200 Subject: [PATCH 3/3] fix: add exit 1 in case there are differences --- scripts/compare_batches.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/compare_batches.sh b/scripts/compare_batches.sh index ac4672a..d0eb5a9 100755 --- a/scripts/compare_batches.sh +++ b/scripts/compare_batches.sh @@ -62,4 +62,5 @@ if diff --side-by-side --suppress-common-lines "$FILE1" "$FILE2"; then rm -f "$TMP1" "$TMP2" else echo "Differences found (see above)." + exit 1 fi