From 2811b6ced04e5172320ad7fc70bef4d69a9c0c2d Mon Sep 17 00:00:00 2001 From: smerle33 Date: Fri, 13 Dec 2024 14:30:49 +0100 Subject: [PATCH 1/4] setting the same pattern for the flags in the geoipupdate command with equals --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index e5ebb9c..8c66f40 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -84,7 +84,7 @@ echo "LAUNCH GEOIPUPDATE" GEOIPUPDATEJSONDIR="$(mktemp -d)" export GEOIPUPDATEJSONDIR if [ "${GEOIPUPDATE_DRYRUN:-false}" != "true" ]; then - geoipupdate --verbose --output "${GEOIPUPDATEJSONDIR}/geoipupdate.json" --database-directory="${GEOIPUPDATE_DB_DIR}" + geoipupdate --verbose --output="${GEOIPUPDATEJSONDIR}/geoipupdate.json" --database-directory="${GEOIPUPDATE_DB_DIR}" else echo "DRY-RUN ON" [[ "$(uname || true)" == "Darwin" ]] && dateCmd="gdate" || dateCmd="date" From 82c26a4e264277cfe3f7da461ef7d94aac04d029 Mon Sep 17 00:00:00 2001 From: smerle33 Date: Fri, 13 Dec 2024 14:41:59 +0100 Subject: [PATCH 2/4] change dir to path variable for json --- entrypoint.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 8c66f40..18dbe65 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -81,25 +81,26 @@ ls -lt "${GEOIPUPDATE_DB_DIR}" ### GEOUPDATEIP echo "LAUNCH GEOIPUPDATE" -GEOIPUPDATEJSONDIR="$(mktemp -d)" -export GEOIPUPDATEJSONDIR +GEOIPUPDATEJSONPATH="$(mktemp)" +export GEOIPUPDATEJSONPATH if [ "${GEOIPUPDATE_DRYRUN:-false}" != "true" ]; then - geoipupdate --verbose --output="${GEOIPUPDATEJSONDIR}/geoipupdate.json" --database-directory="${GEOIPUPDATE_DB_DIR}" + geoipupdate --output --database-directory="${GEOIPUPDATE_DB_DIR}" > "${GEOIPUPDATEJSONPATH}" else echo "DRY-RUN ON" [[ "$(uname || true)" == "Darwin" ]] && dateCmd="gdate" || dateCmd="date" currentUTCdatetime="$("${dateCmd}" --utc +"%Y%m%dT%H%MZ")" echo "dry-run" >"${GEOIPUPDATE_DB_DIR}/dryrun-${currentUTCdatetime}.mmdb" - echo '[{"edition_id":"GeoLite2-ASN","old_hash":"c54b6e64478adfd010c7a86db310033f","new_hash":"857a0cf8118b9961cf6789e1842bce2a","modified_at":1733403617,"checked_at":1733756616},{"edition_id":"GeoLite2-City","old_hash":"34a6a0ec4018c74a503134980c154502","new_hash":"fb3449d8252f74eac39fc55c32c19879","modified_at":1733501742,"checked_at":1733756620},{"edition_id":"GeoLite2-Country","old_hash":"627a1d220b5ef844e0f0f174a0161cd7","new_hash":"27b1f57ae9dd56e1923f5d458514794c","modified_at":1733506208,"checked_at":1733756621}]' > "${GEOIPUPDATEJSONDIR}/geoipupdate.json" - # echo '[{"edition_id":"GeoLite2-ASN","old_hash":"857a0cf8118b9961cf6789e1842bce2a","new_hash":"857a0cf8118b9961cf6789e1842bce2a","checked_at":1733760216},{"edition_id":"GeoLite2-City","old_hash":"fb3449d8252f74eac39fc55c32c19879","new_hash":"fb3449d8252f74eac39fc55c32c19879","checked_at":1733760216},{"edition_id":"GeoLite2-Country","old_hash":"27b1f57ae9dd56e1923f5d458514794c","new_hash":"27b1f57ae9dd56e1923f5d458514794c","checked_at":1733760216}]' > "${GEOIPUPDATEJSONDIR}/geoipupdate.json" - echo "json saved to file ${GEOIPUPDATEJSONDIR}/geoipupdate.json" - cat "${GEOIPUPDATEJSONDIR}/geoipupdate.json" + echo '[{"edition_id":"GeoLite2-ASN","old_hash":"c54b6e64478adfd010c7a86db310033f","new_hash":"857a0cf8118b9961cf6789e1842bce2a","modified_at":1733403617,"checked_at":1733756616},{"edition_id":"GeoLite2-City","old_hash":"34a6a0ec4018c74a503134980c154502","new_hash":"fb3449d8252f74eac39fc55c32c19879","modified_at":1733501742,"checked_at":1733756620},{"edition_id":"GeoLite2-Country","old_hash":"627a1d220b5ef844e0f0f174a0161cd7","new_hash":"27b1f57ae9dd56e1923f5d458514794c","modified_at":1733506208,"checked_at":1733756621}]' > "${GEOIPUPDATEJSONPATH}" + # echo '[{"edition_id":"GeoLite2-ASN","old_hash":"857a0cf8118b9961cf6789e1842bce2a","new_hash":"857a0cf8118b9961cf6789e1842bce2a","checked_at":1733760216},{"edition_id":"GeoLite2-City","old_hash":"fb3449d8252f74eac39fc55c32c19879","new_hash":"fb3449d8252f74eac39fc55c32c19879","checked_at":1733760216},{"edition_id":"GeoLite2-Country","old_hash":"27b1f57ae9dd56e1923f5d458514794c","new_hash":"27b1f57ae9dd56e1923f5d458514794c","checked_at":1733760216}]' > "${GEOIPUPDATEJSONPATH}" + echo "json saved to file ${GEOIPUPDATEJSONPATH}" fi +jq -r . "${GEOIPUPDATEJSONPATH}" # check that the file exist and has valid json content. +jq 'has("old_hash") and has("new_hash")' "${GEOIPUPDATEJSONPATH}" echo "GEOIPUPDATE DONE" ### PARSING JSON copy if hash have changed # > /dev/null to avoid multiple true in output but keep errors output -if jq -e '.[] | select(.old_hash != .new_hash)' "${GEOIPUPDATEJSONDIR}/geoipupdate.json" > /dev/null; then +if jq -e '.[] | select(.old_hash != .new_hash)' "${GEOIPUPDATEJSONPATH}" > /dev/null; then echo "DATA CHANGED, update needed" ### AZCOPY local to dest echo "LAUNCH AZCOPY local to dest" From 6758cc671cb91814faf4b4a027e158e755e5207b Mon Sep 17 00:00:00 2001 From: smerle33 Date: Fri, 13 Dec 2024 14:53:20 +0100 Subject: [PATCH 3/4] remove for now, need check --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 18dbe65..7072061 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -95,7 +95,7 @@ else echo "json saved to file ${GEOIPUPDATEJSONPATH}" fi jq -r . "${GEOIPUPDATEJSONPATH}" # check that the file exist and has valid json content. -jq 'has("old_hash") and has("new_hash")' "${GEOIPUPDATEJSONPATH}" +# jq 'has("old_hash") and has("new_hash")' "${GEOIPUPDATEJSONPATH}" echo "GEOIPUPDATE DONE" ### PARSING JSON copy if hash have changed From 24b460f05ead6fa6abc63362fb39d735adafb153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20MERLE?= <95630726+smerle33@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:58:19 +0100 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Damien Duportal --- entrypoint.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 7072061..dc4d92e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -82,7 +82,6 @@ ls -lt "${GEOIPUPDATE_DB_DIR}" ### GEOUPDATEIP echo "LAUNCH GEOIPUPDATE" GEOIPUPDATEJSONPATH="$(mktemp)" -export GEOIPUPDATEJSONPATH if [ "${GEOIPUPDATE_DRYRUN:-false}" != "true" ]; then geoipupdate --output --database-directory="${GEOIPUPDATE_DB_DIR}" > "${GEOIPUPDATEJSONPATH}" else @@ -91,11 +90,11 @@ else currentUTCdatetime="$("${dateCmd}" --utc +"%Y%m%dT%H%MZ")" echo "dry-run" >"${GEOIPUPDATE_DB_DIR}/dryrun-${currentUTCdatetime}.mmdb" echo '[{"edition_id":"GeoLite2-ASN","old_hash":"c54b6e64478adfd010c7a86db310033f","new_hash":"857a0cf8118b9961cf6789e1842bce2a","modified_at":1733403617,"checked_at":1733756616},{"edition_id":"GeoLite2-City","old_hash":"34a6a0ec4018c74a503134980c154502","new_hash":"fb3449d8252f74eac39fc55c32c19879","modified_at":1733501742,"checked_at":1733756620},{"edition_id":"GeoLite2-Country","old_hash":"627a1d220b5ef844e0f0f174a0161cd7","new_hash":"27b1f57ae9dd56e1923f5d458514794c","modified_at":1733506208,"checked_at":1733756621}]' > "${GEOIPUPDATEJSONPATH}" + ## Use this version to test, in dry run, the case of "not changed data" # echo '[{"edition_id":"GeoLite2-ASN","old_hash":"857a0cf8118b9961cf6789e1842bce2a","new_hash":"857a0cf8118b9961cf6789e1842bce2a","checked_at":1733760216},{"edition_id":"GeoLite2-City","old_hash":"fb3449d8252f74eac39fc55c32c19879","new_hash":"fb3449d8252f74eac39fc55c32c19879","checked_at":1733760216},{"edition_id":"GeoLite2-Country","old_hash":"27b1f57ae9dd56e1923f5d458514794c","new_hash":"27b1f57ae9dd56e1923f5d458514794c","checked_at":1733760216}]' > "${GEOIPUPDATEJSONPATH}" echo "json saved to file ${GEOIPUPDATEJSONPATH}" fi jq -r . "${GEOIPUPDATEJSONPATH}" # check that the file exist and has valid json content. -# jq 'has("old_hash") and has("new_hash")' "${GEOIPUPDATEJSONPATH}" echo "GEOIPUPDATE DONE" ### PARSING JSON copy if hash have changed