-
Notifications
You must be signed in to change notification settings - Fork 678
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d06d362
commit c74e1f8
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/bin/bash | ||
|
||
function flush_dns_cache() { | ||
case "$(uname -s)" in | ||
Darwin) | ||
# macOS | ||
echo "Flushing DNS cache on macOS..." | ||
sudo dscacheutil -flushcache | ||
sudo killall -HUP mDNSResponder | ||
;; | ||
Linux) | ||
# Linux | ||
echo "Flushing DNS cache on Linux..." | ||
sudo systemd-resolve --flush-caches | ||
;; | ||
CYGWIN*|MINGW32*|MSYS*|MINGW*) | ||
# Windows | ||
echo "Flushing DNS cache on Windows..." | ||
ipconfig /flushdns | ||
;; | ||
*) | ||
echo "Unsupported OS. DNS cache flush not performed." | ||
;; | ||
esac | ||
} | ||
|
||
function check_dns_cache { | ||
GIT_HOST=$(terminus connection:info ${SITE_ID}.${ENV_ID} --field=git_host) | ||
CACHED_IP=$(dig +short A $GIT_HOST) | ||
UNCACHED_IP=$(dig +short $GIT_HOST @8.8.8.8) | ||
echo "Checking for stale DNS cache for $GIT_HOST" | ||
# Check if CACHED_IP does not equal UNCACHED_IP | ||
if [ "$CACHED_IP" != "$UNCACHED_IP" ]; then | ||
echo "IP address has changed, flushing DNS cache" | ||
flush_dns_cache | ||
else | ||
echo "IP address has not changed, no need to flush DNS cache" | ||
fi | ||
} | ||
|
||
function push_code { | ||
# Example: if git clone fails, check for stale DNS cache and retry | ||
MAX_RETRIES=5 | ||
RETRY_COUNT=0 | ||
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do | ||
git clone --branch $ENV_ID --depth 2 ${{ env.UPSTREAM_GIT_URL }} | ||
if [ $? -eq 0 ]; then | ||
break | ||
else | ||
RETRY_COUNT=$((RETRY_COUNT+1)) | ||
check_dns_cache && echo "Retrying git clone command..." | ||
fi | ||
done | ||
# Continue existing code | ||
|
||
# Example: if git push fails, check for stale DNS cache and retry | ||
MAX_RETRIES=5 | ||
RETRY_COUNT=0 | ||
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do | ||
git push pantheon $BRANCH -vv | ||
if [ $? -eq 0 ]; then | ||
break | ||
else | ||
RETRY_COUNT=$((RETRY_COUNT+1)) | ||
check_dns_cache && echo "Retrying git push command..." | ||
fi | ||
done | ||
} | ||
|
||
push_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
# Function to flush DNS cache based on the operating system | ||
function flush_dns_cache() { | ||
case "$(uname -s)" in | ||
Darwin) | ||
# macOS | ||
echo "Flushing DNS cache on macOS..." | ||
sudo dscacheutil -flushcache | ||
sudo killall -HUP mDNSResponder | ||
;; | ||
Linux) | ||
# Linux | ||
echo "Flushing DNS cache on Linux..." | ||
sudo systemd-resolve --flush-caches | ||
;; | ||
CYGWIN*|MINGW32*|MSYS*|MINGW*) | ||
# Windows | ||
echo "Flushing DNS cache on Windows..." | ||
ipconfig /flushdns | ||
;; | ||
*) | ||
echo "Unsupported OS. DNS cache flush not performed." | ||
;; | ||
esac | ||
} | ||
|
||
# Flush the DNS cache | ||
flush_dns_cache | ||
|
||
# Standard Pantheon git commands, eg | ||
git clone ssh://codeserver.dev.[id]@codeserver.dev.[id].drush.in:2222/~/repository.git -b master mysite |