Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to parse and filter Docker tags by date #5

Merged
merged 6 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
with:
fetch-depth: 50 # the same value as Travis CI

- name: Install jq
run: sudo apt-get install -y jq

- name: Run build script
run: ./build.sh
env:
Expand Down
39 changes: 25 additions & 14 deletions common.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
#!/bin/bash

one_year_ago=$(date -d "1 year ago" +%s)
parse_tags_js() {
taoky marked this conversation as resolved.
Show resolved Hide resolved
is_empty=true
page_url=$(jq -r '.next' <(echo "$tags_js"))
sscscc marked this conversation as resolved.
Show resolved Hide resolved
for result in $(jq -c '.results[]' <(echo "$tags_js")); do
if ! date=$(date -d "$(jq -r '.last_updated' <(echo "$result"))" +%s); then
return 1
fi
if ! name=$(jq -r '.name' <(echo "$result")); then
return 1
fi
if (( date > one_year_ago )); then
echo "$name"
is_empty=false
fi
done
}
docker-tags(){
image=library/$1
tags_js=$(curl -sSL "https://registry.hub.docker.com/v2/repositories/${image}/tags/")
if [ $? -ne 0 ]; then
echo "curl $image failed" >&2
return 1
fi
grep -oP '(?<="name":").+?(?=")' <(echo "$tags_js")
while next_page=$(grep -oP '(?<="next":").+?(?=")' <(echo "$tags_js") | sed 's/\\u0026/\&/' | xargs)
page_url="https://registry.hub.docker.com/v2/repositories/${image}/tags/"
while [[ -n "$page_url" && "$page_url" != "null" && $is_empty != true ]]
sscscc marked this conversation as resolved.
Show resolved Hide resolved
do
if [[ -z "$next_page" || "$next_page" == "null" ]]; then
break
if ! tags_js=$(curl -sSL "$page_url"); then
sscscc marked this conversation as resolved.
Show resolved Hide resolved
echo "curl $page_url failed" >&2
return 1
fi
tags_js=$(curl -sSL "$next_page")
if [ $? -ne 0 ]; then
echo "curl $next_page failed" >&2
if ! parse_tags_js; then
echo "parse json failed" >&2
return 1
fi
grep -oP '(?<="name":").+?(?=")' <(echo "$tags_js")
done
}
}
taoky marked this conversation as resolved.
Show resolved Hide resolved