-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
2 changed files
with
74 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,9 @@ | ||
ARG TAG=main | ||
ARG DOCKER_REPOSITORY=local | ||
FROM ${DOCKER_REPOSITORY}/scyllaridae:${TAG} | ||
|
||
RUN apk update && \ | ||
apk add --no-cache jq==1.7.1-r0 | ||
|
||
COPY cmd.sh /app/ | ||
COPY scyllaridae.yml /app/scyllaridae.yml |
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,65 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eou pipefail | ||
|
||
mygrep() { | ||
# mac OS needs ggrep for the -P flag | ||
if command -v ggrep &>/dev/null; then | ||
ggrep "$@" | ||
else | ||
grep "$@" | ||
fi | ||
} | ||
|
||
# how many cURL commands to run in parallel | ||
PARALLEL_EXECUTIONS=3 | ||
|
||
# Base URL of the sitemap.xml file | ||
BASE_URL="https://$1/sitemap.xml" | ||
PAGE=1 | ||
|
||
while true; do | ||
NEXT_PAGE_URL="$BASE_URL?page=$PAGE" | ||
STATUS=$(curl -w '%{http_code}' \ | ||
--silent \ | ||
-o links.xml \ | ||
"${NEXT_PAGE_URL}") | ||
|
||
if [ "${STATUS}" -eq 200 ]; then | ||
mapfile -t URLS < <(mygrep -oP '<loc>\K[^<]+' links.xml) | ||
while [ "${#URLS[@]}" -gt 0 ]; do | ||
for ((i = 0; i < PARALLEL_EXECUTIONS; i++)); do | ||
array_length=${#URLS[@]} | ||
if [ "$array_length" -gt 0 ]; then | ||
URL="${URLS[$((array_length-1))]}" | ||
unset "URLS[$((array_length-1))]" | ||
else | ||
break | ||
fi | ||
echo "Crawling: $URL" | ||
curl --silent -o /dev/null "${URL}" & | ||
job_ids+=($!) | ||
done | ||
|
||
for job_id in "${job_ids[@]}"; do | ||
wait "$job_id" || echo "One job failed, but continuing anyway" | ||
done | ||
done | ||
|
||
PAGE=$((PAGE + 1)) | ||
else | ||
break | ||
fi | ||
done | ||
|
||
rm -f links.xml | ||
|
||
curl -v http://drupal/api/v1/paged-content > pc.json | ||
|
||
mapfile -t NIDS < <(jq -r '.[]' pc.json) | ||
for NID in "${NIDS[@]}"; do | ||
echo "Processing: $NID" | ||
curl -s -o /dev/null "http://drupal/node/$NID/book-manifest?cache-warmer=1" | ||
done | ||
|
||
rm -f pc.json |